$calendar_id = $targetcalendar;
$user = Horde_Auth::getAuth();
}
- $share = Kronolith::getInternalCalendar($calendar_id);
- if (is_a($share, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was an error accessing the calendar: %s"), $share->getMessage()), 'horde.error');
- } elseif ($user != Horde_Auth::getAuth() &&
- !$share->hasPermission(Horde_Auth::getAuth(), Kronolith::PERMS_DELEGATE, Horde_Auth::getAuth())) {
- $notification->push(sprintf(_("You do not have permission to delegate events to %s."), Kronolith::getUserName($user)), 'horde.warning');
- } elseif ($user == Horde_Auth::getAuth() &&
- !$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT, Horde_Auth::getAuth())) {
- $notification->push(sprintf(_("You do not have permission to add events to %s."), $share->get('name')), 'horde.warning');
- } elseif ($GLOBALS['perms']->hasAppPermission('max_events') === true ||
- $GLOBALS['perms']->hasAppPermission('max_events') > Kronolith::countEvents()) {
- $event = Kronolith::getDriver(null, $calendar_id)->getEvent();
- $event->readForm();
- $result = $event->save();
- if (is_a($result, 'PEAR_Error')) {
- $userinfo = $result->getUserInfo();
- if (is_array($userinfo)) {
- $userinfo = implode(', ', $userinfo);
- }
- $message = $result->getMessage() . ($userinfo ? ' : ' . $userinfo : '');
-
- $notification->push(sprintf(_("There was an error adding the event: %s"), $message), 'horde.error');
- } else {
- Kronolith::notifyOfResourceRejection($event);
- if (Horde_Util::getFormData('sendupdates', false)) {
- $event = Kronolith::getDriver()->getEvent($result);
- if (is_a($event, 'PEAR_Error')) {
- $notification->push($event, 'horde.error');
- } else {
- Kronolith::sendITipNotifications($event, $notification, Kronolith::ITIP_REQUEST);
+ try {
+ $share = Kronolith::getInternalCalendar($calendar_id);
+ if ($user != Horde_Auth::getAuth() &&
+ !$share->hasPermission(Horde_Auth::getAuth(), Kronolith::PERMS_DELEGATE, Horde_Auth::getAuth())) {
+ $notification->push(sprintf(_("You do not have permission to delegate events to %s."), Kronolith::getUserName($user)), 'horde.warning');
+ } elseif ($user == Horde_Auth::getAuth() &&
+ !$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT, Horde_Auth::getAuth())) {
+ $notification->push(sprintf(_("You do not have permission to add events to %s."), $share->get('name')), 'horde.warning');
+ } elseif ($GLOBALS['perms']->hasAppPermission('max_events') === true ||
+ $GLOBALS['perms']->hasAppPermission('max_events') > Kronolith::countEvents()) {
+ $event = Kronolith::getDriver(null, $calendar_id)->getEvent();
+ $event->readForm();
+ try {
+ $event->save();
+ Kronolith::notifyOfResourceRejection($event);
+ if (Horde_Util::getFormData('sendupdates', false)) {
+ try {
+ $event = Kronolith::getDriver()->getEvent($result);
+ Kronolith::sendITipNotifications($event, $notification, Kronolith::ITIP_REQUEST);
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
+ }
}
+ } catch (Exception $e) {
+ // @todo: there is no getUserInfo() in Horde_Exception
+ $userinfo = $e->getUserInfo();
+ if (is_array($userinfo)) {
+ $userinfo = implode(', ', $userinfo);
+ }
+ $message = $e->getMessage() . ($userinfo ? ' : ' . $userinfo : '');
+
+ $notification->push(sprintf(_("There was an error adding the event: %s"), $message), 'horde.error');
}
}
+ } catch (Exception $e) {
+ $notification->push(sprintf(_("There was an error accessing the calendar: %s"), $e->getMessage()), 'horde.error');
}
}
$notification->push(_("The request was incomplete. Some parameters that are necessary to accept or decline an event are missing."), 'horde.error');
$title = '';
} else {
- if (empty($uid)) {
- $event = Kronolith::getDriver(null, $cal)->getEvent($id);
- } else {
- $event = Kronolith::getDriver()->getByUID($uid);
- }
- if (is_a($event, 'PEAR_Error')) {
- $notification->push($event, 'horde.error');
- $title = '';
- } elseif (!$event->hasAttendee($user)) {
- $notification->push(_("You are not an attendee of the specified event."), 'horde.error');
- $title = $event->getTitle();
- } else {
- $event->addAttendee($user, Kronolith::PART_IGNORE, $action);
- $result = $event->save();
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, 'horde.error');
- } elseif (!empty($msg)) {
- $notification->push($msg, 'horde.success');
+ try {
+ if (empty($uid)) {
+ $event = Kronolith::getDriver(null, $cal)->getEvent($id);
+ } else {
+ $event = Kronolith::getDriver()->getByUID($uid);
}
- $title = $event->getTitle();
+ if (!$event->hasAttendee($user)) {
+ $notification->push(_("You are not an attendee of the specified event."), 'horde.error');
+ $title = $event->getTitle();
+ } else {
+ $event->addAttendee($user, Kronolith::PART_IGNORE, $action);
+ try {
+ $event->save();
+ if (!empty($msg)) {
+ $notification->push($msg, 'horde.success');
+ }
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
+ }
+ $title = $event->getTitle();
+ }
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
+ $title = '';
}
}
}
$cal = array($cal);
}
-$vfb = Kronolith_FreeBusy::generate($cal, null, null, true, Horde_Auth::getAuth());
-if (!is_a($vfb, 'PEAR_Error')) {
+try {
+ $vfb = Kronolith_FreeBusy::generate($cal, null, null, true, Horde_Auth::getAuth());
$attendee_view->addRequiredMember($vfb);
-} else {
- $notification->push(
- sprintf(_("Error retrieving your free/busy information: %s"),
- $vfb->getMessage()));
+} catch (Exception $e) {
+ $notification->push(sprintf(_("Error retrieving your free/busy information: %s"), $e->getMessage()));
}
// Add the Free/Busy information for each attendee.
if (strpos($email, '@') !== false &&
($status['attendance'] == Kronolith::PART_REQUIRED ||
$status['attendance'] == Kronolith::PART_OPTIONAL)) {
- $vfb = Kronolith_Freebusy::get($email);
- if (!is_a($vfb, 'PEAR_Error')) {
+ try {
+ $vfb = Kronolith_Freebusy::get($email);
$organizer = $vfb->getAttribute('ORGANIZER');
if (empty($organizer)) {
$vfb->setAttribute('ORGANIZER', 'mailto:' . $email, array(),
} else {
$attendee_view->addOptionalMember($vfb);
}
- } else {
+ } catch (Exception $e) {
$notification->push(
sprintf(_("Error retrieving free/busy information for %s: %s"),
- $email, $vfb->getMessage()));
+ $email, $e->getMessage()));
}
}
}
if (count($resources)) {
$driver = Kronolith::getDriver('Resource');
foreach ($resources as $r_id => $resource) {
+ $r = $driver->getResource($r_id);
try {
- $r = $driver->getResource($r_id);
$vfb = $r->getFreeBusy(null, null, true);
if ($resource['attendance'] == Kronolith::PART_REQUIRED) {
$attendee_view->addRequiredResourceMember($vfb);
// 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 {
+ try {
+ $form->execute();
$notification->push(sprintf(_("The calendar \"%s\" has been created."), $vars->get('name')), 'horde.success');
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
}
-
header('Location: ' . Horde::applicationUrl('calendars/', true));
exit;
}
header('Location: ' . Horde::applicationUrl('calendars/', true));
exit;
}
-$calendar = $kronolith_shares->getShare($calendar_id);
-if (is_a($calendar, 'PEAR_Error')) {
- $notification->push($calendar, 'horde.error');
+try {
+ $calendar = $kronolith_shares->getShare($calendar_id);
+} catch (Exception $e) {
+ $notification->push($e, 'horde.error');
header('Location: ' . Horde::applicationUrl('calendars/', true));
exit;
-} elseif ($calendar->get('owner') != Horde_Auth::getAuth() &&
- (!is_null($calendar->get('owner')) || !Horde_Auth::isAdmin())) {
+}
+if ($calendar->get('owner') != Horde_Auth::getAuth() &&
+ (!is_null($calendar->get('owner')) || !Horde_Auth::isAdmin())) {
$notification->push(_("You are not allowed to delete this calendar."), 'horde.error');
header('Location: ' . Horde::applicationUrl('calendars/', true));
exit;
// Execute if the form is valid (must pass with POST variables only).
if ($form->validate(new Horde_Variables($_POST))) {
- $result = $form->execute();
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, 'horde.error');
- } elseif ($result) {
+ try {
+ $form->execute();
$notification->push(sprintf(_("The calendar \"%s\" has been deleted."), $calendar->get('name')), 'horde.success');
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
}
-
header('Location: ' . Horde::applicationUrl('calendars/', true));
exit;
}
}
$vars = Horde_Variables::getDefaultVariables();
-$calendar = $kronolith_shares->getShare($vars->get('c'));
-if (is_a($calendar, 'PEAR_Error')) {
- $notification->push($calendar, 'horde.error');
+try {
+ $calendar = $kronolith_shares->getShare($vars->get('c'));
+} catch (Exception $e) {
+ $notification->push($e, 'horde.error');
header('Location: ' . Horde::applicationUrl('calendars/', true));
exit;
-} elseif ($calendar->get('owner') != Horde_Auth::getAuth() &&
- (!is_null($calendar->get('owner')) || !Horde_Auth::isAdmin())) {
+}
+if ($calendar->get('owner') != Horde_Auth::getAuth() &&
+ (!is_null($calendar->get('owner')) || !Horde_Auth::isAdmin())) {
$notification->push(_("You are not allowed to change this calendar."), 'horde.error');
header('Location: ' . Horde::applicationUrl('calendars/', true));
exit;
// Execute if the form is valid.
if ($form->validate($vars)) {
$original_name = $calendar->get('name');
- $result = $form->execute();
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, 'horde.error');
- } else {
+ try {
+ $form->execute();
if ($calendar->get('name') != $original_name) {
$notification->push(sprintf(_("The calendar \"%s\" has been renamed to \"%s\"."), $original_name, $calendar->get('name')), 'horde.success');
} else {
$notification->push(sprintf(_("The calendar \"%s\" has been saved."), $original_name), 'horde.success');
}
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
}
-
header('Location: ' . Horde::applicationUrl('calendars/', true));
exit;
}
// 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 {
+ try {
+ $form->execute();
$notification->push(sprintf(_("The calendar \"%s\" has been saved."), $vars->get('name')), 'horde.success');
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
}
-
header('Location: ' . Horde::applicationUrl('calendars/', true));
exit;
}
// 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 {
+ try {
+ $form->execute();
$notification->push(sprintf(_("You have been subscribed to \"%s\" (%s)."), $vars->get('name'), $vars->get('url')), 'horde.success');
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
}
-
header('Location: ' . Horde::applicationUrl('calendars/', true));
exit;
}
// Execute if the form is valid (must pass with POST variables only).
if ($form->validate(new Horde_Variables($_POST))) {
- $result = $form->execute();
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, 'horde.error');
- } elseif ($result) {
+ try {
+ $calendar = $form->execute();
$notification->push(sprintf(_("You have been unsubscribed from \"%s\" (%s)."), $calendar['name'], $calendar['url']), 'horde.success');
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
}
-
header('Location: ' . Horde::applicationUrl('calendars/', true));
exit;
}
$next_step = Horde_Data::IMPORT_FILE;
} else {
if ($actionID == Horde_Data::IMPORT_FILE) {
- $share = &$kronolith_shares->getShare($_SESSION['import_data']['import_cal']);
- if (is_a($share, 'PEAR_Error')) {
- $notification->push(_("You have specified an invalid calendar."), 'horde.error');
- $next_step = $data->cleanup();
- } elseif (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
- $notification->push(_("You do not have permission to add events to the selected calendar."), 'horde.error');
- $next_step = $data->cleanup();
- } else {
- $next_step = $data->nextStep($actionID, $param);
- if (is_a($next_step, 'PEAR_Error')) {
- $notification->push($next_step->getMessage(), 'horde.error');
+ try {
+ $share = $kronolith_shares->getShare($_SESSION['import_data']['import_cal']);
+ if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+ $notification->push(_("You do not have permission to add events to the selected calendar."), 'horde.error');
$next_step = $data->cleanup();
+ } else {
+ $next_step = $data->nextStep($actionID, $param);
+ if (is_a($next_step, 'PEAR_Error')) {
+ $notification->push($next_step->getMessage(), 'horde.error');
+ $next_step = $data->cleanup();
+ }
}
+ } catch (Exception $e) {
+ $notification->push(_("You have specified an invalid calendar."), 'horde.error');
+ $next_step = $data->cleanup();
}
} else {
$next_step = $data->nextStep($actionID, $param);
} else {
/* Purge old calendar if requested. */
if ($_SESSION['import_data']['purge']) {
- $result = $kronolith_driver->delete($_SESSION['import_data']['import_cal']);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("The calendar could not be purged: %s"), $result->getMessage()), 'horde.error');
- } else {
+ try {
+ $kronolith_driver->delete($_SESSION['import_data']['import_cal']);
$notification->push(_("Calendar successfully purged."), 'horde.success');
+ } catch (Exception $e) {
+ $notification->push(sprintf(_("The calendar could not be purged: %s"), $e->getMessage()), 'horde.error');
}
}
}
$notification->push($message, 'horde.error', array('content.raw'));
break;
}
- $event = &$kronolith_driver->getEvent();
- if (!$event || is_a($event, 'PEAR_Error')) {
- $msg = _("Can't create a new event.");
- if (is_a($event, 'PEAR_Error')) {
- $msg .= ' ' . sprintf(_("This is what the server said: %s"), $event->getMessage());
- }
+ try {
+ $event = $kronolith_driver->getEvent();
+ } catch (Exception $e) {
+ $msg = _("Can't create a new event.")
+ . ' ' . sprintf(_("This is what the server said: %s"), $e->getMessage());
$notification->push($msg, 'horde.error');
$error = true;
break;
// Skip other iCalendar components for now.
continue;
} else {
- $valid = $event->fromHash($row);
- if (is_a($valid, 'PEAR_Error')) {
- $notification->push($valid, 'horde.error');
+ try {
+ $event->fromHash($row);
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
$error = true;
break;
}
}
- $success = $event->save();
- if (is_a($success, 'PEAR_Error')) {
- $notification->push($success, 'horde.error');
+ try {
+ $event->save();
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
$error = true;
break;
}
$kronolith_driver = Kronolith::getDriver($driver, $c);
if ($eventID = Horde_Util::getFormData('eventID')) {
- $event = $kronolith_driver->getEvent($eventID);
- if (is_a($event, 'PEAR_Error')) {
+ try {
+ $event = $kronolith_driver->getEvent($eventID);
+ } catch(Exception $e) {
if (($url = Horde_Util::getFormData('url')) === null) {
$url = Horde::applicationUrl($prefs->getValue('defaultview') . '.php', true);
}
exit;
}
if ($driver != 'Resource') {
- $share = &$kronolith_shares->getShare($event->calendar);
+ $share = $kronolith_shares->getShare($event->calendar);
if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE, $event->creator)) {
$notification->push(_("You do not have permission to delete this event."), 'horde.warning');
} else {
'mday' => Horde_Util::getFormData('mday', date('j')) - 1,
'year' => Horde_Util::getFormData('year', date('Y'))));
if ($event->end->compareDate($recurEnd) > 0) {
- $result = $kronolith_driver->deleteEvent($event->id);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, 'horde.error');
+ try {
+ $kronolith_driver->deleteEvent($event->id);
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
}
} else {
$event->recurrence->setRecurEnd($recurEnd);
if (!$event->recurs() ||
Horde_Util::getFormData('all') ||
!$event->recurrence->hasActiveRecurrence()) {
- $result = $kronolith_driver->deleteEvent($event->id);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, 'horde.error');
+ try {
+ $kronolith_driver->deleteEvent($event->id);
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
}
}
function _save(&$event)
{
- $res = $event->save();
+ try {
+ $event->save();
+ if (Horde_Util::getFormData('sendupdates', false)) {
+ Kronolith::sendITipNotifications($event, $GLOBALS['notification'], Kronolith::ITIP_REQUEST);
+ }
+ } catch (Exception $e) {
+ $GLOBALS['notification']->push(sprintf(_("There was an error editing the event: %s"), $e->getMessage()), 'horde.error');
+ }
$tagger = Kronolith::getTagger();
$tagger->replaceTags($event->uid, Horde_Util::getFormData('tags'));
- if (is_a($res, 'PEAR_Error')) {
- $GLOBALS['notification']->push(sprintf(_("There was an error editing the event: %s"), $res->getMessage()), 'horde.error');
- } elseif (Horde_Util::getFormData('sendupdates', false)) {
- Kronolith::sendITipNotifications($event, $GLOBALS['notification'], Kronolith::ITIP_REQUEST);
- }
Kronolith::notifyOfResourceRejection($event);
}
if ($exception = Horde_Util::getFormData('del_exception')) {
$calendar = Horde_Util::getFormData('calendar');
- $share = Kronolith::getInternalCalendar($calendar);
- if (is_a($share, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was an error accessing the calendar: %s"), $share->getMessage()), 'horde.error');
- } else {
+ try {
+ $share = Kronolith::getInternalCalendar($calendar);
$kronolith_driver->open($calendar);
- $event = &$kronolith_driver->getEvent(Horde_Util::getFormData('eventID'));
+ $event = $kronolith_driver->getEvent(Horde_Util::getFormData('eventID'));
$result = sscanf($exception, '%04d%02d%02d', $year, $month, $day);
if ($result == 3 && !is_a($event, 'PEAR_Error') && $event->recurs()) {
$event->recurrence->deleteException($year, $month, $day);
_save($event);
}
+ } catch (Exception $e) {
+ $notification->push(sprintf(_("There was an error accessing the calendar: %s"), $e->getMessage()), 'horde.error');
}
} elseif (!Horde_Util::getFormData('cancel')) {
$source = Horde_Util::getFormData('existingcalendar');
$target = $targetcalendar;
$user = Horde_Auth::getAuth();
}
- $share = Kronolith::getInternalCalendar($target);
- if (is_a($share, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was an error accessing the calendar: %s"), $share->getMessage()), 'horde.error');
- } else {
+ try {
+ $share = Kronolith::getInternalCalendar($target);
$event = false;
-
if (($edit_recur = Horde_Util::getFormData('edit_recur')) &&
$edit_recur != 'all' && $edit_recur != 'copy' &&
_check_max()) {
/* Get event details. */
$kronolith_driver->open($source);
- $event = &$kronolith_driver->getEvent(Horde_Util::getFormData('eventID'));
+ $event = $kronolith_driver->getEvent(Horde_Util::getFormData('eventID'));
$recur_ex = Horde_Util::getFormData('recur_ex');
$exception = new Horde_Date($recur_ex);
/* Create one-time event. */
$kronolith_driver->open($target);
- $event = &$kronolith_driver->getEvent();
+ $event = $kronolith_driver->getEvent();
$event->readForm();
$event->recurrence->setRecurType(Horde_Date_Recurrence::RECUR_NONE);
/* Set recurrence end. */
$exception->mday--;
if ($event->end->compareDate($exception) > 0) {
- $result = $kronolith_driver->deleteEvent($event->id);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, 'horde.error');
+ try {
+ $kronolith_driver->deleteEvent($event->id);
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
}
} else {
$event->recurrence->setRecurEnd($exception);
/* Create new event. */
$kronolith_driver->open($target);
- $event = &$kronolith_driver->getEvent();
+ $event = $kronolith_driver->getEvent();
$event->readForm();
break;
$edit_recur == 'copy') {
if (_check_max()) {
$kronolith_driver->open($target);
- $event = &$kronolith_driver->getEvent();
+ $event = $kronolith_driver->getEvent();
}
} else {
$event_load_from = $source;
if ($target != $source) {
// Only delete the event from the source calendar if this user
// has permissions to do so.
- $sourceShare = Kronolith::getInternalCalendar($source);
- if (!is_a($share, 'PEAR_Error') &&
- !is_a($sourceShare, 'PEAR_Error') &&
- $sourceShare->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE) &&
- (($user == Horde_Auth::getAuth() &&
- $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) ||
- ($user != Horde_Auth::getAuth() &&
- $share->hasPermission(Horde_Auth::getAuth(), Kronolith::PERMS_DELEGATE)))) {
- $kronolith_driver->open($source);
- $res = $kronolith_driver->move(Horde_Util::getFormData('eventID'), $target);
- if (is_a($res, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was an error moving the event: %s"), $res->getMessage()), 'horde.error');
- } else {
- $event_load_from = $target;
+ try {
+ $sourceShare = Kronolith::getInternalCalendar($source);
+ if (!is_a($share, 'PEAR_Error') &&
+ $sourceShare->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE) &&
+ (($user == Horde_Auth::getAuth() &&
+ $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) ||
+ ($user != Horde_Auth::getAuth() &&
+ $share->hasPermission(Horde_Auth::getAuth(), Kronolith::PERMS_DELEGATE)))) {
+ $kronolith_driver->open($source);
+ try {
+ $res = $kronolith_driver->move(Horde_Util::getFormData('eventID'), $target);
+ $event_load_from = $target;
+ } catch (Exception $e) {
+ $notification->push(sprintf(_("There was an error moving the event: %s"), $e->getMessage()), 'horde.error');
+ }
}
+ } catch (Exception $e) {
}
}
$kronolith_driver->open($event_load_from);
- $event = &$kronolith_driver->getEvent(Horde_Util::getFormData('eventID'));
+ $event = $kronolith_driver->getEvent(Horde_Util::getFormData('eventID'));
}
- if ($event && !is_a($event, 'PEAR_Error')) {
+ if ($event) {
if (isset($sourceShare) && !is_a($sourceShare, 'PEAR_Error')
&& !$sourceShare->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
$notification->push(_("You do not have permission to move this event."), 'horde.warning');
_save($event);
}
}
+ } catch (Exception $e) {
+ $notification->push(sprintf(_("There was an error accessing the calendar: %s"), $e->getMessage()), 'horde.error');
}
}
}
}
- $fb = Kronolith_FreeBusy::generate(explode('|', $cal), null, null, false, $user);
- if (is_a($fb, 'PEAR_Error')) {
- Horde::logMessage($fb, __FILE__, __LINE__, PEAR_LOG_ERR);
+ try {
+ $fb = Kronolith_FreeBusy::generate(explode('|', $cal), null, null, false, $user);
+ } catch (Exception $e) {
+ Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
exit;
}
$cache->set($key, $fb);
Horde_Registry::appInit('kronolith', array('authentication' => 'none', 'session_control' => 'readonly'));
$calendar = Horde_Util::getFormData('c');
-$share = $kronolith_shares->getShare($calendar);
-if (is_a($share, 'PEAR_Error')) {
+try {
+ $share = $kronolith_shares->getShare($calendar);
+} catch (Exception $e) {
_no_access(404, 'Not Found',
sprintf(_("The requested feed (%s) was not found on this server."),
htmlspecialchars($calendar)));
$startDate = new Horde_Date(array('year' => date('Y'),
'month' => date('n'),
'mday' => date('j')));
-$events = Kronolith::listEvents($startDate,
- new Horde_Date($startDate),
- array($calendar));
-if (is_a($events, 'PEAR_Error')) {
- Horde::logMessage($events, __FILE__, __LINE__, PEAR_LOG_ERR);
+try {
+ $events = Kronolith::listEvents($startDate,
+ new Horde_Date($startDate),
+ array($calendar));
+} catch (Exception $e) {
+ Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
$events = array();
}
{
$start = new Horde_Date($vars->start);
$end = new Horde_Date($vars->end);
-
$result = new stdClass;
$result->cal = $vars->cal;
$result->view = $vars->view;
return $result;
}
$events = $kronolith_driver->listEvents($start, $end, true, false, true);
- if ($events instanceof PEAR_Error) {
- $GLOBALS['notification']->push($events, 'horde.error');
- return $result;
- break;
- }
-
if (count($events)) {
$result->events = $events;
}
-
return $result;
}
*/
public function QuickSaveEvent($vars)
{
- $kronolith_driver = Kronolith::getDriver();
try {
$event = Kronolith::quickAdd($vars->text, Kronolith::getDefaultCalendar(Horde_Perms::EDIT));
- if ($event instanceof PEAR_Error) {
- $GLOBALS['notification']->push($event, 'horde.error');
- return false;
- }
return $this->_saveEvent($event);
} catch (Horde_Exception $e) {
$GLOBALS['notification']->push($e);
}
$deleted = $kronolith_driver->deleteEvent($event->id);
- if ($deleted instanceof PEAR_Error) {
- $GLOBALS['notification']->push($deleted, 'horde.error');
- return false;
- }
if ($vars->sendupdates) {
Kronolith::sendITipNotifications($event, $GLOBALS['notification'], Kronolith::ITIP_CANCEL);
$events = array();
foreach ($cals as $cal) {
if (!($kronolith_driver = $this->_getDriver($cal))) {
- break;
- }
- $result = $kronolith_driver->search($query, true);
- if ($result instanceof PEAR_Error) {
- $GLOBALS['notification']->push($result, 'horde.error');
- break;
+ continue;
}
- if ($result) {
- $events[$cal] = $result;
+ try {
+ $result = $kronolith_driver->search($query, true);
+ if ($result) {
+ $events[$cal] = $result;
+ }
+ } catch (Exception $e) {
+ $GLOBALS['notification']->push($e, 'horde.error');
}
}
foreach ($tags as $tag) {
$result->tags[] = $tag['tag_name'];
}
-
return $result;
}
*/
public function GetFreeBusy($vars)
{
- $fb = Kronolith_FreeBusy::get($vars->email, true);
- if ($fb instanceof PEAR_Error) {
- $GLOBALS['notification']->push($fb->getMessage(), 'horde.warning');
+ try {
+ $fb = Kronolith_FreeBusy::get($vars->email, true);
+ } catch (Exception $e) {
+ $GLOBALS['notification']->push($e->getMessage(), 'horde.warning');
return false;
}
$result = new stdClass;
$result->fb = $fb;
-
return $result;
}
$GLOBALS['prefs']->isLocked('default_share')) {
return false;
}
- $calendar = Kronolith::addShare($info);
- if ($calendar instanceof PEAR_Error) {
- $GLOBALS['notification']->push($calendar, 'horde.error');
+ try {
+ $calendar = Kronolith::addShare($info);
+ } catch (Exception $e) {
+ $GLOBALS['notification']->push($e, 'horde.error');
return false;
}
$GLOBALS['notification']->push(sprintf(_("The calendar \"%s\" has been created."), $info['name']), 'horde.success');
}
// Update a calendar.
- $calendar = $GLOBALS['kronolith_shares']->getShare($calendar_id);
- if ($calendar instanceof PEAR_Error) {
- $GLOBALS['notification']->push($calendar, 'horde.error');
+ try {
+ $calendar = $GLOBALS['kronolith_shares']->getShare($calendar_id);
+ } catch (Exception $e) {
+ $GLOBALS['notification']->push($e, 'horde.error');
return false;
}
$original_name = $calendar->get('name');
- $updated = Kronolith::updateShare($calendar, $info);
- if ($updated instanceof PEAR_Error) {
- $GLOBALS['notification']->push($updated, 'horde.error');
+ try {
+ Kronolith::updateShare($calendar, $info);
+ } catch (Exception $e) {
+ $GLOBALS['notification']->push($e, 'horde.error');
return false;
}
foreach (array('name', 'description', 'url', 'color', 'username', 'password') as $key) {
$calendar[$key] = $vars->$key;
}
- $subscribed = Kronolith::subscribeRemoteCalendar($calendar);
- if ($subscribed instanceof PEAR_Error) {
- $GLOBALS['notification']->push($subscribed, 'horde.error');
+ try {
+ Kronolith::subscribeRemoteCalendar($calendar);
+ } catch (Exception $e) {
+ $GLOBALS['notification']->push($e, 'horde.error');
return false;
}
if ($calendar_id) {
switch ($vars->type) {
case 'internal':
- $calendar = $GLOBALS['kronolith_shares']->getShare($calendar_id);
- if ($calendar instanceof PEAR_Error) {
- $GLOBALS['notification']->push($calendar, 'horde.error');
+ try {
+ $calendar = $GLOBALS['kronolith_shares']->getShare($calendar_id);
+ } catch (Exception $e) {
+ $GLOBALS['notification']->push($e, 'horde.error');
return false;
}
- $deleted = Kronolith::deleteShare($calendar);
- if ($deleted instanceof PEAR_Error) {
- $GLOBALS['notification']->push(sprintf(_("Unable to delete \"%s\": %s"), $calendar->get('name'), $deleted->getMessage()), 'horde.error');
+ try {
+ Kronolith::deleteShare($calendar);
+ } catch (Exception $e) {
+ $GLOBALS['notification']->push(sprintf(_("Unable to delete \"%s\": %s"), $calendar->get('name'), $e->getMessage()), 'horde.error');
return false;
}
$GLOBALS['notification']->push(sprintf(_("The calendar \"%s\" has been deleted."), $calendar->get('name')), 'horde.success');
break;
case 'remote':
- $deleted = Kronolith::unsubscribeRemoteCalendar($calendar_id);
- if ($deleted instanceof PEAR_Error) {
- $GLOBALS['notification']->push($deleted, 'horde.error');
+ try {
+ $deleted = Kronolith::unsubscribeRemoteCalendar($calendar_id);
+ } catch (Exception $e) {
+ $GLOBALS['notification']->push($e, 'horde.error');
return false;
}
$GLOBALS['notification']->push(sprintf(_("You have been unsubscribed from \"%s\" (%s)."), $deleted['name'], $deleted['url']), 'horde.success');
*/
protected function _saveEvent($event)
{
- $result = $event->save();
- if ($result instanceof PEAR_Error) {
- $GLOBALS['notification']->push($result, 'horde.error');
+ try {
+ $result = $event->save();
+ } catch (Exception $e) {
+ $GLOBALS['notification']->push($e, 'horde.error');
return true;
}
$start = new Horde_Date(Horde_Util::getFormData('view_start'));
* Handle the tag related action.
*
* If removing a tag, needs a 'resource' which is the local identifier of
- * the kronolith object, a 'type' which should be the string reprentation of
- * the type of object (event/calendar) and 'tags' should be the integer
+ * the kronolith object, a 'type' which should be the string reprentation
+ * of the type of object (event/calendar) and 'tags' should be the integer
* tag_id of the tag to remove.
+ *
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
*/
public function handle($args, $post)
{
* @param string $type The type of resource (calendar/event)
*
* @return string The HTML
+ *
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
*/
private function _getTagHtml($tagger, $id, $type)
{
* 'icon', and 'browseable'.
*
* @return array The contents of $path
+ * @throws Kronolith_Exception
*/
public function browse($path = '', $properties = array())
{
// directory.
$kronolith_driver = Kronolith::getDriver(null, $parts[1]);
$events = $kronolith_driver->listEvents();
- if (is_a($events, 'PEAR_Error')) {
- return $events;
- }
-
$icon = $registry->getImageDir('horde') . '/mime/icalendar.png';
$results = array();
foreach ($events as $dayevents) {
array_key_exists($parts[1], Kronolith::listCalendars(false, Horde_Perms::READ))) {
// This request is for a specific item within a given calendar.
$event = Kronolith::getDriver(null, $parts[1])->getEvent($parts[2]);
- if (is_a($event, 'PEAR_Error')) {
- return $event;
- }
$result = array(
'data' => $this->export($event->uid, 'text/calendar'),
* @param string $content The file content.
* @param string $content_type The file's content type.
*
- * @return array The event UIDs, or a PEAR_Error on failure.
+ * @return array The event UIDs.
+ * @throws Kronolith_Exception
*/
public function put($path, $content, $content_type)
{
$content_type = 'text/calendar';
}
} else {
- return PEAR::raiseError("Invalid calendar data supplied.");
+ throw new Kronolith_Exception("Invalid calendar data supplied.");
}
if (!array_key_exists($calendar, Kronolith::listCalendars(false, Horde_Perms::EDIT))) {
// FIXME: Should we attempt to create a calendar based on the
// filename in the case that the requested calendar does not
// exist?
- return PEAR::raiseError("Calendar does not exist or no permission to edit");
+ throw new Kronolith_Exception("Calendar does not exist or no permission to edit");
}
// Store all currently existings UIDs. Use this info to delete UIDs not
$iCal = new Horde_iCalendar();
if (!is_a($content, 'Horde_iCalendar_vevent')) {
if (!$iCal->parsevCalendar($content)) {
- return PEAR::raiseError(_("There was an error importing the iCalendar data."));
+ throw new Kronolith_Exception(_("There was an error importing the iCalendar data."));
}
} else {
$iCal->addComponent($content);
if (isset($uids_remove[$uid])) {
unset($uids_remove[$uid]);
}
- $existing_event = $kronolith_driver->getByUID($uid, array($calendar));
- if (!is_a($existing_event, 'PEAR_Error')) {
+ try {
+ $existing_event = $kronolith_driver->getByUID($uid, array($calendar));
// Check if our event is newer then the existing - get
// the event's history.
$history = Horde_History::singleton();
// Don't change creator/owner.
$event->creator = $existing_event->creator;
+ } catch (Kronolith_Exception $e) {
}
// Save entry.
$saved = $event->save();
- if (is_a($saved, 'PEAR_Error')) {
- return $saved;
- }
$ids[] = $event->uid;
}
}
break;
default:
- return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $content_type));
+ throw new Kronolith_Exception(sprintf(_("Unsupported Content-Type: %s"), $content_type));
}
if (array_key_exists($calendar, Kronolith::listCalendars(false, Horde_Perms::DELETE))) {
*
* @param string $path The path to the file.
*
- * @return mixed The event's UID, or a PEAR_Error on failure.
+ * @throws Kronolith_Exception
*/
public function path_delete($path)
{
if (!(count($parts) == 2 || count($parts) == 3) ||
!array_key_exists($calendarId, Kronolith::listCalendars(false, Horde_Perms::DELETE))) {
- return PEAR::raiseError("Calendar does not exist or no permission to delete");
+ throw new Kronolith_Exception("Calendar does not exist or no permission to delete");
}
if (count($parts) == 3) {
return Kronolith::getDriver(null, $calendarId)->deleteEvent($parts[2]);
} else {
// Delete the entire calendar
- $result = Kronolith::getDriver()->delete($calendarId);
- if (is_a($result, 'PEAR_Error')) {
- return PEAR::raiseError(sprintf(_("Unable to delete calendar \"%s\": %s"), $calendarId, $result->getMessage()));
- } else {
+ try {
+ Kronolith::getDriver()->delete($calendarId);
// Remove share and all groups/permissions.
$share = $GLOBALS['kronolith_shares']->getShare($calendarId);
$result = $GLOBALS['kronolith_shares']->removeShare($share);
if (is_a($result, 'PEAR_Error')) {
return $result;
}
+ } catch (Exception $e) {
+ throw new Kronolith_Exception(sprintf(_("Unable to delete calendar \"%s\": %s"), $calendarId, $e->getMessage()));
}
}
}
* @param object $endstamp The end of the time range.
*
* @return array The event ids happening in this time period.
+ * @throws Kronolith_Exception
*/
public function listUids($calendar = null, $startstamp = 0, $endstamp = 0)
{
}
if (!array_key_exists($calendar,
Kronolith::listCalendars(false, Horde_Perms::READ))) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
$driver = Kronolith::getDriver(null, $calendar);
if (is_a($driver, 'PEAR_Error')) {
return $driver;
}
+
$events = $driver->listEvents(new Horde_Date($startstamp),
new Horde_Date($endstamp));
- if (is_a($events, 'PEAR_Error')) {
- return $events;
- }
-
$uids = array();
foreach ($events as $dayevents) {
foreach ($dayevents as $event) {
* @param string $calendar The calendar to search in.
*
* @return array An array of UIDs matching the action and time criteria.
+ * @throws Kronolith_Exception
*/
public function listBy($action, $timestamp, $calendar = null)
{
if (!array_key_exists($calendar,
Kronolith::listCalendars(false, Horde_Perms::READ))) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
$history = Horde_History::singleton();
* @param string $calendar The calendar to search in.
*
* @return integer The timestamp for this action.
+ * @throws Kronolith_Exception
*/
public function getActionTimestamp($uid, $action, $calendar = null)
{
if (!array_key_exists($calendar,
Kronolith::listCalendars(false, Horde_Perms::READ))) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
$history = Horde_History::singleton();
* </pre>
* @param string $calendar What calendar should the event be added to?
*
- * @return mixed The event's UID, or a PEAR_Error on failure.
+ * @return array The event's UID.
+ * @throws Kronolith_Exception
*/
public function import($content, $contentType, $calendar = null)
{
}
if (!array_key_exists($calendar,
Kronolith::listCalendars(false, Horde_Perms::EDIT))) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
switch ($contentType) {
$iCal = new Horde_iCalendar();
if (!is_a($content, 'Horde_iCalendar_vevent')) {
if (!$iCal->parsevCalendar($content)) {
- return PEAR::raiseError(_("There was an error importing the iCalendar data."));
+ throw new Kronolith_Exception(_("There was an error importing the iCalendar data."));
}
} else {
$iCal->addComponent($content);
$components = $iCal->getComponents();
if (count($components) == 0) {
- return PEAR::raiseError(_("No iCalendar data was found."));
+ throw new Kronolith_Exception(_("No iCalendar data was found."));
}
$kronolith_driver = Kronolith::getDriver(null, $calendar);
// Check if the entry already exists in the data source,
// first by UID.
$uid = $event->uid;
- $existing_event = $kronolith_driver->getByUID($uid, array($calendar));
- if (!is_a($existing_event, 'PEAR_Error')) {
- return PEAR::raiseError(_("Already Exists"),
- 'horde.message', null, null, $uid);
+ try {
+ $existing_event = $kronolith_driver->getByUID($uid, array($calendar));
+ throw new Kronolith_Exception(_("Already Exists"),
+ 'horde.message', null, null, $uid);
+ } catch (Kronolith_Exception $e) {
}
$result = $kronolith_driver->search($event);
// Check if the match really is an exact match:
$match->title == $event->title &&
$match->location == $event->location &&
$match->hasPermission(Horde_Perms::EDIT)) {
- return PEAR::raiseError(_("Already Exists"), 'horde.message', null, null, $match->uid);
+ throw new Kronolith_Exception(_("Already Exists"), 'horde.message', null, null, $match->uid);
}
}
}
$eventId = $event->save();
- if (is_a($eventId, 'PEAR_Error')) {
- return $eventId;
- }
$ids[] = $event->uid;
}
}
if (count($ids) == 0) {
- return PEAR::raiseError(_("No iCalendar data was found."));
+ throw new Kronolith_Exception(_("No iCalendar data was found."));
} else if (count($ids) == 1) {
return $ids[0];
}
return $ids;
}
- return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $contentType));
+ throw new Kronolith_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType));
}
/**
* calendar will be used.
*
* @return array The UID of all events that were added.
+ * @throws Kronolith_Exception
*/
public function quickAdd($text, $calendar = null)
{
- global $kronolith_shares;
-
if (!isset($calendar)) {
$calendar = Kronolith::getDefaultCalendar(Horde_Perms::EDIT);
}
if (!array_key_exists($calendar,
Kronolith::listCalendars(false, Horde_Perms::EDIT))) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
-
$event = Kronolith::quickAdd($text, $calendar);
- if (is_a($event, 'PEAR_Error')) {
- return $event;
- }
-
return $event->uid;
}
* </pre>
*
* @return string The requested data.
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
*/
public function export($uid, $contentType)
{
global $kronolith_shares;
$event = Kronolith::getDriver()->getByUID($uid);
- if (is_a($event, 'PEAR_Error')) {
- return $event;
- }
if (!$event->hasPermission(Horde_Perms::READ)) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
$version = '2.0';
}
- return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $contentType));
+ throw new Kronolith_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType));
}
/**
* </pre>
*
* @return string The iCalendar representation of the calendar.
+ * @throws Kronolith_Exception
*/
public function exportCalendar($calendar, $contentType)
{
if (!array_key_exists($calendar,
Kronolith::listCalendars(false, Horde_Perms::READ))) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
$kronolith_driver = Kronolith::getDriver(null, $calendar);
return $iCal->exportvCalendar();
}
- return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $contentType));
+ throw new Kronolith_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType));
}
/**
* Deletes an event identified by UID.
*
- * @param string|array $uid A single UID or an array identifying the event(s)
- * to delete.
+ * @param string|array $uid A single UID or an array identifying the
+ * event(s) to delete.
*
- * @return boolean Success or failure.
+ * @throws Kronolith_Exception
*/
public function delete($uid)
{
- // Handle an array of UIDs for convenience of deleting multiple events at
- // once.
+ // Handle an array of UIDs for convenience of deleting multiple events
+ // at once.
if (is_array($uid)) {
foreach ($uid as $g) {
$result = $this->delete($g);
return $result;
}
}
-
- return true;
+ return;
}
$kronolith_driver = Kronolith::getDriver();
$events = $kronolith_driver->getByUID($uid, null, true);
- if (is_a($events, 'PEAR_Error')) {
- return $events;
- }
$event = null;
if (Horde_Auth::isAdmin()) {
}
if (empty($event)) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
- return $kronolith_driver->deleteEvent($event->id);
+ $kronolith_driver->deleteEvent($event->id);
}
/**
* text/x-vcalendar
* (Ignored if content is Horde_iCalendar_vevent)
*
- * @return mixed True on success, PEAR_Error otherwise.
+ * @throws Kronolith_Exception
*/
public function replace($uid, $content, $contentType)
{
$event = Kronolith::getDriver()->getByUID($uid);
- if (is_a($event, 'PEAR_Error')) {
- return $event;
- }
if (!$event->hasPermission(Horde_Perms::EDIT) ||
($event->private && $event->creator != Horde_Auth::getAuth())) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
if (is_a($content, 'Horde_iCalendar_vevent')) {
if (!is_a($content, 'Horde_iCalendar_vevent')) {
$iCal = new Horde_iCalendar();
if (!$iCal->parsevCalendar($content)) {
- return PEAR::raiseError(_("There was an error importing the iCalendar data."));
+ throw new Kronolith_Exception(_("There was an error importing the iCalendar data."));
}
$components = $iCal->getComponents();
foreach ($components as $content) {
if (is_a($content, 'Horde_iCalendar_vevent')) {
if ($component !== null) {
- return PEAR::raiseError(_("Multiple iCalendar components found; only one vEvent is supported."));
+ throw new Kronolith_Exception(_("Multiple iCalendar components found; only one vEvent is supported."));
}
$component = $content;
}
}
if ($component === null) {
- return PEAR::raiseError(_("No iCalendar data was found."));
+ throw new Kronolith_Exception(_("No iCalendar data was found."));
}
}
break;
default:
- return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $contentType));
+ throw new Kronolith_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType));
}
}
// Ensure we keep the original UID, even when content does not
// contain one and fromiCalendar creates a new one.
$event->uid = $uid;
- $eventId = $event->save();
-
- return is_a($eventId, 'PEAR_Error') ? $eventId : true;
+ $event->save();
}
/**
*
* @return Horde_iCalendar_vfreebusy A freebusy object that covers the
* specified time period.
+ * @throws Kronolith_Exception
*/
public function getFreeBusy($startstamp = null, $endstamp = null,
$calendar = null)
}
// Free/Busy information is globally available; no permission
// check is needed.
-
return Kronolith_FreeBusy::generate($calendar, $startstamp, $endstamp, true);
}
*
* @param string $uid The event's UID.
*
- * @return Kronolith_Event A valid Kronolith_Event on success, or a PEAR_Error
- * on failure.
+ * @return Kronolith_Event A valid Kronolith_Event.
+ * @throws Kronolith_Exception
*/
public function eventFromUID($uid)
{
$event = Kronolith::getDriver()->getByUID($uid);
- if (is_a($event, 'PEAR_Error')) {
- return $event;
- }
if (!$event->hasPermission(Horde_Perms::SHOW)) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
return $event;
/**
* Updates an attendee's response status for a specified event.
*
- * @param Horde_iCalender_vevent $response A Horde_iCalender_vevent object,
- * with a valid UID attribute that
- * points to an existing event.
- * This is typically the vEvent
- * portion of an iTip meeting-request
+ * @param Horde_iCalender_vevent $response A Horde_iCalender_vevent
+ * object, with a valid UID
+ * attribute that points to an
+ * existing event. This is
+ * typically the vEvent portion
+ * of an iTip meeting-request
* response, with the attendee's
- * response in an ATTENDEE parameter.
- * @param string $sender The email address of the person
- * initiating the update. Attendees
- * are only updated if this address
+ * response in an ATTENDEE
+ * parameter.
+ * @param string $sender The email address of the
+ * person initiating the
+ * update. Attendees are only
+ * updated if this address
* matches.
*
- * @return mixed True on success, PEAR_Error on failure.
+ * @throws Kronolith_Exception
*/
public function updateAttendee($response, $sender = null)
{
}
$events = Kronolith::getDriver()->getByUID($uid, null, true);
- if (is_a($events, 'PEAR_Error')) {
- return $events;
- }
/* First try the user's own calendars. */
$ownerCalendars = Kronolith::listCalendars(true, Horde_Perms::EDIT);
if (empty($event) ||
($event->private && $event->creator != Horde_Auth::getAuth())) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
$atnames = $response->getAttribute('ATTENDEE');
}
}
}
-
- $result = $event->save();
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
+ $event->save();
if (!$found) {
- return PEAR::raiseError($error);
+ throw new Kronolith_Exception($error);
}
-
- return true;
}
/**
* Lists events for a given time period.
*
- * @param integer $startstamp The start of the time period to retrieve.
+ * @param integer $startstamp The start of the time period to
+ * retrieve.
* @param integer $endstamp The end of the time period to retrieve.
* @param array $calendars The calendars to view events from.
* Defaults to the user's default calendar.
- * @param boolean $showRecurrence Return every instance of a recurring event?
- * If false, will only return recurring events
- * once inside the $startDate - $endDate range.
+ * @param boolean $showRecurrence Return every instance of a recurring
+ * event? If false, will only return
+ * recurring events once inside the
+ * $startDate - $endDate range.
* @param boolean $alarmsOnly Filter results for events with alarms.
* Defaults to false.
* @param boolean $showRemote Return events from remote calendars and
* listTimeObject API as well?
*
* @return array A list of event hashes.
+ * @throws Kronolith_Exception
*/
public function listEvents($startstamp = null, $endstamp = null,
$calendars = null, $showRecurrence = true,
$allowed_calendars = Kronolith::listCalendars(false, Horde_Perms::READ);
foreach ($calendars as $calendar) {
if (!array_key_exists($calendar, $allowed_calendars)) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
}
* @param string $user The user to retrieve alarms for. All users if null.
*
* @return array An array of UIDs
+ * @throws Kronolith_Exception
*/
public function listAlarms($time, $user = null)
{
$current_user = Horde_Auth::getAuth();
if ((empty($user) || $user != $current_user) && !Horde_Auth::isAdmin()) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
$group = Group::singleton();
$time = new Horde_Date($time);
$calendars = is_null($user) ? array_keys($GLOBALS['kronolith_shares']->listAllShares()) : $GLOBALS['display_calendars'];
$alarms = Kronolith::listAlarms($time, $calendars, true);
- if (is_a($alarms, 'PEAR_Error')) {
- return $alarms;
- }
foreach ($alarms as $calendar => $cal_alarms) {
if (!$cal_alarms) {
continue;
}
- $share = $GLOBALS['kronolith_shares']->getShare($calendar);
- if (is_a($share, 'PEAR_Error')) {
+ try {
+ $share = $GLOBALS['kronolith_shares']->getShare($calendar);
+ } catch (Exception $e) {
continue;
}
if (empty($user)) {
* Subscribe to a calendar.
*
* @param array $calendar Calendar description hash, with required 'type'
- * parameter. Currently supports 'http' and 'webcal'
- * for remote calendars.
+ * parameter. Currently supports 'http' and
+ * 'webcal' for remote calendars. @throws
+ * Kronolith_Exception
*/
public function subscribe($calendar)
{
if (!isset($calendar['type'])) {
- return PEAR::raiseError(_("Unknown calendar protocol"));
+ throw new Kronolith_Exception(_("Unknown calendar protocol"));
}
switch ($calendar['type']) {
}
default:
- return PEAR::raiseError(_("Unknown calendar protocol"));
+ throw new Kronolith_Exception(_("Unknown calendar protocol"));
}
}
* Unsubscribe from a calendar.
*
* @param array $calendar Calendar description array, with required 'type'
- * parameter. Currently supports 'http' and 'webcal'
- * for remote calendars.
+ * parameter. Currently supports 'http' and
+ * 'webcal' for remote calendars. @throws
+ * Kronolith_Exception
*/
public function unsubscribe($calendar)
{
if (!isset($calendar['type'])) {
- return PEAR::raiseError('Unknown calendar specification');
+ throw new Kronolith_Exception('Unknown calendar specification');
}
switch ($calendar['type']) {
}
default:
- return PEAR::raiseError('Unknown calendar specification');
+ throw new Kronolith_Exception('Unknown calendar specification');
}
}
* @param array $calendar The calendar to lock
* @param array $event The event to lock
*
- * @return mixed A lock ID on success, PEAR_Error on failure, false if:
+ * @return mixed A lock ID on success, false if:
* - The calendar is already locked
* - The event is already locked
- * - A calendar lock was requested and an event is already
- * locked in the calendar
+ * - A calendar lock was requested and an event is
+ * already locked in the calendar
+ * @throws Kronolith_Exception
*/
public function lock($calendar, $event = null)
{
if (!array_key_exists($calendar,
Kronolith::listCalendars(false, Horde_Perms::EDIT))) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
-
- $share = $GLOBALS['kronolith_shares']->getShare($calendar);
- return $share->lock($calendar, $event);
+ return $GLOBALS['kronolith_shares']->getShare($calendar)->lock($calendar, $event);
}
/**
*
* @param array $calendar The event to lock.
* @param array $lockid The lock id to unlock.
+ *
+ * @throws Kronolith_Exception
*/
public function unlock($calendar, $lockid)
{
if (!array_key_exists($calendar,
Kronolith::listCalendars(false, Horde_Perms::EDIT))) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
-
- $share = $GLOBALS['kronolith_shares']->getShare($calendar);
- return $share->unlock($lockid);
+ return $GLOBALS['kronolith_shares']->getShare($calendar)->unlock($lockid);
}
/**
*
* @param array $calendar The calendar to check locks for.
* @param array $event The event to check locks for.
+ *
+ * @throws Kronolith_Exception
*/
public function checkLocks($calendar, $event = null)
{
if (!array_key_exists($calendar,
Kronolith::listCalendars(false, Horde_Perms::READ))) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
-
- $share = $GLOBALS['kronolith_shares']->getShare($calendar);
- return $share->checkLocks($event);
+ return $GLOBALS['kronolith_shares']->getShare($calendar)->checkLocks($event);
}
/**
public function prefsCallback()
{
if ($GLOBALS['prefs']->isDirty('event_alarms')) {
- $alarms = $GLOBALS['registry']->callByPackage('kronolith', 'listAlarms', array($_SERVER['REQUEST_TIME']));
- if (!is_a($alarms, 'PEAR_Error') && !empty($alarms)) {
- $horde_alarm = Horde_Alarm::factory();
- foreach ($alarms as $alarm) {
- $alarm['start'] = new Horde_Date($alarm['start']);
- $alarm['end'] = new Horde_Date($alarm['end']);
- $horde_alarm->set($alarm);
+ try {
+ $alarms = $GLOBALS['registry']->callByPackage('kronolith', 'listAlarms', array($_SERVER['REQUEST_TIME']));
+ if (!empty($alarms)) {
+ $horde_alarm = Horde_Alarm::factory();
+ foreach ($alarms as $alarm) {
+ $alarm['start'] = new Horde_Date($alarm['start']);
+ $alarm['end'] = new Horde_Date($alarm['end']);
+ $horde_alarm->set($alarm);
+ }
}
+ } catch (Exception $e) {
}
}
}
*
* @param string $user Name of user to remove data for.
*
- * @return mixed true on success | PEAR_Error on failure
+ * @throws Kronolith_Exception
*/
public function removeUserData($user)
{
if (!Horde_Auth::isAdmin() && $user != Horde_Auth::getAuth()) {
- return PEAR::raiseError(_("You are not allowed to remove user data."));
+ throw new Kronolith_Exception(_("You are not allowed to remove user data."));
}
/* Remove all events owned by the user in all calendars. */
}
/* Get the user's default share */
- $share = $GLOBALS['kronolith_shares']->getShare($user);
- if (is_a($share, 'PEAR_Error')) {
- Horde::logMessage($share, __FILE__, __LINE__, PEAR_LOG_ERR);
- } else {
+ try {
+ $share = $GLOBALS['kronolith_shares']->getShare($user);
$result = $GLOBALS['kronolith_shares']->removeShare($share);
if (is_a($result, 'PEAR_Error')) {
$hasError = true;
Horde::logMessage($result->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
}
+ } catch (Exception $e) {
+ Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
}
- /* Get a list of all shares this user has perms to and remove the perms */
+ /* Get a list of all shares this user has perms to and remove the
+ * perms */
$shares = $GLOBALS['kronolith_shares']->listShares($user);
if (is_a($shares, 'PEAR_Error')) {
Horde::logMessage($shares, __FILE__, __LINE__, PEAR_LOG_ERR);
foreach ($shares as $share) {
$share->removeUser($user);
}
-
- return true;
}
}
$url = Horde::url($GLOBALS['registry']->getInitialPage(), true);
if (isset($this->_params['calendar']) &&
$this->_params['calendar'] != '__all') {
- $this->_share = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']);
- if (!is_a($this->_share, 'PEAR_Error')) {
+ try {
+ $this->_share = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']);
$url->add('display_cal', $this->_params['calendar']);
$title = htmlspecialchars($this->_share->get('name'));
+ } catch (Exception $e) {
}
}
$date = new Horde_Date(time());
if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') {
if (empty($this->_share)) {
- $this->_share = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']);
- }
- if (is_a($this->_share, 'PEAR_Error')) {
- return _(sprintf("There was an error accessing the calendar: %s", $this->_share->getMessage()));
- }
- if (is_a($this->_share, 'PEAR_Error')) {
- return $this->_share;
+ try {
+ $this->_share = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']);
+ } catch (Exception $e) {
+ return _(sprintf("There was an error accessing the calendar: %s", $e->getMessage()));
+ }
}
if (!$this->_share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW)) {
return _("Permission Denied");
$html .= '<th class="item">' . $weekday . '</th>';
}
- if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') {
- $all_events = Kronolith::listEvents(
- $startDate,
- $endDate,
- array($this->_params['calendar']), true, false, false);
- } else {
- $all_events = Kronolith::listEvents($startDate,
- $endDate,
- $GLOBALS['display_calendars']);
- }
- if (is_a($all_events, 'PEAR_Error')) {
- return '<em>' . $all_events->getMessage() . '</em>';
+ try {
+ if (isset($this->_params['calendar']) &&
+ $this->_params['calendar'] != '__all') {
+ $all_events = Kronolith::listEvents($startDate,$endDate, array($this->_params['calendar']), true, false, false);
+ } else {
+ $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']);
+ }
+ } catch (Exception $e) {
+ return '<em>' . $e->getMessage() . '</em>';
}
$weeks = array();
$startDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j')));
$endDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n') + $this->_params['months'], 'mday' => date('j') - 1));
- if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') {
- $calendar = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']);
- if (!is_a($calendar, 'PEAR_Error') && !$calendar->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW)) {
- return _("Permission Denied");
+ try {
+ if (isset($this->_params['calendar']) &&
+ $this->_params['calendar'] != '__all') {
+ try {
+ $calendar = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']);
+ if (!$calendar->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW)) {
+ return _("Permission Denied");
+ }
+ } catch (Exception $e) {
+ }
+ $all_events = Kronolith::listEvents($startDate, $endDate, array($this->_params['calendar']), true, false, false);
+ } else {
+ $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']);
}
- $all_events = Kronolith::listEvents($startDate, $endDate, array($this->_params['calendar']), true, false, false);
- } else {
- $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']);
- }
- if (is_a($all_events, 'PEAR_Error')) {
- return '<em>' . $all_events->getMessage() . '</em>';
+ } catch (Exception $e) {
+ return '<em>' . $e->getMessage() . '</em>';
}
/* How many days do we need to check. */
$current_month = '';
- if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') {
- $calendar = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']);
- if (!is_a($calendar, 'PEAR_Error') && !$calendar->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW)) {
- return _("Permission Denied");
+ try {
+ if (isset($this->_params['calendar']) &&
+ $this->_params['calendar'] != '__all') {
+ try {
+ $calendar = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']);
+ if (!$calendar->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW)) {
+ return _("Permission Denied");
+ }
+ } catch (Exception $e) {
+ }
+ $all_events = Kronolith::listEvents($startDate, $endDate, array($this->_params['calendar']), true, false, false);
+ } else {
+ $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']);
}
- $all_events = Kronolith::listEvents($startDate, $endDate, array($this->_params['calendar']), true, false, false);
- } else {
- $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']);
- }
- if (is_a($all_events, 'PEAR_Error')) {
- return '<em>' . $all_events->getMessage() . '</em>';
+ } catch (Exception $e) {
+ return '<em>' . $e->getMessage() . '</em>';
}
$html = '';
$startDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j')));
$endDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j') + $this->_params['days']));
- if (isset($this->_params['calendar']) &&
- $this->_params['calendar'] != '__all') {
-
- $calendar = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']);
- if (!is_a($calendar, 'PEAR_Error') && !$calendar->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW)) {
- return _("Permission Denied");
+ try {
+ if (isset($this->_params['calendar']) &&
+ $this->_params['calendar'] != '__all') {
+ try {
+ $calendar = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']);
+ if (!$calendar->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW)) {
+ return _("Permission Denied");
+ }
+ } catch (Exception $e) {
+ }
+ $all_events = Kronolith::listEvents($startDate,
+ $endDate,
+ array($this->_params['calendar']),
+ true, false, false);
+ } else {
+ $all_events = Kronolith::listEvents($startDate,
+ $endDate,
+ $GLOBALS['display_calendars']);
}
-
- $all_events = Kronolith::listEvents($startDate,
- $endDate,
- array($this->_params['calendar']),
- true, false, false);
- } else {
- $all_events = Kronolith::listEvents($startDate,
- $endDate,
- $GLOBALS['display_calendars']);
- }
- if (is_a($all_events, 'PEAR_Error')) {
- return '<em>' . $all_events->getMessage() . '</em>';
+ } catch (Exception $e) {
+ return '<em>' . $e->getMessage() . '</em>';
}
$html = '';
}
$alarmCount = 0;
- $alarms = Kronolith::listAlarms(new Horde_Date($_SERVER['REQUEST_TIME']),
- $GLOBALS['display_calendars'],
- true);
- if (is_a($alarms, 'PEAR_Error')) {
- return $alarms;
+ try {
+ $alarms = Kronolith::listAlarms(new Horde_Date($_SERVER['REQUEST_TIME']),
+ $GLOBALS['display_calendars'],
+ true);
+ } catch (Exception $e) {
+ return;
}
foreach ($alarms as $calId => $calAlarms) {
foreach ($calAlarms as $event) {
* @param object $query An object with the criteria to search for.
* @param boolean $json Store the results of the events' toJson() method?
*
- * @return mixed An array of Kronolith_Events or a PEAR_Error.
+ * @return mixed An array of Kronolith_Events.
+ * @throws Kronolith_Exception
*/
public function search($query, $json = false)
{
$results = array();
$events = $this->listEvents($query->start, $query->end);
- if (is_a($events, 'PEAR_Error')) {
- return $events;
- }
-
foreach ($events as $day => $day_events) {
foreach ($day_events as $event) {
if ((((!isset($query->start) ||
*
* @return Horde_Date|boolean The date of the next recurrence or false if
* the event does not recur after $afterDate.
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
*/
public function nextRecurrence($eventId, $afterDate)
{
$event = $this->getEvent($eventId);
- if (is_a($event, 'PEAR_Error')) {
- return $event;
- }
-
return $event->recurs() ? $event->recurrence->nextRecurrence($afterDate) : false;
}
* Returns the number of events in the current calendar.
*
* @return integer The number of events.
+ * @throws Kronolith_Exception
*/
public function countEvents()
{
if (class_exists($class)) {
$driver = new $class($params);
- $result = $driver->initialize();
- if (is_a($result, 'PEAR_Error')) {
- $driver = new Kronolith_Driver($params, sprintf(_("The Calendar backend is not currently available: %s"), $result->getMessage()));
+ try {
+ $driver->initialize();
+ } catch (Exception $e) {
+ $driver = new Kronolith_Driver($params, sprintf(_("The Calendar backend is not currently available: %s"), $e->getMessage()));
}
} else {
$driver = new Kronolith_Driver($params, sprintf(_("Unable to load the definition of %s."), $class));
/**
* Stub to initiate a driver.
+ *
+ * @throws Kronolith_Exception
*/
public function initialize()
{
/**
* Stub to be overridden in the child class.
+ *
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
*/
public function getEvent()
{
- return PEAR::raiseError($this->_errormsg);
+ throw new Kronolith_Exception($this->_errormsg);
}
/**
* Stub to be overridden in the child class.
+ *
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
*/
public function getByUID($uid, $calendars = null, $getAll = false)
{
- return PEAR::raiseError($this->_errormsg);
+ throw new Kronolith_Exception($this->_errormsg);
}
/**
* Stub to be overridden in the child class.
+ *
+ * @throws Kronolith_Exception
*/
public function listAlarms($date, $fullevent = false)
{
- return PEAR::raiseError($this->_errormsg);
+ throw new Kronolith_Exception($this->_errormsg);
}
/**
* Stub to be overridden in the child class.
+ *
+ * @throws Kronolith_Exception
*/
public function listEvents()
{
- return PEAR::raiseError($this->_errormsg);
+ throw new Kronolith_Exception($this->_errormsg);
}
/**
* Stub to be overridden in the child class.
+ *
+ * @throws Kronolith_Exception
*/
public function saveEvent()
{
- return PEAR::raiseError($this->_errormsg);
+ throw new Kronolith_Exception($this->_errormsg);
}
/**
* Stub for child class to override if it can implement.
+ *
+ * @throws Kronolith_Exception
*/
public function exists()
{
- return PEAR::raiseError('Not supported');
+ throw new Kronolith_Exception('Not supported');
}
/**
*
* @param string $eventId The event to move.
* @param string $newCalendar The new calendar.
+ *
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
*/
public function move($eventId, $newCalendar)
{
/**
* Stub to be overridden in the child class.
+ *
+ * @throws Kronolith_Exception
*/
protected function _move($eventId, $newCalendar)
{
- return PEAR::raiseError('Not supported');
+ throw new Kronolith_Exception('Not supported');
}
/**
* Stub to be overridden in the child class.
+ *
+ * @throws Kronolith_Exception
*/
public function delete($calendar)
{
- return PEAR::raiseError('Not supported');
+ throw new Kronolith_Exception('Not supported');
}
/**
*/
public function deleteEvent($eventId)
{
-
}
/**
- * Stub for child class to override if it can implement.
+ * Stub to be overridden in the child class if it can implement.
+ *
+ * @throws Kronolith_Exception
*/
- public function removeUserData($user)
+ public function filterEventsByCalendar($uids, $calendar)
{
- return PEAR::raiseError(_("Removing user data is not supported with the current calendar storage backend."));
+ throw new Kronolith_Exception('Not supported');
}
/**
- * Stub to be overridden in the child class if it can implement.
+ * Stub for child class to override if it can implement.
+ *
+ * @throws Kronolith_Exception
*/
- public function filterEventsByCalendar($uids, $calendar)
+ public function removeUserData($user)
{
- return PEAR::raiseError('Not supported');
+ throw new Kronolith_Exception(_("Removing user data is not supported with the current calendar storage backend."));
}
}
*/
class Kronolith_Driver_Holidays extends Kronolith_Driver
{
-
public function listAlarms($date, $fullevent = false)
{
return array();
return $results;
}
+ /**
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
+ */
public function getEvent($eventId = null)
{
if (!$eventId) {
$event = $dh->getHoliday($id);
if (is_a($event, 'PEAR_Error')) {
- return $event;
+ throw new Horde_Exception_NotFound($event);
}
return new Kronolith_Event_Holidays($this, $event);
* that they cover.
*
* @return array Events in the given time range.
- * @throws Horde_Exception
+ * @throws Kronolith_Exception
*/
public function listEvents($startDate = null, $endDate = null,
$showRecurrence = false, $hasAlarm = false,
/**
* @todo: implement getTimeObject in timeobjects API.
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
*/
public function getEvent($eventId = null, $start = null)
{
}
}
- return PEAR::raiseError(_("Event not found"));
+ throw new Horde_Exception_NotFound(_("Event not found"));
}
}
* that they cover.
*
* @return array Events in the given time range.
+ * @throws Kronolith_Exception
*/
public function listEvents($startDate = null, $endDate = null,
$showRecurrence = false, $hasAlarm = false,
$json = false, $coverDates = true)
{
$iCal = $this->getRemoteCalendar();
- if (is_a($iCal, 'PEAR_Error')) {
- return $iCal;
- }
if (is_null($startDate)) {
$startDate = new Horde_Date(array('mday' => 1,
return $results;
}
+ /**
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
+ */
public function getEvent($eventId = null)
{
if (!$eventId) {
}
$eventId = str_replace('ical', '', $eventId);
$iCal = $this->getRemoteCalendar();
- if (is_a($iCal, 'PEAR_Error')) {
- return $iCal;
- }
$components = $iCal->getComponents();
if (isset($components[$eventId]) &&
$event->status = Kronolith::STATUS_FREE;
$event->fromiCalendar($components[$eventId]);
$event->id = 'ical' . $eventId;
-
return $event;
}
- return false;
+ throw new Horde_Exception_NotFound(_("Event not found"));
}
/**
*
* @param boolean $cache Whether to return data from the session cache.
*
- * @throws Kronolith_Exception
* @return Horde_iCalendar The calendar data, or an error on failure.
+ * @throws Kronolith_Exception
*/
public function getRemoteCalendar($cache = true)
{
$_SESSION['kronolith']['remote'][$signature] = new Horde_iCalendar();
$result = $_SESSION['kronolith']['remote'][$signature]->parsevCalendar($data);
if (is_a($result, 'PEAR_Error')) {
- $_SESSION['kronolith']['remote'][$signature] = $result;
+ throw new Kronolith_Exception($result);
}
return $_SESSION['kronolith']['remote'][$signature];
<?php
-
-require_once 'Horde/Kolab.php';
-
/**
* Horde Kronolith driver for the Kolab IMAP Server.
*
/**
* Attempts to open a Kolab Groupware folder.
- *
- * @return boolean True on success, PEAR_Error on failure.
*/
public function initialize()
{
$this->_kolab = new Kolab();
$this->reset();
- return true;
}
/**
$this->_synchronized = true;
}
+ /**
+ * @throws Kronolith_Exception
+ */
public function listAlarms($date, $fullevent = false)
{
$allevents = $this->listEvents($date, null, false, true);
foreach ($allevents as $eventId) {
$event = $this->getEvent($eventId);
- if (is_a($event, 'PEAR_Error')) {
- return $event;
- }
-
if (!$event->recurs()) {
$start = new Horde_Date($event->start);
$start->min -= $event->alarm;
*
* @return string|boolean Returns a string with event_id or false if
* not found.
+ * @throws Kronolith_Exception
*/
public function exists($uid, $calendar_id = null)
{
// Log error if someone uses this function in an unsupported way
if ($calendar_id != $this->calendar) {
Horde::logMessage(sprintf("Kolab::exists called for calendar %s. Currently active is %s.", $calendar_id, $this->calendar), __FILE__, __LINE__, PEAR_LOG_ERR);
- return PEAR::raiseError(sprintf("Kolab::exists called for calendar %s. Currently active is %s.", $calendar_id, $this->calendar));
+ throw new Kronolith_Exception(sprintf("Kolab::exists called for calendar %s. Currently active is %s.", $calendar_id, $this->calendar));
}
$result = $this->synchronize();
return $events;
}
+ /**
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
+ */
public function getEvent($eventId = null)
{
if (!strlen($eventId)) {
return $this->_events_cache[$eventId];
}
- return PEAR::raiseError(sprintf(_("Event not found: %s"), $eventId));
+ throw new Horde_Exception_NotFound(sprintf(_("Event not found: %s"), $eventId));
}
/**
* an error will be returned if more than one event is found.
*
* @return Kronolith_Event
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
*/
public function getByUID($uid, $calendars = null, $getAll = false)
{
}
}
- return PEAR::raiseError(sprintf(_("Event not found: %s"), $uid));
+ throw new Horde_Exception_NotFound(sprintf(_("Event not found: %s"), $uid));
}
/**
*
* @param Kronolith_Event $event The event to save.
*
- * @return mixed UID on success, a PEAR error otherwise
+ * @return integer The event id.
+ * @throws Horde_Mime_Exception
*/
- public function saveEvent(&$event)
+ public function saveEvent($event)
{
$result = $this->synchronize();
if (is_a($result, 'PEAR_Error')) {
}
/* Notify about the changed event. */
- $result = Kronolith::sendNotification($event, $edit ? 'edit' : 'add');
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- }
+ Kronolith::sendNotification($event, $edit ? 'edit' : 'add');
/* Log the creation/modification of this item in the history log. */
$history = Horde_History::singleton();
* @param string $newCalendar The new calendar.
*
* @return Kronolith_Event The old event.
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
*/
protected function _move($eventId, $newCalendar)
{
$event = $this->getEvent($eventId);
-
$result = $this->synchronize();
if (is_a($result, 'PEAR_Error')) {
return $result;
*
* @param string $calendar The name of the calendar to delete.
*
- * @return mixed True or a PEAR_Error on failure.
+ * @throws Kronolith_Exception
*/
public function delete($calendar)
{
*
* @param string $eventId The ID of the event to delete.
*
- * @return mixed True or a PEAR_Error on failure.
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
+ * @throws Horde_Mime_Exception
*/
public function deleteEvent($eventId, $silent = false)
{
}
if (!$this->_store->objectUidExists($eventId)) {
- return PEAR::raiseError(sprintf(_("Event not found: %s"), $eventId));
+ throw new Kronolith_Exception(sprintf(_("Event not found: %s"), $eventId));
}
$event = $this->getEvent($eventId);
-
if ($this->_store->delete($eventId)) {
// Notify about the deleted event.
if (!$silent) {
- $result = Kronolith::sendNotification($event, 'delete');
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- }
+ Kronolith::sendNotification($event, 'delete');
}
/* Log the deletion of this item in the history log. */
unset($this->_events_cache[$eventId]);
} else {
- return PEAR::raiseError(sprintf(_("Cannot delete event: %s"), $eventId));
+ throw new Kronolith_Exception(sprintf(_("Cannot delete event: %s"), $eventId));
}
-
- return true;
}
}
* it is attached to. Not sure if there is a better way to do this...
*
* @see lib/Driver/Kronolith_Driver_Sql#deleteEvent($eventId, $silent)
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
*/
public function deleteEvent($event, $silent = false)
{
/* 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...
- */
+ * it is attached to. Not sure if there is a better way to do
+ * this... */
$delete_event = $this->getEvent($event);
$uid = $delete_event->uid;
$driver = Kronolith::getDriver();
* @param Kronolith_Resource $resource
*
* @return Kronolith_Resource object
- * @throws Horde_Exception
+ * @throws Kronolith_Exception
*/
public function save($resource)
{
$result = $this->_write_db->query($query, $values);
if ($result instanceof PEAR_Error) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- throw new Horde_Exception($result);
+ throw new Kronolith_Exception($result);
}
} else {
$query = 'INSERT INTO kronolith_resources (resource_id, resource_name, resource_calendar, resource_description, resource_response_type, resource_type, resource_members)';
$result = $this->_write_db->query($query . $cols_values, $values);
if ($result instanceof PEAR_Error) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- throw new Horde_Exception($result);
+ throw new Kronolith_Exception($result);
}
$resource->setId($id);
*
* @param Kronolith_Resource $resource The kronolith resource to remove
*
- * @return boolean
- * @throws Horde_Exception
+ * @throws Kronolith_Exception
*/
public function delete($resource)
{
if (!($resource instanceof Kronolith_Resource_Base) || !$resource->getId()) {
- throw new Horde_Exception(_("Resource not valid."));
+ throw new Kronolith_Exception(_("Resource not valid."));
}
$query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE calendar_id = ?';
$result = $this->_write_db->query($query, array($resource->get('calendar')));
if ($result instanceof PEAR_Error) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- throw new Horde_Exception($result);
+ throw new Kronolith_Exception($result);
}
$query = 'DELETE FROM kronolith_resources WHERE resource_id = ?';
$result = $this->_write_db->query($query, array($resource->getId()));
if ($result instanceof PEAR_Error) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- throw new Horde_Exception($result);
+ throw new Kronolith_Exception($result);
}
-
- return true;
}
/**
*
* @param int $id The key for the Kronolith_Resource
*
- * @return Kronolith_Resource_Single || Kronolith_Resource_Group
- * @throws Horde_Exception
+ * @return Kronolith_Resource_Single|Kronolith_Resource_Group
+ * @throws Kronolith_Exception
*/
public function getResource($id)
{
$results = $this->_db->getRow($query, array($id), DB_FETCHMODE_ASSOC);
if ($results instanceof PEAR_Error) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- throw new Horde_Exception($results);
+ throw new Kronolith_Exception($results);
}
if (empty($results)) {
- throw new Horde_Exception('Resource not found');
+ throw new Kronolith_Exception('Resource not found');
}
$class = 'Kronolith_Resource_' . $results['resource_type'];
if (!class_exists($class)) {
- throw new Horde_Exception('Could not load the class definition for ' . $class);
+ throw new Kronolith_Exception('Could not load the class definition for ' . $class);
}
return new $class($this->_fromDriver($results));
/**
* Obtain the resource id associated with the given calendar uid.
*
- * @param string $calendar The calendar's uid
+ * @param string $calendar The calendar's uid.
*
- * @return int The Kronolith_Resource id
- * @throws Horde_Exception
+ * @return integer The Kronolith_Resource id.
+ * @throws Kronolith_Exception
*/
public function getResourceIdByCalendar($calendar)
{
$query = 'SELECT resource_id FROM kronolith_resources WHERE resource_calendar = ?';
- $results = $this->_db->getOne($query, array($calendar));
- if ($results instanceof PEAR_Error) {
+ $result = $this->_db->getOne($query, array($calendar));
+ if ($result instanceof PEAR_Error) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- throw new Horde_Exception($results);
+ throw new Kronolith_Exception($result);
}
- if (empty($results)) {
- throw new Horde_Exception('Resource not found');
+ if (empty($result)) {
+ throw new Kronolith_Exception('Resource not found');
}
- return $results;
+ return $result;
}
/**
* Right now, all users have Horde_Perms::READ, but only system admins have
* Horde_Perms::EDIT | Horde_Perms::DELETE
*
- * @param int $perms A Horde_Perms::* constant.
- * @param array $filter A hash of field/values to filter on.
+ * @param integer $perms A Horde_Perms::* constant.
+ * @param array $filter A hash of field/values to filter on.
*
* @return an array of Kronolith_Resource objects.
+ * @throws Kronolith_Exception
*/
public function listResources($perms = Horde_Perms::READ, $filter = array())
{
- if (($perms & (Horde_Perms::EDIT | Horde_Perms::DELETE)) && !Horde_Auth::isAdmin()) {
+ if (($perms & (Horde_Perms::EDIT | Horde_Perms::DELETE)) &&
+ !Horde_Auth::isAdmin()) {
return array();
}
$results = $this->_db->getAssoc($query, true, $filter, DB_FETCHMODE_ASSOC, false);
if ($results instanceof PEAR_Error) {
Horde::logMessage($results, __FILE__, __LINE__, PEAR_LOG_ERR);
- throw new Horde_Exception($results);
+ throw new Kronolith_Exception($results);
}
$return = array();
* @param integer $resource_id The resource id to check for.
*
* @return array of group ids.
+ * @throws Kronolith_Exception
*/
public function getGroupMemberships($resource_id)
{
return $return;
}
-
- /**
- * Remove all events owned by the specified user in all calendars.
- *
- * @todo Refactor: move to Kronolith::
- *
- * @param string $user The user name to delete events for.
- *
- * @param mixed True | PEAR_Error
- */
- public function removeUserData($user)
- {
- return PEAR::raiseError(_("Removing user data is not supported with the current calendar storage backend."));
- }
-
}
return '#dddddd';
}
+ /**
+ * @throws Kronolith_Exception
+ */
public function listAlarms($date, $fullevent = false)
{
$allevents = $this->listEvents($date, null, false, true);
- if (is_a($allevents, 'PEAR_Error')) {
- return $allevents;
- }
-
$events = array();
foreach ($allevents as $dayevents) {
foreach ($dayevents as $event) {
* @param object $query An object with the criteria to search for.
* @param boolean $json Store the results of the events' toJson() method?
*
- * @return mixed An array of Kronolith_Events or a PEAR_Error.
+ * @return mixed An array of Kronolith_Events.
+ * @throws Kronolith_Exception
*/
public function search($query, $json = false)
{
$query->end,
$cond,
$values);
- if (is_a($eventIds, 'PEAR_Error')) {
- return $eventIds;
- }
-
$now = new Horde_Date($_SERVER['REQUEST_TIME']);
$events = array();
foreach ($eventIds as $eventId) {
$event = $this->getEvent($eventId);
- if (is_a($event, 'PEAR_Error')) {
- return $event;
- }
$showRecurrence = true;
if ($event->recurs()) {
if (empty($query->end)) {
*
* @return string|boolean Returns a string with event_id or false if
* not found.
+ * @throws Kronolith_Exception
*/
public function exists($uid, $calendar_id = null)
{
$event = $this->_db->getRow($query, $values, DB_FETCHMODE_ASSOC);
if (is_a($event, 'PEAR_Error')) {
Horde::logMessage($event, __FILE__, __LINE__, PEAR_LOG_ERR);
- return $event;
+ throw new Kronolith_Exception($event);
}
if ($event) {
* that they cover.
*
* @return array Events in the given time range.
+ * @throws Kronolith_Exception
*/
public function listEvents($startDate = null, $endDate = null,
$showRecurrence = false, $hasAlarm = false,
$events = $this->_listEventsConditional($startDate, $endDate,
$hasAlarm ? 'event_alarm > ?' : '',
$hasAlarm ? array(0) : array());
- if (is_a($events, 'PEAR_Error')) {
- return $events;
- }
$results = array();
foreach ($events as $id) {
Kronolith::addEvents($results, $this->getEvent($id), $startDate,
/* Run the query. */
$qr = $this->_db->query($q, $values);
- if (is_a($qr, 'PEAR_Error')) {
+ if ($qr instanceof PEAR_Error) {
Horde::logMessage($qr, __FILE__, __LINE__, PEAR_LOG_ERR);
- return $qr;
+ throw new Kronolith_Exception($qr);
}
$events = array();
* Returns the number of events in the current calendar.
*
* @return integer The number of events.
+ * @throws Kronolith_Exception
*/
public function countEvents()
{
__FILE__, __LINE__, PEAR_LOG_DEBUG);
/* Run the query. */
- return $this->_db->getOne($query, array($this->calendar));
+ $result = $this->_db->getOne($query, array($this->calendar));
+ if ($result instanceof PEAR_Error) {
+ Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+ throw new Kronolith_Exception($result);
+ }
+ return $result;
}
+ /**
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
+ */
public function getEvent($eventId = null)
{
if (!strlen($eventId)) {
$event = $this->_db->getRow($query, $values, DB_FETCHMODE_ASSOC);
if (is_a($event, 'PEAR_Error')) {
Horde::logMessage($event, __FILE__, __LINE__, PEAR_LOG_ERR);
- return $event;
+ throw new Kronolith_Exception($event);
}
if ($event) {
$this->_cache[$this->calendar][$eventId] = new $this->_eventClass($this, $event);
return $this->_cache[$this->calendar][$eventId];
- } else {
- return PEAR::raiseError(_("Event not found"));
}
+
+ throw new Horde_Exception_NotFound(_("Event not found"));
}
/**
* an error will be returned if more than one event is found.
*
* @return Kronolith_Event
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
*/
public function getByUID($uid, $calendars = null, $getAll = false)
{
/* Optionally filter by calendar */
if (!is_null($calendars)) {
if (!count($calendars)) {
- return PEAR::raiseError(_("No calendars to search"));
+ throw new Kronolith_Exception(_("No calendars to search"));
}
$query .= ' AND calendar_id IN (?' . str_repeat(', ?', count($calendars) - 1) . ')';
$values = array_merge($values, $calendars);
$events = $this->_db->getAll($query, $values, DB_FETCHMODE_ASSOC);
if (is_a($events, 'PEAR_Error')) {
Horde::logMessage($events, __FILE__, __LINE__, PEAR_LOG_ERR);
- return $events;
+ throw new Kronolith_Exception($events);
}
if (!count($events)) {
- return PEAR::raiseError($uid . ' not found');
+ throw new Horde_Exception_NotFound($uid . ' not found');
}
$eventArray = array();
/**
* Saves an event in the backend.
+ *
* If it is a new event, it is added, otherwise the event is updated.
*
* @param Kronolith_Event $event The event to save.
+ *
+ * @return integer The event id.
+ * @throws Horde_Mime_Exception
+ * @throws Kronolith_Exception
*/
public function saveEvent($event)
{
$result = $this->_write_db->query($query, $values);
if (is_a($result, 'PEAR_Error')) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- return $result;
+ throw new Kronolith_Exception($result);
}
/* Log the modification of this item in the history log. */
/* Update Geolocation */
if ($gDriver = Kronolith::getGeoDriver()) {
- try {
- $gDriver->setLocation($event->id, $event->geoLocation);
- } catch (Horde_Exception $e) {
- Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
- return new PEAR_Error($e->getMessage());
- }
+ $gDriver->setLocation($event->id, $event->geoLocation);
}
/* Notify users about the changed event. */
- $result = Kronolith::sendNotification($event, 'edit');
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- }
+ Kronolith::sendNotification($event, 'edit');
return $event->id;
+ }
+
+ if ($event->id) {
+ $id = $event->id;
} else {
- if ($event->id) {
- $id = $event->id;
- } else {
- $id = hash('md5', uniqid(mt_rand(), true));
- $event->id = $id;
- }
+ $id = hash('md5', uniqid(mt_rand(), true));
+ $event->id = $id;
+ }
- if ($event->uid) {
- $uid = $event->uid;
- } else {
- $uid = (string)new Horde_Support_Guid;
- $event->uid = $uid;
- }
+ if ($event->uid) {
+ $uid = $event->uid;
+ } else {
+ $uid = (string)new Horde_Support_Guid;
+ $event->uid = $uid;
+ }
- $query = 'INSERT INTO ' . $this->_params['table'];
- $cols_name = ' (event_id, event_uid,';
- $cols_values = ' VALUES (?, ?,';
- $values = array($id, $uid);
+ $query = 'INSERT INTO ' . $this->_params['table'];
+ $cols_name = ' (event_id, event_uid,';
+ $cols_values = ' VALUES (?, ?,';
+ $values = array($id, $uid);
- foreach ($event->getProperties() as $key => $val) {
- $cols_name .= " $key,";
- $cols_values .= ' ?,';
- $values[] = $val;
- }
+ foreach ($event->getProperties() as $key => $val) {
+ $cols_name .= " $key,";
+ $cols_values .= ' ?,';
+ $values[] = $val;
+ }
- $cols_name .= ' calendar_id)';
- $cols_values .= ' ?)';
- $values[] = $this->calendar;
+ $cols_name .= ' calendar_id)';
+ $cols_values .= ' ?)';
+ $values[] = $this->calendar;
- $query .= $cols_name . $cols_values;
+ $query .= $cols_name . $cols_values;
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Kronolith_Driver_Sql::saveEvent(): user = "%s"; query = "%s"; values = "%s"',
- Horde_Auth::getAuth(), $query, implode(',', $values)),
- __FILE__, __LINE__, PEAR_LOG_DEBUG);
+ /* Log the query at a DEBUG log level. */
+ Horde::logMessage(sprintf('Kronolith_Driver_Sql::saveEvent(): user = "%s"; query = "%s"; values = "%s"',
+ Horde_Auth::getAuth(), $query, implode(',', $values)),
+ __FILE__, __LINE__, PEAR_LOG_DEBUG);
- $result = $this->_write_db->query($query, $values);
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- return $result;
- }
+ $result = $this->_write_db->query($query, $values);
+ if (is_a($result, 'PEAR_Error')) {
+ Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+ throw new Kronolith_Exception($result);
+ }
- /* Log the creation of this item in the history log. */
- $history = Horde_History::singleton();
- $history->log('kronolith:' . $this->calendar . ':' . $uid, array('action' => 'add'), true);
+ /* Log the creation of this item in the history log. */
+ $history = Horde_History::singleton();
+ $history->log('kronolith:' . $this->calendar . ':' . $uid, array('action' => 'add'), true);
- /* Deal with any tags */
- $tagger = Kronolith::getTagger();
- $tagger->tag($event->uid, $event->tags, 'event');
+ /* Deal with any tags */
+ $tagger = Kronolith::getTagger();
+ $tagger->tag($event->uid, $event->tags, 'event');
- /* Update Geolocation */
- if ($event->geoLocation && $gDriver = Kronolith::getGeoDriver()) {
- try {
- $gDriver->setLocation($event->id, $event->geoLocation);
- } catch (Horde_Exception $e) {
- Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
- return new PEAR_Error($e->getMessage());
- }
- }
+ /* Update Geolocation */
+ if ($event->geoLocation && $gDriver = Kronolith::getGeoDriver()) {
+ $gDriver->setLocation($event->id, $event->geoLocation);
+ }
- /* Notify users about the new event. */
- $result = Kronolith::sendNotification($event, 'add');
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- }
+ /* Notify users about the new event. */
+ Kronolith::sendNotification($event, 'add');
- return $id;
- }
+ return $id;
}
/**
* @param string $newCalendar The new calendar.
*
* @return Kronolith_Event The old event.
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
*/
protected function _move($eventId, $newCalendar)
{
/* Fetch the event for later use. */
$event = $this->getEvent($eventId);
- if (is_a($event, 'PEAR_Error')) {
- return $event;
- }
$query = 'UPDATE ' . $this->_params['table'] . ' SET calendar_id = ? WHERE calendar_id = ? AND event_id = ?';
$values = array($newCalendar, $this->calendar, $eventId);
$result = $this->_write_db->query($query, $values);
if (is_a($result, 'PEAR_Error')) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- return $result;
+ throw new Kronolith_Exception($result);
}
return $event;
*
* @param string $calendar The name of the calendar to delete.
*
- * @return mixed True or a PEAR_Error on failure.
+ * @throws Kronolith_Exception
*/
public function delete($calendar)
{
Horde_Auth::getAuth(), $query, implode(',', $values)),
__FILE__, __LINE__, PEAR_LOG_DEBUG);
- return $this->_write_db->query($query, $values);
+ $result = $this->_write_db->query($query, $values);
+ if ($result instanceof PEAR_Error) {
+ Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+ throw new Kronolith_Exception($result);
+ }
}
/**
* @param boolean $silent Don't send notifications, used when deleting
* events in bulk from maintenance tasks.
*
- * @return mixed True or a PEAR_Error on failure.
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
+ * @throws Horde_Mime_Exception
*/
public function deleteEvent($eventId, $silent = false)
{
/* Fetch the event for later use. */
$event = $this->getEvent($eventId);
- if (is_a($event, 'PEAR_Error')) {
- return $event;
- }
$query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE event_id = ? AND calendar_id = ?';
$values = array($eventId, $this->calendar);
$result = $this->_write_db->query($query, $values);
if (is_a($result, 'PEAR_Error')) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- return $result;
+ throw new Kronolith_Exception($result);
}
/* Log the deletion of this item in the history log. */
/* Notify about the deleted event. */
if (!$silent) {
- $result = Kronolith::sendNotification($event, 'delete');
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- }
+ Kronolith::sendNotification($event, 'delete');
+ }
+ }
+
+ /**
+ * Filters a list of events to return only those that belong to certain
+ * calendars.
+ *
+ * @param array $uids A list of event UIDs.
+ * @param array $calendar A list of calendar IDs.
+ *
+ * @return array Event UIDs filtered by calendar IDs.
+ * @throws Kronolith_Exception
+ */
+ public function filterEventsByCalendar($uids, $calendar)
+ {
+ $sql = 'SELECT event_uid FROM kronolith_events WHERE calendar_id IN (' . str_repeat('?, ', count($calendar) - 1) . '?) '
+ . 'AND event_uid IN (' . str_repeat('?,', count($uids) - 1) . '?)';
+
+ /* Log the query at a DEBUG log level. */
+ Horde::logMessage(sprintf('Kronolith_Driver_Sql::filterEventsByCalendar(): %s', $sql),
+ __FILE__, __LINE__, PEAR_LOG_DEBUG);
+
+ $result = $this->_db->getCol($sql, 0, array_merge($calendar, $uids));
+ if ($result instanceof PEAR_Error) {
+ Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+ throw new Kronolith_Exception($result);
}
- return true;
}
/**
* Attempts to open a connection to the SQL server.
*
- * @return boolean True.
+ * @throws Kronolith_Exception
*/
public function initialize()
{
$this->_write_db = DB::connect($this->_params,
array('persistent' => !empty($this->_params['persistent']),
'ssl' => !empty($this->_params['ssl'])));
- if (is_a($this->_write_db, 'PEAR_Error')) {
- return $this->_write_db;
+ if ($this->_write_db instanceof PEAR_Error) {
+ throw new Kronolith_Exception($this->_write_db);
}
$this->_initConn($this->_write_db);
$this->_db = DB::connect($params,
array('persistent' => !empty($params['persistent']),
'ssl' => !empty($params['ssl'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- return $this->_db;
+ if ($this->_db instanceof PEAR_Error) {
+ throw new Kronolith_Exception($this->_db);
}
$this->_initConn($this->_db);
} else {
/* Default to the same DB handle for the writer too. */
$this->_db = $this->_write_db;
}
-
- return true;
}
/**
/**
* Remove all events owned by the specified user in all calendars.
*
- * @todo Refactor: move to Kronolith::
+ * @todo Refactor: move to Kronolith:: and catch exceptions instead of relying on boolean return value.
*
* @param string $user The user name to delete events for.
*
- * @param mixed True | PEAR_Error
+ * @return boolean
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
*/
public function removeUserData($user)
{
- return PEAR::raiseError('to be refactored');
+ throw new Kronolith_Exception('to be refactored');
if (!Horde_Auth::isAdmin()) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Kronolith_Exception(_("Permission Denied"));
}
$shares = $GLOBALS['kronolith_shares']->listShares($user, Horde_Perms::EDIT);
foreach ($uids as $uid) {
$event = $this->getByUID($uid);
- if (is_a($event, 'PEAR_Error')) {
- return $event;
- }
-
$this->deleteEvent($event->id);
}
}
return true;
}
- /**
- * Filter an array of event_uids to return only the events that belong to
- * one of the $calendars.
- *
- * @param array $uids An array of event_uid values.
- * @param array $calendar An array of calendar_ids.
- *
- * @return An array of event_uid values filtered by calendar_ids || PEAR_Error
- */
- public function filterEventsByCalendar($uids, $calendar)
- {
- $sql = 'SELECT event_uid FROM kronolith_events WHERE calendar_id IN (' . str_repeat('?, ', count($calendar) - 1) . '?) '
- . 'AND event_uid IN (' . str_repeat('?,', count($uids) - 1) . '?)';
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Kronolith_Driver_Sql::filterEventsByCalendar(): %s', $sql),
- __FILE__, __LINE__, PEAR_LOG_DEBUG);
-
- return $this->_db->getCol($sql, 0, array_merge($calendar, $uids));
- }
-
}
/* Get geolocation data */
if ($gDriver = Kronolith::getGeoDriver()) {
- $this->geoLocation = $gDriver->getLocation($this->id);
+ try {
+ $this->geoLocation = $gDriver->getLocation($this->id);
+ } catch (Exception $e) {
+ }
}
}
}
* Returns the share this event belongs to.
*
* @return Horde_Share This event's share.
+ * @throws Kronolith_Exception
*/
public function getShare()
{
if (isset($GLOBALS['all_calendars'][$this->calendar])) {
- $share = $GLOBALS['all_calendars'][$this->calendar];
- } else {
- $share = PEAR::raiseError('Share not found');
+ return $GLOBALS['all_calendars'][$this->calendar];
}
- return $share;
+ throw new Kronolith_Exception('Share not found');
}
/**
if ($user === null) {
$user = Horde_Auth::getAuth();
}
-
- return (!is_a($share = &$this->getShare(), 'PEAR_Error') &&
- $share->hasPermission($user, $permission, $this->creator));
+ try {
+ $share = $this->getShare();
+ } catch (Exception $e) {
+ return false;
+ }
+ return $share->hasPermission($user, $permission, $this->creator);
}
/**
* Saves changes to this event.
*
- * @return mixed True or a PEAR_Error on failure.
+ * @return integer The event id.
+ * @throws Kronolith_Exception
*/
public function save()
{
if (!$this->initialized) {
- return PEAR::raiseError('Event not yet initialized');
+ throw new Kronolith_Exception('Event not yet initialized');
}
- /* Check for acceptance/denial of this event's resources.
- */
+ /* Check for acceptance/denial of this event's resources. */
$add_events = array();
$locks = Horde_Lock::singleton($GLOBALS['conf']['lock']['driver']);
$lock = array();
$failed_resources = array();
foreach ($this->getResources() as $id => $resourceData) {
-
/* Get the resource and protect against infinite recursion in case
* someone is silly enough to add a resource to it's own event.*/
$resource = Kronolith::getDriver('Resource')->getResource($id);
// Already locked
// For now, just fail. Not sure how else to capture the locked
// resources and notify the user.
- return PEAR::raiseError(sprintf(_("The resource \"%s\" was locked. Please try again."), $resource->get('name')));
+ throw new Kronolith_Exception(sprintf(_("The resource \"%s\" was locked. Please try again."), $resource->get('name')));
} else {
$response = $resource->getResponse($this);
}
/* Save */
$this->toDriver();
$result = $this->getDriver()->saveEvent($this);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
- /* Now that the event is definitely commited to storage, we can add the
- * event to each resource that has accepted. Not very efficient, but
- * this also solves the problem of not having a GUID for the event until
- * after it's saved. If we add the event to the resources calendar
- * before it is saved, they will have different GUIDs, and hence no
- * longer refer to the same event.
- */
+ /* Now that the event is definitely commited to storage, we can add
+ * the event to each resource that has accepted. Not very efficient,
+ * but this also solves the problem of not having a GUID for the event
+ * until after it's saved. If we add the event to the resources
+ * calendar before it is saved, they will have different GUIDs, and
+ * hence no longer refer to the same event. */
foreach ($add_events as $resource) {
$resource->addEvent($this);
if ($resource->get('response_type') == Kronolith_Resource::RESPONSETYPE_AUTO) {
* Imports the values for this event from an array of values.
*
* @param array $hash Array containing all the values.
+ *
+ * @throws Kronolith_Exception
*/
public function fromHash($hash)
{
if (!empty($hash['title'])) {
$this->title = $hash['title'];
} else {
- return PEAR::raiseError(_("Events must have a title."));
+ throw new Kronolith_Exception(_("Events must have a title."));
}
if (!empty($hash['description'])) {
$this->description = $hash['description'];
'sec' => $time[2]));
}
} else {
- return PEAR::raiseError(_("Events must have a start date."));
+ throw new Kronolith_Exception(_("Events must have a start date."));
}
if (empty($hash['duration'])) {
if (empty($hash['end_date'])) {
if (!isset($this->uid) || !isset($this->calendar)) {
return false;
}
-
- $eventID = $this->getDriver()->exists($this->uid, $this->calendar);
- if (is_a($eventID, 'PEAR_Error') || !$eventID) {
- return false;
- } else {
- $this->id = $eventID;
- return true;
+ try {
+ $eventID = $this->getDriver()->exists($this->uid, $this->calendar);
+ if (!$eventID) {
+ return false;
+ }
+ } catch (Exception $e) {
+ return $false;
}
+ $this->id = $eventID;
+ return true;
}
public function getDuration()
*/
public function hasAttendee($email)
{
- $email = Horde_String::lower($email);
- return isset($this->attendees[$email]);
+ return isset($this->attendees[Horde_String::lower($email)]);
}
/**
}
/**
- * Adds a single Kronolith_Resource to this event.
- * No validation or acceptence/denial is done here...it should be done
- * when saving the Event.
+ * Adds a single resource to this event.
*
- * @param Kronolith_Resource $resource The resource to add
+ * No validation or acceptence/denial is done here...it should be done
+ * when saving the event.
*
- * @return void
+ * @param Kronolith_Resource $resource The resource to add.
*/
public function addResource($resource, $response)
{
}
/**
- * Remove a Kronolith_Resource from this event
- *
- * @param Kronolith_Resource $resource The resource to remove
+ * Removes a resource from this event.
*
- * @return void
+ * @param Kronolith_Resource $resource The resource to remove.
*/
public function removeResource($resource)
{
}
/**
- * Returns the entire resources array.
+ * Returns all resources.
*
- * @return array A copy of the attendees array.
+ * @return array A copy of the resources array.
*/
public function getResources()
{
* @package Kronolith
*/
-/** Horde_Form */
-require_once 'Horde/Form.php';
-
-/** Horde_Form_Renderer */
-require_once 'Horde/Form/Renderer.php';
-
/**
- * The Kronolith_CreateCalendarForm class provides the form for
- * creating a calendar.
+ * The Kronolith_CreateCalendarForm class provides the form for creating a
+ * calendar.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @package Kronolith
*/
-class Kronolith_CreateCalendarForm extends Horde_Form {
-
- function Kronolith_CreateCalendarForm(&$vars)
+class Kronolith_CreateCalendarForm extends Horde_Form
+{
+ public function __construct($vars)
{
parent::Horde_Form($vars, _("Create Calendar"));
$this->setButtons(array(_("Create")));
}
- function execute()
+ /**
+ * @throws Kronolith_Exception
+ */
+ public function execute()
{
$info = array();
foreach (array('name', 'color', 'description', 'tags', 'system') as $key) {
<?php
/**
- * Horde_Form for creating resource calendars.
+ * Horde_Form for creating resources.
*
* 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.
+ * The Kronolith_CreateResourceForm class provides the form for creating a
+ * resource.
*
* @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)
+class Kronolith_CreateResourceForm extends Horde_Form
+{
+ /**
+ * @throws Kronolith_Exception
+ */
+ public function __construct($vars)
{
parent::Horde_Form($vars, _("Create Resource"));
+
$responses = array(Kronolith_Resource::RESPONSETYPE_ALWAYS_ACCEPT => _("Always Accept"),
Kronolith_Resource::RESPONSETYPE_ALWAYS_DECLINE => _("Always Decline"),
Kronolith_Resource::RESPONSETYPE_AUTO => _("Automatically"),
Kronolith_Resource::RESPONSETYPE_NONE => _("None"));
/* Get a list of available resource groups */
- $driver = Kronolith::getDriver('Resource');
- $groups = $driver->listResources(Horde_Perms::READ, array('type' => Kronolith_Resource::TYPE_GROUP));
+ $groups = Kronolith::getDriver('Resource')
+ ->listResources(Horde_Perms::READ,
+ array('type' => Kronolith_Resource::TYPE_GROUP));
$enum = array();
foreach ($groups as $id => $group) {
$enum[$id] = $group->get('name');
$this->setButtons(array(_("Create")));
}
- function execute()
+ /**
+ * @throws Kronolith_Exception
+ */
+ public function execute()
{
$new = array('name' => $this->_vars->get('name'),
'description' => $this->_vars->get('description'),
'response_type' => $this->_vars->get('responsetype'));
-
- $resource = new Kronolith_Resource_Single($new);
- $resource = Kronolith_Resource::addResource($resource);
+ $resource = Kronolith_Resource::addResource(new Kronolith_Resource_Single($new));
/* Do we need to add this to any groups? */
$groups = $this->_vars->get('category');
<?php
/**
- * Horde_Form for creating resource calendars.
+ * Horde_Form for creating resource groups.
*
* 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.
+ * The Kronolith_CreateResourceGroupForm class provides the form for creating
+ * a resource group.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @author Michael J. Rubinsky <mrubinsk@horde.org>
* @package Kronolith
*/
-class Kronolith_CreateResourceGroupForm extends Horde_Form {
-
- function Kronolith_CreateResourceGroupForm(&$vars)
+class Kronolith_CreateResourceGroupForm extends Horde_Form
+{
+ /**
+ * @throws Kronolith_Exception
+ */
+ public function __construct($vars)
{
parent::Horde_Form($vars, _("Create Resource"));
$this->setButtons(array(_("Create")));
}
- function execute()
+ public function execute()
{
$new = array('name' => $this->_vars->get('name'),
'description' => $this->_vars->get('description'),
'members' => $this->_vars->get('members'));
-
- $resource = new Kronolith_Resource_Group($new);
-
- return $results = Kronolith_Resource::addResource($resource);
+ return Kronolith_Resource::addResource(new Kronolith_Resource_Group($new));
}
}
* @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.
+ * The Kronolith_DeleteCalendarForm class provides the form for deleting a
+ * calendar.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @package Kronolith
*/
-class Kronolith_DeleteCalendarForm extends Horde_Form {
-
+class Kronolith_DeleteCalendarForm extends Horde_Form
+{
/**
- * Calendar being deleted
+ * Calendar being deleted.
*/
- var $_calendar;
+ protected $_calendar;
- function Kronolith_DeleteCalendarForm(&$vars, &$calendar)
+ public function __construct($vars, $calendar)
{
- $this->_calendar = &$calendar;
+ $this->_calendar = $calendar;
parent::Horde_Form($vars, sprintf(_("Delete %s"), $calendar->get('name')));
$this->addHidden('', 'c', 'text', true);
$this->setButtons(array(_("Delete"), _("Cancel")));
}
- function execute()
+ /**
+ * @throws Kronolith_Exception
+ */
+ public function execute()
{
// If cancel was clicked, return false.
if ($this->_vars->get('submitbutton') == _("Cancel")) {
<?php
/**
- * Horde_Form for deleting calendars.
+ * Horde_Form for deleting resources.
*
* 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.
+ * The Kronolith_DeleteResourceForm class provides the form for deleting a
+ * resource.
*
* @author Chuck Hagenbuch <chuck@horde.org>
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
* @package Kronolith
*/
-class Kronolith_DeleteResourceForm extends Horde_Form {
-
+class Kronolith_DeleteResourceForm extends Horde_Form
+{
/**
- * Calendar being deleted
+ * Resource being deleted.
+ *
+ * @var Kronolith_Resource_Single
*/
- var $_calendar;
+ protected $_resource;
- function Kronolith_DeleteResourceForm(&$vars, &$resource)
+ public function __construct($vars, $resource)
{
- $this->_resource = &$resource;
+ $this->_resource = $resource;
parent::Horde_Form($vars, sprintf(_("Delete %s"), $resource->get('name')));
$this->addHidden('', 'c', 'text', true);
$this->setButtons(array(_("Delete"), _("Cancel")));
}
- function execute()
+ /**
+ * @throws Kronolith_Exception
+ */
+ public function execute()
{
// If cancel was clicked, return false.
if ($this->_vars->get('submitbutton') == _("Cancel")) {
- return false;
+ return;
}
if (!($this->_resource->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE))) {
- return PEAR::raiseError(_("Permission denied"));
+ throw new Kronolith_Exception(_("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()));
+ try {
+ Kronolith::getDriver('Resource')->delete($this->_resource);
+ } catch (Exception $e) {
+ throw new Kronolith_Exception(sprintf(_("Unable to delete \"%s\": %s"), $this->_resource->get('name'), $e->getMessage()));
}
-
- return true;
}
}
<?php
/**
- * Horde_Form for deleting calendars.
+ * Horde_Form for deleting resource groups.
*
* 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_DeleteResourceGroupForm class provides the form for
- * deleting a calendar.
+ * The Kronolith_DeleteResourceGroupForm class provides the form for deleting
+ * a resource group.
*
* @author Chuck Hagenbuch <chuck@horde.org>
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
* @package Kronolith
*/
-class Kronolith_DeleteResourceGroupForm extends Horde_Form {
-
+class Kronolith_DeleteResourceGroupForm extends Horde_Form
+{
/**
- * Calendar being deleted
+ * Resource group being deleted.
+ *
+ * @var Kronolith_Resource_Group
*/
- var $_calendar;
+ protected $_resource;
- function Kronolith_DeleteResourceGroupForm(&$vars, &$resource)
+ public function __construct($vars, $resource)
{
- $this->_resource = &$resource;
+ $this->_resource = $resource;
parent::Horde_Form($vars, sprintf(_("Delete %s"), $resource->get('name')));
$this->addHidden('', 'c', 'text', true);
$this->setButtons(array(_("Delete"), _("Cancel")));
}
- function execute()
+ /**
+ * @throws Kronolith_Exception
+ */
+ public function execute()
{
// If cancel was clicked, return false.
if ($this->_vars->get('submitbutton') == _("Cancel")) {
- return false;
+ return;
}
if (!($this->_resource->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE))) {
- return PEAR::raiseError(_("Permission denied"));
+ throw new Kronolith_Exception(_("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()));
+ try {
+ Kronolith::getDriver('Resource')->delete($this->_resource);
+ } catch (Exception $e) {
+ throw new Kronolith_Exception(sprintf(_("Unable to delete \"%s\": %s"), $this->_resource->get('name'), $e->getMessage()));
}
-
- return true;
}
}
* @package Kronolith
*/
-/** Horde_Form */
-require_once 'Horde/Form.php';
-
-/** Horde_Form_Renderer */
-require_once 'Horde/Form/Renderer.php';
-
/**
- * The Kronolith_EditCalendarForm class provides the form for
- * editing a calendar.
+ * The Kronolith_EditCalendarForm class provides the form for editing a
+ * calendar.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @package Kronolith
*/
-class Kronolith_EditCalendarForm extends Horde_Form {
-
+class Kronolith_EditCalendarForm extends Horde_Form
+{
/**
- * Calendar being edited
+ * Calendar being edited.
*/
- var $_calendar;
+ protected $_calendar;
- function Kronolith_EditCalendarForm(&$vars, &$calendar)
+ public function __construct($vars, $calendar)
{
- $this->_calendar = &$calendar;
+ $this->_calendar = $calendar;
parent::Horde_Form($vars, sprintf(_("Edit %s"), $calendar->get('name')));
$this->addHidden('', 'c', 'text', true);
$this->setButtons(array(_("Save")));
}
- function execute()
+ /**
+ * @throws Kronolith_Exception
+ */
+ public function execute()
{
$info = array();
foreach (array('name', 'color', 'description', 'tags', 'system') as $key) {
* @package Kronolith
*/
-/** Horde_Form */
-require_once 'Horde/Form.php';
-
-/** Horde_Form_Renderer */
-require_once 'Horde/Form/Renderer.php';
-
/**
- * The Kronolith_EditRemoteCalendarForm class provides the form for
- * editing a remote calendar.
+ * The Kronolith_EditRemoteCalendarForm class provides the form for editing a
+ * remote calendar.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @package Kronolith
*/
-class Kronolith_EditRemoteCalendarForm extends Horde_Form {
-
- function Kronolith_EditRemoteCalendarForm(&$vars, $remote_calendar)
+class Kronolith_EditRemoteCalendarForm extends Horde_Form
+{
+ public function __construct($vars, $remote_calendar)
{
parent::Horde_Form($vars, sprintf(_("Edit %s"), $remote_calendar['name']));
$this->setButtons(array(_("Save")));
}
- function execute()
+ /**
+ * @throws Kronolith_Exception
+ */
+ public function execute()
{
$info = array();
foreach (array('name', 'new_url', 'user', 'password', 'color', 'desc') as $key) {
<?php
/**
- * Horde_Form for editing resource calendars.
+ * Horde_Form for editing resources.
*
* 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.
+ * The Kronolith_EditResourceForm class provides the form for editing a
+ * resource.
*
* @author Chuck Hagenbuch <chuck@horde.org>
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
* @package Kronolith
*/
-class Kronolith_EditResourceForm extends Horde_Form {
-
+class Kronolith_EditResourceForm extends Horde_Form
+{
/**
- * Calendar being edited
+ * Resource being edited.
+ *
+ * @var Kronolith_Resource_Single
*/
- var $_resource;
+ protected $_resource;
- function Kronolith_EditResourceForm(&$vars, &$resource)
+ /**
+ * @throws Kronolith_Exception
+ */
+ public function __construct($vars, $resource)
{
- $this->_resource = &$resource;
+ $this->_resource = $resource;
parent::Horde_Form($vars, sprintf(_("Edit %s"), $resource->get('name')));
+
$responses = array(Kronolith_Resource::RESPONSETYPE_ALWAYS_ACCEPT => _("Always Accept"),
Kronolith_Resource::RESPONSETYPE_ALWAYS_DECLINE => _("Always Decline"),
Kronolith_Resource::RESPONSETYPE_AUTO => _("Automatically"),
Kronolith_Resource::RESPONSETYPE_NONE => _("None"));
/* Get a list of available resource groups */
- $driver = Kronolith::getDriver('Resource');
- $groups = $driver->listResources(Horde_Perms::READ, array('type' => Kronolith_Resource::TYPE_GROUP));
+ $groups = Kronolith::getDriver('Resource')
+ ->listResources(Horde_Perms::READ,
+ array('type' => Kronolith_Resource::TYPE_GROUP));
$enum = array();
foreach ($groups as $id => $group) {
$enum[$id] = $group->get('name');
$this->setButtons(array(_("Save")));
}
- function execute()
+ /**
+ * @throws Kronolith_Exception
+ */
+ public function execute()
{
$original_name = $this->_resource->get('name');
$new_name = $this->_vars->get('name');
$group->save();
}
-
- $result = $this->_resource->save();
- if (is_a($result, 'PEAR_Error')) {
- return PEAR::raiseError(sprintf(_("Unable to save resource \"%s\": %s"), $new_name, $result->getMessage()));
+ try {
+ $result = $this->_resource->save();
+ } catch (Exception $e) {
+ throw new Kronolith_Exception(sprintf(_("Unable to save resource \"%s\": %s"), $new_name, $e->getMessage()));
}
return $this->_resource;
-
}
}
<?php
/**
- * Horde_Form for editing resource calendars.
+ * Horde_Form for editing resource groups.
*
* 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.
+ * The Kronolith_EditResourceGroupForm class provides the form for editing
+ * resource groups.
*
* @author Chuck Hagenbuch <chuck@horde.org>
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
* @package Kronolith
*/
-class Kronolith_EditResourceGroupForm extends Horde_Form {
-
+class Kronolith_EditResourceGroupForm extends Horde_Form
+{
/**
- * Calendar being edited
+ * Resource group being edited.
+ *
+ * @var Kronolith_Resource_Single
*/
- var $_resource;
+ protected $_resource;
- function Kronolith_EditResourceGroupForm(&$vars, &$resource)
+ /**
+ * @throws Kronolith_Exception
+ */
+ public function __construct($vars, $resource)
{
- $this->_resource = &$resource;
+ $this->_resource = $resource;
parent::Horde_Form($vars, sprintf(_("Edit %s"), $resource->get('name')));
+
$resources = Kronolith::getDriver('Resource')->listResources(Horde_Perms::READ, array('type' => Kronolith_Resource::TYPE_SINGLE));
$enum = array();
foreach ($resources as $r) {
$this->addVariable(_("Name"), 'name', 'text', true);
$this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
$this->addVariable(_("Resources"), 'members', 'multienum', false, false, null, array('enum' => $enum));
-
$this->setButtons(array(_("Save")));
}
- function execute()
+ /**
+ * @throws Kronolith_Exception
+ */
+ public function execute()
{
$original_name = $this->_resource->get('name');
$new_name = $this->_vars->get('name');
$this->_resource->set('description', $this->_vars->get('description'));
$this->_resource->set('members', $this->_vars->get('members'));
- $result = $this->_resource->save();
- if (is_a($result, 'PEAR_Error')) {
- return PEAR::raiseError(sprintf(_("Unable to save resource \"%s\": %s"), $new_name, $result->getMessage()));
+ try {
+ $this->_resource->save();
+ } catch (Exception $e) {
+ throw new Kronolith_Exception(sprintf(_("Unable to save resource \"%s\": %s"), $new_name, $e->getMessage()));
}
return $this->_resource;
-
}
}
* @package Kronolith
*/
-/** Horde_Form */
-require_once 'Horde/Form.php';
-
-/** Horde_Form_Renderer */
-require_once 'Horde/Form/Renderer.php';
-
/**
- * The Kronolith_SubscribeRemoteCalendarForm class provides the form
- * for subscribing to remote calendars
+ * The Kronolith_SubscribeRemoteCalendarForm class provides the form for
+ * subscribing to remote calendars.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @package Kronolith
*/
-class Kronolith_SubscribeRemoteCalendarForm extends Horde_Form {
-
- function Kronolith_SubscribeRemoteCalendarForm(&$vars)
+class Kronolith_SubscribeRemoteCalendarForm extends Horde_Form
+{
+ public function __construct($vars)
{
parent::Horde_Form($vars, _("Subscribe to a Remote Calendar"));
$this->setButtons(array(_("Subscribe")));
}
- function execute()
+ /**
+ * @throws Kronolith_Exception
+ */
+ public function execute()
{
$info = array();
foreach (array('name', 'url', 'color', 'username', 'password') as $key) {
$info[$key] = $this->_vars->get($key);
}
- return Kronolith::subscribeRemoteCalendar($info);
+ Kronolith::subscribeRemoteCalendar($info);
}
}
* @package Kronolith
*/
-/** Horde_Form */
-require_once 'Horde/Form.php';
-
-/** Horde_Form_Renderer */
-require_once 'Horde/Form/Renderer.php';
-
/**
* The Kronolith_UnsubscribeRemoteCalendarForm class provides the form for
- * deleting a calendar.
+ * unsubscribing from remote calendars.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @package Kronolith
*/
-class Kronolith_UnsubscribeRemoteCalendarForm extends Horde_Form {
-
- function Kronolith_UnsubscribeRemoteCalendarForm(&$vars, $calendar)
+class Kronolith_UnsubscribeRemoteCalendarForm extends Horde_Form
+{
+ public function __construct($vars, $calendar)
{
parent::Horde_Form($vars, sprintf(_("Unsubscribe from %s"), $calendar['name']));
$this->setButtons(array(_("Unsubscribe"), _("Cancel")));
}
- function execute()
+ /**
+ * @throws Kronolith_Exception
+ */
+ public function execute()
{
// If cancel was clicked, return false.
if ($this->_vars->get('submitbutton') == _("Cancel")) {
return false;
}
-
- return Kronolit::unsubscribeRemoteCalendar($this->_vars->get('url'));
+ return Kronolith::unsubscribeRemoteCalendar($this->_vars->get('url'));
}
}
* @author Chuck Hagenbuch <chuck@horde.org>
* @package Kronolith
*/
-class Kronolith_FreeBusy {
+class Kronolith_FreeBusy
+{
/**
* Generates the free/busy text for $calendar. Cache it for at least an
* hour, as well.
* @param string $user Set organizer to this user.
*
* @return string The free/busy text.
+ * @throws Kronolith_Exception
*/
- function generate($calendar, $startstamp = null, $endstamp = null,
- $returnObj = false, $user = null)
+ public static function generate($calendar, $startstamp = null,
+ $endstamp = null, $returnObj = false,
+ $user = null)
{
global $kronolith_shares;
}
/* Fetch the appropriate share and check permissions. */
- $share = &$kronolith_shares->getShare($calendar[0]);
- if (is_a($share, 'PEAR_Error')) {
+ try {
+ $share = $kronolith_shares->getShare($calendar[0]);
+ $owner = $share->get('owner');
+ } catch (Exception $e) {
// Might be a Kronolith_Resource
try {
$resource = Kronolith_Resource::isResourceCalendar($calendar[0]);
} catch (Horde_Exception $e) {
return $returnObj ? $share : '';
}
- } else {
- $owner = $share->get('owner');
}
/* Default the start date to today. */
/* Fetch events. */
$busy = Kronolith::listEvents(new Horde_Date($startstamp), $enddate, $calendar);
- if (is_a($busy, 'PEAR_Error')) {
- return $busy;
- }
/* Create the new iCalendar. */
$vCal = new Horde_iCalendar();
$vCal->setAttribute('METHOD', 'PUBLISH');
/* Create new vFreebusy. */
- $vFb = &Horde_iCalendar::newComponent('vfreebusy', $vCal);
+ $vFb = Horde_iCalendar::newComponent('vfreebusy', $vCal);
$params = array();
if (!empty($cn)) {
$params['CN'] = $cn;
*
* @return Horde_iCalendar_vfreebusy Free/busy component on success,
* PEAR_Error on failure.
+ * @throws Kronolith_Exception
*/
- function get($email, $json = false)
+ public static function get($email, $json = false)
{
/* Properly handle RFC822-compliant email addresses. */
static $rfc822;
return $res;
}
if (!count($res)) {
- return PEAR::raiseError(_("No valid email address found"));
+ throw new Kronolith_Exception(_("No valid email address found"));
}
$email = Horde_Mime_Address::writeAddress($res[0]->mailbox, $res[0]->host);
/* Check if we can retrieve a VFB from the Free/Busy URL, if one is
* set. */
- $url = Kronolith_FreeBusy::getUrl($email);
+ $url = self::getUrl($email);
if ($url) {
$url = trim($url);
$options['method'] = 'GET';
$http = new HTTP_Request($url, $options);
if (is_a($response = @$http->sendRequest(), 'PEAR_Error')) {
- return PEAR::raiseError(sprintf(_("The free/busy url for %s cannot be retrieved."), $email));
+ throw new Kronolith_Exception(sprintf(_("The free/busy url for %s cannot be retrieved."), $email));
}
if ($http->getResponseCode() == 200 &&
$data = $http->getResponseBody()) {
}
if ($found) {
- return $json ? Kronolith_FreeBusy::toJson($vFb) : $vFb;
+ // @todo: actually store the results in the storage, so
+ // that they can be retrieved later. We should store the
+ // plain iCalendar data though, to avoid versioning
+ // problems with serialize iCalendar objects.
+ return $json ? self::toJson($vFb) : $vFb;
}
}
}
/* Check storage driver. */
- $storage = Kronolith_Storage::singleton();
-
- $fb = $storage->search($email);
- if (!is_a($fb, 'PEAR_Error')) {
- return $json ? Kronolith_FreeBusy::toJson($fb) : $fb;
- } elseif ($fb->getCode() == Kronolith::ERROR_FB_NOT_FOUND) {
- return $url ?
- PEAR::raiseError(sprintf(_("No free/busy information found at the free/busy url of %s."), $email)) :
- PEAR::raiseError(sprintf(_("No free/busy url found for %s."), $email));
+ $storage = Kronolith_Storage::factory();
+
+ try {
+ $fb = $storage->search($email);
+ return $json ? self::toJson($fb) : $fb;
+ } catch (Kronolith_Exception $e) {
+ if ($e->getCode() == Kronolith::ERROR_FB_NOT_FOUND) {
+ if ($url) {
+ throw new Kronolith_Exception(sprintf(_("No free/busy information found at the free/busy url of %s."), $email));
+ }
+ throw new Kronolith_Exception(sprintf(_("No free/busy url found for %s."), $email));
+ }
}
/* Or else return an empty VFB object. */
$vFb = Horde_iCalendar::newComponent('vfreebusy', $vCal);
$vFb->setAttribute('ORGANIZER', $email);
- return $json ? Kronolith_FreeBusy::toJson($vFb) : $vFb;
+ return $json ? self::toJson($vFb) : $vFb;
}
/**
*
* @return mixed The url on success or false on failure.
*/
- function getUrl($email)
+ public static function getUrl($email)
{
$sources = $GLOBALS['prefs']->getValue('search_sources');
$sources = empty($sources) ? array() : explode("\t", $sources);
* @param unknown_type $params Any driver specific parameters
*
* @return Kronolith_Geo
+ * @throws Kronolith_Exception
*/
static public function factory($driver = null, $params = array())
{
$driver = basename($driver);
$class = 'Kronolith_Geo_' . $driver;
-
- if (class_exists($class)) {
- $driver = new $class(Horde::getDriverConfig('calendar', 'sql'));
- }
-
+ $driver = new $class(Horde::getDriverConfig('calendar', 'sql'));
$driver->initialize();
return $driver;
}
* Set the location of the specified event _id
*
* @see kronolith/lib/Driver/Kronolith_Driver_Geo#setLocation($event_id, $point)
+ * @throws Kronolith_Exception
*/
public function setLocation($event_id, $point)
{
$sql = "SELECT COUNT(*) FROM kronolith_events_geo WHERE event_id = ('" . $event_id . "')";
$count = $this->_db->getOne($sql);
if ($count instanceof PEAR_Error) {
- throw new Horde_Exception($count->getMessage());
+ Horde::logMessage($count, __FILE__, __LINE__, PEAR_LOG_ERR);
+ throw new Horde_Exception($count);
}
/* Do we actually have data? */
}
$result = $this->_write_db->query($sql);
if ($result instanceof PEAR_Error) {
- throw new Horde_Exception($result->getMessage());
+ Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+ throw new Horde_Exception($result);
}
return $result;
* Get the location of the provided event_id.
*
* @see kronolith/lib/Driver/Kronolith_Driver_Geo#getLocation($event_id)
+ * @throws Kronolith_Exception
*/
public function getLocation($event_id)
{
$sql = "SELECT x(event_coordinates) as lat, y(event_coordinates) as lon FROM kronolith_events_geo WHERE event_id = '" . $event_id . "'";
$result = $this->_db->getRow($sql, null, DB_FETCHMODE_ASSOC);
if ($result instanceof PEAR_Error) {
- throw new Horde_Exception($result->getMessage());
+ Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+ throw new Horde_Exception($result);
}
return $result;
}
* MBRs
*
* @see kronolith/lib/Driver/Kronolith_Driver_Geo#search($criteria)
+ * @throws Kronolith_Exception
*/
public function search($criteria)
{
$results = $this->_db->getAssoc($sql, false, null, DB_FETCHMODE_ASSOC);
if ($results instanceof PEAR_Error) {
- throw new Horde_Exception($results->getMessage());
+ Horde::logMessage($results, __FILE__, __LINE__, PEAR_LOG_ERR);
+ throw new Horde_Exception($results);
}
return $results;
-
}
}
\ No newline at end of file
<?php
/**
- * General SQL implementation for storing/searching geo location data for events.
+ * General SQL implementation for storing/searching geo location data for
+ * events.
*
* Copyright 2009-2010 The Horde Project (http://www.horde.org/)
*
protected $_db;
/**
- * Still needs to return a PEAR_Error since Kronolith_Driver still expects it
- *
- * @return mixed boolean || PEAR_Error
+ * @throws Kronolith_Exception
*/
public function initialize()
{
$this->_write_db = DB::connect($this->_params,
array('persistent' => !empty($this->_params['persistent']),
'ssl' => !empty($this->_params['ssl'])));
- if (is_a($this->_write_db, 'PEAR_Error')) {
- return $this->_write_db;
+ if ($this->_write_db instanceof PEAR_Error) {
+ throw new Kronolith_Exception($this->_write_db);
}
$this->_initConn($this->_write_db);
$this->_db = DB::connect($params,
array('persistent' => !empty($params['persistent']),
'ssl' => !empty($params['ssl'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- return $this->_db;
+ if ($this->_db instanceof PEAR_Error) {
+ throw new Kronolith_Exception($this->_db);
}
$this->_initConn($this->_db);
} else {
default:
$db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
}
-
- /* Handle any database specific initialization code to run. */
- switch ($db->dbsyntax) {
- case 'oci8':
- $query = "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'";
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Kronolith_Driver_Sql::_initConn(): user = "%s"; query = "%s"',
- Horde_Auth::getAuth(), $query),
- __FILE__, __LINE__, PEAR_LOG_DEBUG);
-
- $db->query($query);
- break;
-
- case 'pgsql':
- $query = "SET datestyle TO 'iso'";
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Kronolith_Driver_Sql::_initConn(): user = "%s"; query = "%s"',
- Horde_Auth::getAuth(), $query),
- __FILE__, __LINE__, PEAR_LOG_DEBUG);
-
- $db->query($query);
- break;
- }
}
/**
* Set the location of the specified event _id
*
* @see kronolith/lib/Driver/Kronolith_Driver_Geo#setLocation($event_id, $point)
+ * @throws Kronolith_Exception
*/
public function setLocation($event_id, $point)
{
$sql = 'SELECT COUNT(*) FORM kronolith_events_geo WHERE event_id = ?';
$count = $this->_db->getOne($sql, array($event_id));
if ($count instanceof PEAR_Error) {
- throw new Horde_Exception($count->getMessage());
+ Horde::logMessage($count, __FILE__, __LINE__, PEAR_LOG_ERR);
+ throw new Horde_Exception($count);
}
/* Do we actually have data? If not, see if we are deleting an
}
$result = $this->_write_db->query($sql, $params);
if ($result instanceof PEAR_Error) {
- throw new Horde_Exception($result->getMessage());
+ Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+ throw new Horde_Exception($result);
}
return $result;
* Get the location of the provided event_id.
*
* @see kronolith/lib/Driver/Kronolith_Driver_Geo#getLocation($event_id)
+ * @throws Kronolith_Exception
*/
public function getLocation($event_id)
{
$sql = 'SELECT event_lat as lat, event_lng as lng FROM kronolith_events_geo WHERE event_id = ?';
$result = $this->_db->getRow($sql, array($event_id), DB_FETCHMODE_ASSOC);
if ($result instanceof PEAR_Error) {
- throw new Horde_Exception($result->getMessage());
+ Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+ throw new Horde_Exception($result);
}
return $result;
public function deleteLocation($event_id)
{
$sql = 'DELETE FROM kronolith_events_geo WHERE event_id = ?';
- $this->_write_db->query($sql, array($event_id));
+ $result = $this->_write_db->query($sql, array($event_id));
+ if ($result instanceof PEAR_Error) {
+ Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+ throw new Horde_Exception($result);
+ }
}
/**
* MBRs
*
* @see kronolith/lib/Driver/Kronolith_Driver_Geo#search($criteria)
+ * @throws Kronolith_Exception
*/
public function search($criteria)
{
*
* @return array The alarms active on the date. A hash with calendar names
* as keys and arrays of events or event ids as values.
+ * @throws Kronolith_Exception
*/
public static function listAlarms($date, $calendars, $fullevent = false)
{
foreach ($calendars as $cal) {
$kronolith_driver->open($cal);
$alarms[$cal] = $kronolith_driver->listAlarms($date, $fullevent);
- if (is_a($alarms[$cal], 'PEAR_Error')) {
- return $alarms[$cal];
- }
}
return $alarms;
* "Driver|calendar_id".
*
* @return array The events.
+ * @throws Kronolith_Exception
*/
public static function search($query, $calendar = null)
{
* listTimeObjects as well?
*
* @return array The events happening in this time period.
+ * @throws Kronolith_Exception
*/
public static function listEvents($startDate, $endDate, $calendars = null,
$showRecurrence = true,
foreach ($calendars as $calendar) {
$driver->open($calendar);
$events = $driver->listEvents($startDate, $endDate, true);
- if (!is_a($events, 'PEAR_Error')) {
- self::mergeEvents($results, $events);
- }
+ self::mergeEvents($results, $events);
}
/* Resource calendars (this would only be populated if explicitly
foreach ($GLOBALS['display_resource_calendars'] as $calendar) {
$driver->open($calendar);
$events = $driver->listEvents($startDate, $endDate, true);
- if (!is_a($events, 'PEAR_Error')) {
- self::mergeEvents($results, $events);
- }
+ self::mergeEvents($results, $events);
}
}
foreach ($GLOBALS['display_external_calendars'] as $external_cal) {
$driver->open($external_cal);
$events = $driver->listEvents($startDate, $endDate, true);
- if (!is_a($events, 'PEAR_Error')) {
- self::mergeEvents($results, $events);
- }
+ self::mergeEvents($results, $events);
}
/* Remote Calendars. */
$driver->setParam($param, $value);
}
$events = $driver->listEvents($startDate, $endDate, true);
- if (!is_a($events, 'PEAR_Error')) {
- self::mergeEvents($results, $events);
- }
+ self::mergeEvents($results, $events);
}
/* Holidays. */
foreach ($GLOBALS['display_holidays'] as $holiday) {
$driver->open($holiday);
$events = $driver->listEvents($startDate, $endDate, true);
- if (!is_a($events, 'PEAR_Error')) {
- self::mergeEvents($results, $events);
- }
+ self::mergeEvents($results, $events);
}
}
/**
* Calculates recurrences of an event during a certain period.
- *
- * @access private
*/
public static function addEvents(&$results, &$event, $startDate, $endDate,
$showRecurrence, $json, $coverDates = true)
$count = 0;
foreach (array_keys($calendars) as $calendar) {
$kronolith_driver->open($calendar);
- $count += $kronolith_driver->countEvents();
+ try {
+ $count += $kronolith_driver->countEvents();
+ } catch (Exception $e) {
+ }
}
/* Reopen last calendar. */
* calendar will be used.
*
* @return array The UID of all events that were added.
+ * @throws Kronolith_Exception
*/
public function quickAdd($text, $calendar = null)
{
$event->description = $description;
$event->start = $d;
$event->end = $d->add(array('hour' => 1));
+ $event->save();
- $eventId = $event->save();
- if (is_a($eventId, 'PEAR_Error')) {
- return $eventId;
- }
return $event;
}
* @param array $info Hash with calendar information.
*
* @return Horde_Share The new share.
+ * @throws Kronolith_Exception
*/
public static function addShare($info)
{
$calendar = $GLOBALS['kronolith_shares']->newShare(hash('md5', microtime()));
- if (is_a($calendar, 'PEAR_Error')) {
- return $calendar;
+ if ($calendar instanceof PEAR_Error) {
+ throw new Kronolith_Exception($calendar);
}
$calendar->set('name', $info['name']);
$tagger->tag($calendar->getName(), $info['tags'], 'calendar');
$result = $GLOBALS['kronolith_shares']->addShare($calendar);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
+ if ($result instanceof PEAR_Error) {
+ throw new Kronolith_Exception($result);
}
$GLOBALS['display_calendars'][] = $calendar->getName();
*
* @param Horde_Share $share The share to update.
* @param array $info Hash with calendar information.
+ *
+ * @throws Kronolith_Exception
*/
public static function updateShare(&$calendar, $info)
{
if (!Horde_Auth::getAuth() ||
($calendar->get('owner') != Horde_Auth::getAuth() &&
(!is_null($calendar->get('owner')) || !Horde_Auth::isAdmin()))) {
- return PEAR::raiseError(_("You are not allowed to change this calendar."));
+ throw new Kronolith_Exception(_("You are not allowed to change this calendar."));
}
$original_name = $calendar->get('name');
$calendar->set('color', $info['color']);
$calendar->set('desc', $info['description']);
$calendar->set('owner', empty($info['system']) ? Horde_Auth::getAuth() : null);
- if ($original_name != $info['name']) {
- $result = Kronolith::getDriver()->rename($original_name, $info['name']);
- if (is_a($result, 'PEAR_Error')) {
- return PEAR::raiseError(sprintf(_("Unable to rename \"%s\": %s"), $original_name, $result->getMessage()));
- }
- }
$result = $calendar->save();
- if (is_a($result, 'PEAR_Error')) {
- return PEAR::raiseError(sprintf(_("Unable to save calendar \"%s\": %s"), $info['name'], $result->getMessage()));
+ if ($result instanceof PEAR_Error) {
+ throw new Kronolith_Exception(sprintf(_("Unable to save calendar \"%s\": %s"), $info['name'], $result->getMessage()));
}
$tagger = self::getTagger();
* Deletes a share.
*
* @param Horde_Share $calendar The share to delete.
+ *
+ * @throws Kronolith_Exception
*/
public static function deleteShare($calendar)
{
if ($calendar->getName() == Horde_Auth::getAuth()) {
- return PEAR::raiseError(_("This calendar cannot be deleted."));
+ throw new Kronolith_Exception(_("This calendar cannot be deleted."));
}
if (!Horde_Auth::getAuth() ||
($calendar->get('owner') != Horde_Auth::getAuth() &&
(!is_null($calendar->get('owner')) || !Horde_Auth::isAdmin()))) {
- return PEAR::raiseError(_("You are not allowed to delete this calendar."));
+ throw new Kronolith_Exception(_("You are not allowed to delete this calendar."));
}
// Delete the calendar.
- $result = Kronolith::getDriver()->delete($calendar->getName());
- if (is_a($result, 'PEAR_Error')) {
- return PEAR::raiseError(sprintf(_("Unable to delete \"%s\": %s"), $calendar->get('name'), $result->getMessage()));
+ try {
+ Kronolith::getDriver()->delete($calendar->getName());
+ } catch (Exception $e) {
+ throw new Kronolith_Exception(sprintf(_("Unable to delete \"%s\": %s"), $calendar->get('name'), $ed->getMessage()));
}
// Remove share and all groups/permissions.
- return $GLOBALS['kronolith_shares']->removeShare($calendar);
+ $result = $GLOBALS['kronolith_shares']->removeShare($calendar);
+ if ($result instanceof PEAR_Error) {
+ throw new Kronolith_Exception($result);
+ }
}
/**
* Subscribes to a remote calendar.
*
* @param array $info Hash with calendar information.
+ *
+ * @throws Kronolith_Exception
*/
public static function subscribeRemoteCalendar($info)
{
if (!(strlen($info['name']) && strlen($info['url']))) {
- return PEAR::raiseError(_("You must specify a name and a URL."));
+ throw new Kronolith_Exception(_("You must specify a name and a URL."));
}
if (strlen($info['username']) || strlen($info['password'])) {
* @param string $url The calendar URL.
*
* @return array Hash with the deleted calendar's information.
+ * @throws Kronolith_Exception
*/
public static function unsubscribeRemoteCalendar($url)
{
}
}
if (!$remote_calendar) {
- return PEAR::raiseError(_("The remote calendar was not found."));
+ throw new Kronolith_Exception(_("The remote calendar was not found."));
}
$GLOBALS['prefs']->setValue('remote_cals', serialize($remote_calendars));
*/
public static function parseAttendees($newAttendees)
{
+ global $notification;
+
if (empty($newAttendees)) {
return;
}
$myemail = explode('@', $myemail);
$from = Horde_Mime_Address::writeAddress($myemail[0], isset($myemail[1]) ? $myemail[1] : '', $ident->getValue('fullname'));
- $share = &$GLOBALS['kronolith_shares']->getShare($event->calendar);
+ $share = $GLOBALS['kronolith_shares']->getShare($event->calendar);
foreach ($event->attendees as $email => $status) {
/* Don't bother sending an invitation/update if the recipient does
* @param Kronolith_Event $event An event.
* @param string $action The event action. One of "add", "edit",
* or "delete".
+ *
+ * @throws Horde_Mime_Exception
+ * @throws Kronolith_Exception
*/
- public static function sendNotification(&$event, $action)
+ public static function sendNotification($event, $action)
{
global $conf;
if (!in_array($action, array('add', 'edit', 'delete'))) {
- return PEAR::raiseError('Unknown event action: ' . $action);
+ throw new Kronolith_Exception('Unknown event action: ' . $action);
}
require_once 'Horde/Group.php';
- $groups = &Group::singleton();
+ $groups = Group::singleton();
$calendar = $event->calendar;
$recipients = array();
- $share = &$GLOBALS['kronolith_shares']->getShare($calendar);
- if (is_a($share, 'PEAR_Error')) {
- return $share;
+ $share = $GLOBALS['kronolith_shares']->getShare($calendar);
+ if ($share instanceof PEAR_Error) {
+ throw new Kronolith_Exception($share);
}
$identity = Horde_Prefs_Identity::singleton();
foreach ($share->listGroups(Horde_Perms::READ) as $group) {
$group = $groups->getGroupById($group);
- if (is_a($group, 'PEAR_Error')) {
+ if ($group instanceof PEAR_Error) {
continue;
}
$group_users = $group->listAllUsers();
- if (is_a($group_users, 'PEAR_Error')) {
+ if ($group_users instanceof PEAR_Error) {
Horde::logMessage($group_users, __FILE__, __LINE__, PEAR_LOG_ERR);
continue;
}
$mail->addHeader('User-Agent', 'Kronolith ' . $GLOBALS['registry']->getVersion());
$mime_mail->setBody($message, Horde_Nls::getCharset(), true);
Horde::logMessage(sprintf('Sending event notifications for %s to %s', $event->title, implode(', ', $df_recipients)), __FILE__, __LINE__, PEAR_LOG_DEBUG);
- try {
- $mime_mail->send(Horde::getMailerConfig(), false, false);
- } catch (Horde_Mime_Exception $e) {}
+ $mime_mail->send(Horde::getMailerConfig(), false, false);
}
}
}
-
- return true;
}
/**
* Check for resource declines and push notice to stack if found.
*
- * @param Kronolith_Event #
+ * @param Kronolith_Event $event
+ *
+ * @throws Kronolith_Exception
*/
public static function notifyOfResourceRejection($event)
{
*
* @return Kronolith_Driver The newly created concrete Kronolith_Driver
* instance, or a PEAR_Error on error.
+ * @throws Kronolith_Exception
*/
public static function getDriver($driver = null, $calendar = null)
{
case 'Holidays':
if (empty($GLOBALS['conf']['holidays']['enable'])) {
- return PEAR::raiseError(_("Holidays are disabled"));
+ throw new Kronolith_Exception(_("Holidays are disabled"));
}
$params['language'] = $GLOBALS['language'];
break;
default:
- return PEAR::raiseError('No calendar driver specified');
+ throw new Kronolith_Exception('No calendar driver specified');
break;
}
case 'EditEvent':
case 'DeleteEvent':
case 'ExportEvent':
- if ($uid = Horde_Util::getFormData('uid')) {
- $event = self::getDriver()->getByUID($uid);
- } else {
- $event = self::getDriver(Horde_Util::getFormData('type'),
- Horde_Util::getFormData('calendar'))
- ->getEvent(Horde_Util::getFormData('eventID'),
- Horde_Util::getFormData('datetime'));
+ try {
+ if ($uid = Horde_Util::getFormData('uid')) {
+ $event = self::getDriver()->getByUID($uid);
+ } else {
+ $event = self::getDriver(Horde_Util::getFormData('type'),
+ Horde_Util::getFormData('calendar'))
+ ->getEvent(Horde_Util::getFormData('eventID'),
+ Horde_Util::getFormData('datetime'));
+ }
+ } catch (Horde_Exception $e) {
+ $event = $e->getMessage();
}
switch ($view) {
case 'Event':
- if (!is_a($event, 'PEAR_Error') &&
+ if (!is_string($event) &&
!$event->hasPermission(Horde_Perms::READ)) {
- $event = PEAR::raiseError(_("Permission Denied"));
+ $event = _("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') &&
+ if (!is_string($event) &&
!$event->hasPermission(Horde_Perms::READ)) {
- $event = PEAR::raiseError(_("Permission Denied"));
+ $event = _("Permission Denied");
}
return new Kronolith_View_EditEvent($event);
case 'DeleteEvent':
- if (!is_a($event, 'PEAR_Error') &&
+ if (!is_string($event) &&
!$event->hasPermission(Horde_Perms::DELETE)) {
- $event = PEAR::raiseError(_("Permission Denied"));
+ $event = _("Permission Denied");
}
return new Kronolith_View_DeleteEvent($event);
case 'ExportEvent':
- if (!is_a($event, 'PEAR_Error') &&
+ if (!is_string($event) &&
!$event->hasPermission(Horde_Perms::READ)) {
- $event = PEAR::raiseError(_("Permission Denied"));
+ $event = _("Permission Denied");
}
return new Kronolith_View_ExportEvent($event);
}
if (empty(self::$_tagger)) {
self::$_tagger = new Kronolith_Tagger();
}
-
return self::$_tagger;
}
public static function getGeoDriver()
{
- /* Get geolocation data */
if (!empty($GLOBALS['conf']['maps']['geodriver'])) {
- return Kronolith_Geo::factory($GLOBALS['conf']['maps']['geodriver']);
- } else {
- return false;
+ try {
+ return Kronolith_Geo::factory($GLOBALS['conf']['maps']['geodriver']);
+ } catch (Exception $e) {
+ Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
+ }
}
+ return false;
}
/**
*
* @param string $target The calendar id to retrieve.
*
- * @return mixed Kronolith_Resource or Horde_Share_Object
+ * @return Kronolith_Resource|Horde_Share_Object
+ * @throws Kronolith_Exception
*/
static public function getInternalCalendar($target)
{
* Purge old messages in the Trash folder.
*
* @return boolean Whether any messages were purged from the Trash folder.
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
*/
public function execute()
{
$del_time = new Horde_Date($_SERVER['REQUEST_TIME']);
$del_time->mday -= $GLOBALS['prefs']->getValue('purge_events_keep');
- /* Need to have Horde_Perms::DELETE on a calendar to delete events from it */
+ /* Need to have Horde_Perms::DELETE on a calendar to delete events
+ * from it */
$calendars = Kronolith::listCalendars(false, Horde_Perms::DELETE);
/* Start building an event object to use for the search */
$kronolith_driver = Kronolith::getDriver();
- $query = &$kronolith_driver->getEvent();
+ $query = $kronolith_driver->getEvent();
$query->start = null;
$query->end = $del_time;
$query->status = null;
if ($event->calendar != $kronolith_driver->calendar) {
$kronolith_driver->open($event->calendar);
}
- $results = $kronolith_driver->deleteEvent($event->id, true);
- ++$count;
- if (is_a($results, 'PEAR_Error')) {
- Horde::logMessage($results, __FILE__, __LINE__, PEAR_LOG_ERR);
- return $results;
+ try {
+ $results = $kronolith_driver->deleteEvent($event->id, true);
+ ++$count;
+ } catch (Exception $e) {
+ Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
+ throw $e;
}
}
}
/**
* Save resource to storage.
+ *
+ * @return Kronolith_Resource object
+ * @throws Kronolith_Exception
*/
public function save()
{
- $d = $this->getDriver();
- return $d->save($this);
+ return $this->getDriver()->save($this);
}
/**
*
*
* @return boolean
+ * @throws Kronolith_Exception
*/
public function isFree($event)
{
$conflict = false;
$resource = $this->_driver->getResource($resource_id);
$busy = Kronolith::listEvents($start, $end, array($resource->get('calendar')));
- if ($busy instanceof PEAR_Error) {
- throw new Horde_Exception($busy->getMessage());
- }
/* No events at all during time period for requested event */
if (!count($busy)) {
*
*
* @return boolean
+ * @throws Kronolith_Exception
*/
public function isFree($event)
{
/* Fetch events. */
$busy = Kronolith::listEvents($start, $end, array($this->get('calendar')));
- if ($busy instanceof PEAR_Error) {
- throw new Horde_Exception($busy->getMessage());
- }
/* No events at all during time period for requested event */
if (!count($busy)) {
*
* @param $event
*
- * @return void
+ * @throws Kronolith_Exception
*/
public function addEvent($event)
{
/* Make sure it's not already attached. */
$uid = $event->uid;
- $existing = $driver->getByUID($uid, array($this->get('calendar')));
- if (!($existing instanceof PEAR_Error)) {
+ try {
+ $existing = $driver->getByUID($uid, array($this->get('calendar')));
/* Already attached, just update */
$this->_copyEvent($event, $existing);
$result = $existing->save();
- if (is_a($result, 'PEAR_Error')) {
- throw new Kronolith_Exception($result->getMessage());
- }
- } else {
+ } catch (Horde_Exception_NotFound $ex) {
/* Create a new event */
$e = $driver->getEvent();
$this->_copyEvent($event, $e);
$result = $e->save();
- if (is_a($result, 'PEAR_Error')) {
- throw new Kronolith_Exception($result->getMessage());
- }
}
}
* Remove this event from resource's calendar
*
* @param $event
- * @return unknown_type
+ *
+ * @throws Kronolith_Exception
+ * @throws Horde_Exception_NotFound
*/
public function removeEvent($event)
{
$driver = Kronolith::getDriver('Resource', $this->get('calendar'));
$re = $driver->getByUID($event->uid, 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)) {
- $driver->deleteEvent($re->id);
- }
+ $driver->deleteEvent($re->id);
}
/**
<?php
/**
- * Kronolith_Storage:: defines an API for storing free/busy information.
+ * Kronolith_Storage defines an API for storing free/busy information.
*
* @author Mike Cochrane <mike@graftonhall.co.nz>
* @package Kronolith
*/
-class Kronolith_Storage {
-
+abstract class Kronolith_Storage
+{
/**
* String containing the current username.
*
* @var string
*/
- var $_user = '';
+ protected $_user = '';
/**
- * Attempts to return a concrete Kronolith_Storage instance based on $driver.
- *
- * @param string $driver The type of concrete Kronolith_Storage subclass
- * to return. The is based on the storage
- * driver ($driver). The code is dynamically
- * included.
- *
- * @param string $user The name of the user who owns the free/busy
- * information
+ * Attempts to return a concrete Kronolith_Storage instance based on
+ * $driver.
*
- * @param array $params (optional) A hash containing any additional
- * configuration or connection parameters a
- * subclass might need.
+ * @param string $driver The type of concrete Kronolith_Storage subclass
+ * to return. The is based on the storage driver
+ * ($driver). The code is dynamically included.
+ * @param string $user The name of the user who owns the free/busy
+ * information.
+ * @param array $params A hash containing any additional configuration or
+ * connection parameters a subclass might need.
*
- * @return mixed The newly created concrete Kronolith_Storage instance, or
- * false on an error.
+ * @return Kronolith_Storage The newly created concrete Kronolith_Storage
+ * instance.
+ * @throws Kronolith_Exception
*/
- function &factory($user = null, $driver = null, $params = null)
+ public static function factory($user = null, $driver = null, $params = null)
{
if (is_null($user)) {
$user = Horde_Auth::getAuth();
if (class_exists($class)) {
$driver = new $class($user, $params);
} else {
- $driver = PEAR::raiseError(sprintf(_("Unable to load the definition of %s."), $class));
- return $driver;
+ throw new Kronolith_Exception(sprintf(_("Unable to load the definition of %s."), $class));
}
- $result = $driver->initialize();
- if (is_a($result, 'PEAR_Error')) {
+ try {
+ $driver->initialize();
+ } catch (Exception $e) {
$driver = new Kronolith_Storage($params);
}
}
/**
- * Attempts to return a reference to a concrete Kronolith_Storage instance
- * based on $driver. It will only create a new instance if no
- * Kronolith_Storage instance with the same parameters currently exists.
- *
- * This should be used if multiple storage sources are required.
- *
- * This method must be invoked as: $var = &Kronolith_Storage::singleton()
- *
- * @param string $driver The type of concrete Kronolith_Storage subclass
- * to return. The is based on the storage
- * driver ($driver). The code is dynamically
- * included.
- *
- * @param string $user The name of the user who owns the free/busy
- * information
- *
- * @param array $params (optional) A hash containing any additional
- * configuration or connection parameters a
- * subclass might need.
- *
- * @return mixed The created concrete Kronolith_Storage instance, or false
- * on error.
- */
- function &singleton($user = null, $driver = null, $params = null)
- {
- static $instances = array();
-
- if (is_null($user)) {
- $user = Horde_Auth::getAuth();
- }
-
- if (is_null($driver)) {
- $driver = $GLOBALS['conf']['storage']['driver'];
- }
-
- if (is_null($params)) {
- $params = Horde::getDriverConfig('storage', $driver);
- }
-
- $signature = serialize(array($user, $driver, $params));
- if (!isset($instances[$signature])) {
- $instances[$signature] = &Kronolith_Storage::factory($user, $driver, $params);
- }
-
- return $instances[$signature];
- }
-
- /**
* Stub to initiate a driver.
+ * @throws Kronolith_Exception
*/
function initialize()
{
/**
* Stub to be overridden in the child class.
*/
- function search()
- {
- return PEAR::raiseError(_("Searching free/busy is not available."));
- }
+ abstract public function search($email, $private_only = false);
/**
* Stub to be overridden in the child class.
*/
- function store()
- {
- return PEAR::raiseError(_("Storing free/busy is not available."));
- }
-
+ abstract public function store($email, $vfb, $public = false);
}
<?php
-
-require_once 'Horde/iCalendar.php';
-require_once 'Horde/Kolab.php';
-
/**
* Horde Kronolith free/busy driver for the Kolab IMAP Server.
* Copyright 2004-2010 The Horde Project (http://www.horde.org/)
* @author Stuart Binge <omicron@mighty.co.za>
* @package Kronolith
*/
-class Kronolith_Storage_kolab extends Kronolith_Storage {
-
- var $_params = array();
+class Kronolith_Storage_kolab extends Kronolith_Storage
+{
+ protected $_params = array();
- function Kronolith_Storage_kolab($user, $params = array())
+ function __construct($user, $params = array())
{
$this->_user = $user;
$this->_params = $params;
}
- function search($email, $private_only = false)
+ /**
+ * @throws Kronolith_Exception
+ */
+ public function search($email, $private_only = false)
{
global $conf;
if (class_exists('Horde_Kolab_Session')) {
- $session = &Horde_Kolab_Session::singleton();
+ $session = Horde_Kolab_Session::singleton();
$server = $session->freebusy_server;
- } else if (!is_callable('Kolab', 'getServer')) {
- $server = sprintf('%s://%s:%d/freebusy/',
- $conf['storage']['freebusy']['protocol'],
- $conf['kolab']['imap']['server'],
- $conf['storage']['freebusy']['port']);
} else {
$server = sprintf('%s://%s:%d/freebusy/',
$conf['storage']['freebusy']['protocol'],
$options = array_merge($options, $GLOBALS['conf']['http']['proxy']);
}
- require_once 'HTTP/Request.php';
$http = new HTTP_Request($fb_url, $options);
$http->setBasicAuth(Horde_Auth::getAuth(), Horde_Auth::getCredential('password'));
@$http->sendRequest();
if ($http->getResponseCode() != 200) {
- return PEAR::raiseError(sprintf(_("Unable to retrieve free/busy information for %s"),
+ throw new Kronolith_Exception(sprintf(_("Unable to retrieve free/busy information for %s"),
$email), Kronolith::ERROR_FB_NOT_FOUND);
}
$vfb_text = $http->getResponseBody();
$vfb = &$iCal->findComponent('VFREEBUSY');
if ($vfb === false) {
- return PEAR::raiseError(sprintf(_("No free/busy information is available for %s"),
+ throw new Kronolith_Exception(sprintf(_("No free/busy information is available for %s"),
$email), Kronolith::ERROR_FB_NOT_FOUND);
}
return $vfb;
}
- function store($email, $vfb, $public = false)
+ public function store($email, $vfb, $public = false)
{
// We don't care about storing FB info at the moment; we rather let
// Kolab's freebusy.php script auto-generate it for us.
- return true;
}
}
<?php
/**
- * Kronolith_Storage:: defines an API for storing free/busy
- * information.
+ * Kronolith_Storage:: defines an API for storing free/busy information.
*
* @author Mike Cochrane <mike@graftonhall.co.nz>
* @package Kronolith
*/
-class Kronolith_Storage_sql extends Kronolith_Storage {
-
+class Kronolith_Storage_sql extends Kronolith_Storage
+{
/**
* Handle for the current database connection, used for reading.
*
* @var DB
*/
- var $_db;
+ protected $_db;
/**
* Handle for the current database connection, used for writing. Defaults
*
* @var DB
*/
- var $_write_db;
+ protected $_write_db;
/**
* Hash containing connection parameters.
*
* @var array
*/
- var $_params = array();
+ protected $_params = array();
/**
* Constructs a new Kronolith_Storage SQL instance.
*
* @param array $params A hash containing connection parameters.
*/
- function Kronolith_Storage_sql($user, $params = array())
+ public function __construct($user, $params = array())
{
$this->_user = $user;
/**
* Connect to the database
*
- * @return boolean True on success or PEAR_Error on failure.
+ * @throws Kronolith_Exception
*/
- function initialize()
+ public function initialize()
{
Horde::assertDriverConfig($this->_params, 'storage',
array('phptype'),
$this->_write_db = &DB::connect($this->_params,
array('persistent' => !empty($this->_params['persistent']),
'ssl' => !empty($this->_params['ssl'])));
- if (is_a($this->_write_db, 'PEAR_Error')) {
- return PEAR::raiseError(_("Unable to connect to SQL server."));
+ if ($this->_write_db instanceof PEAR_Error) {
+ throw new Kronolith_Exception($this->_write_db);
}
+ $this->_initConn($this->_write_db);
- // Set DB portability options.
- switch ($this->_write_db->phptype) {
- case 'mssql':
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- /* Check if we need to set up the read DB connection
- * seperately. */
+ /* Check if we need to set up the read DB connection seperately. */
if (!empty($this->_params['splitread'])) {
$params = array_merge($this->_params, $this->_params['read']);
$this->_db = &DB::connect($params,
array('persistent' => !empty($params['persistent']),
'ssl' => !empty($params['ssl'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- return $this->_db;
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+ if ($this->_db instanceof PEAR_Error) {
+ throw new Kronolith_Exception($this->_db);
}
-
+ $this->_initConn($this->_db);
} else {
/* Default to the same DB handle for the writer too. */
$this->_db =& $this->_write_db;
}
+ }
- return true;
+ /**
+ */
+ private function _initConn(&$db)
+ {
+ // Set DB portability options.
+ switch ($db->phptype) {
+ case 'mssql':
+ $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
+ break;
+ default:
+ $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+ }
}
/**
*
* @return object Horde_iCalendar_vFreebusy on success
* PEAR_Error on error or not found
+ * @throws Kronolith_Exception
*/
- function search($email, $private_only = false)
+ public function search($email, $private_only = false)
{
/* Build the SQL query. */
$query = sprintf('SELECT vfb_serialized FROM %s WHERE vfb_email=? AND (vfb_owner=?',
/* Execute the query. */
$result = $this->_db->query($query, $values);
- if (!is_a($result, 'PEAR_Error')) {
+ if (!($result instanceof PEAR_Error)) {
$row = $result->fetchRow(DB_GETMODE_ASSOC);
$result->free();
if (is_array($row)) {
return $vfb;
}
}
- return PEAR::raiseError(_("Not found"), Kronolith::ERROR_FB_NOT_FOUND);
+ throw new Kronolith_Exception(_("Not found"), Kronolith::ERROR_FB_NOT_FOUND);
}
/**
* @param Horde_iCalendar_vFreebusy $vfb TODO
* @param boolean $private_only (optional) TODO
*
- * @return boolean True on success
- * PEAR_Error on error or not found
+ * @throws Kronolith_Exception
*/
- function store($email, $vfb, $public = false)
+ public function store($email, $vfb, $public = false)
{
- $owner = (!$public) ? $this->_user : '';
-
/* Build the SQL query. */
$query = sprintf('INSERT INTO %s (vfb_owner, vfb_email, vfb_serialized) VALUES (?, ?, ?)',
$this->_params['table']);
- $values = array($owner, $email, Horde_Serialize::serialize($vfb, Horde_Serialize::BASIC));
+ $values = array($public ? '' : $this->_user, $email, Horde_Serialize::serialize($vfb, Horde_Serialize::BASIC));
/* Log the query at debug level. */
Horde::logMessage(sprintf('SQL insert by %s: query = "%s"',
__FILE__, __LINE__, PEAR_LOG_DEBUG);
/* Execute the query. */
- return $this->_write_db->query($query, $values);
+ $result = $this->_write_db->query($query, $values);
+ if ($result instanceof PEAR_Error) {
+ throw new Kronolith_Exception($result);
+ }
}
}
//TODO: Are there any cases where we can shortcut the postFilter?
$results = array('calendar' => array(),
- 'event' => $this->_postFilter($results, $filter['calendar']));
+ 'event' => Kronolith::getDriver()->filterEventsByCalendar($results, $filter['calendar']));
} else {
$args = array('tagId' => self::$_tagger->ensureTags($tags));
if (!empty($filter['userId'])) {
}
/**
- * Filter events in the $results array to return only those that are
- * in $calendar.
- *
- * @param $results
- * @param $calendar
- * @return unknown_type
- */
- protected function _postFilter($results, $calendar)
- {
- $driver = Kronolith::getDriver();
- return $driver->filterEventsByCalendar($results, $calendar);
- }
-
- /**
* List tags belonging to the current user beginning with $token.
* Used for autocomplete code.
*
}
if ($events === null) {
- $events = Kronolith::listEvents(
- $this,
- new Horde_Date(array('year' => $this->year,
- 'month' => $this->month,
- 'mday' => $this->mday)),
- $GLOBALS['display_calendars']);
- if (is_a($events, 'PEAR_Error')) {
- $this->_events = $events;
- } else {
- $this->_events = array_shift($events);
+ try {
+ $events = Kronolith::listEvents(
+ $this,
+ new Horde_Date(array('year' => $this->year,
+ 'month' => $this->month,
+ 'mday' => $this->mday)),
+ $GLOBALS['display_calendars']);
+ $this->_events = array_shift($events);
+ } catch (Exception $e) {
+ $GLOBALS['notification']->push($e, 'horde.error');
+ $this->_events = array();
}
} else {
$this->_events = $events;
}
- if (is_a($this->_events, 'PEAR_Error')) {
- $GLOBALS['notification']->push($this->_events, 'horde.error');
- $this->_events = array();
- }
if (!is_array($this->_events)) {
$this->_events = array();
}
var $event;
/**
- * @param Kronolith_Event &$event
+ * @param Kronolith_Event $event
*/
- function Kronolith_View_DeleteEvent(&$event)
+ function Kronolith_View_DeleteEvent($event)
{
- $this->event =& $event;
+ $this->event = $event;
}
function getTitle()
{
- if (!$this->event || is_a($this->event, 'PEAR_Error')) {
+ if (!$this->event) {
return _("Not Found");
}
+ if (is_string($this->event)) {
+ return $this->event;
+ }
return sprintf(_("Delete %s"), $this->event->getTitle());
}
function html($active = true)
{
- if (!$this->event || is_a($this->event, 'PEAR_Error')) {
- echo '<h3>' . _("The requested event was not found.") . '</h3>';
- return;
+ if (!$this->event) {
+ echo '<h3>' . _("Event not found") . '</h3>';
+ exit;
+ }
+ if (is_string($this->event)) {
+ echo '<h3>' . $this->event . '</h3>';
+ exit;
}
if ($datetime = Horde_Util::getFormData('datetime')) {
var $event;
/**
- * @param Kronolith_Event &$event
+ * @param Kronolith_Event $event
*/
- function Kronolith_View_EditEvent(&$event)
+ function Kronolith_View_EditEvent($event)
{
- $this->event = &$event;
+ $this->event = $event;
}
function getTitle()
{
- if (!$this->event || is_a($this->event, 'PEAR_Error')) {
+ if (!$this->event) {
return _("Not Found");
}
+ if (is_string($this->event)) {
+ return $this->event;
+ }
return sprintf(_("Edit %s"), $this->event->getTitle());
}
function html($active = true)
{
- $identity = Horde_Prefs_Identity::singleton();
-
- if (!$this->event || is_a($this->event, 'PEAR_Error')) {
- echo '<h3>' . _("The requested event was not found.") . '</h3>';
- return;
+ if (!$this->event) {
+ echo '<h3>' . _("Event not found") . '</h3>';
+ exit;
+ }
+ if (is_string($this->event)) {
+ echo '<h3>' . $this->event . '</h3>';
+ exit;
}
+ $identity = Horde_Prefs_Identity::singleton();
+
if ($this->event->hasPermission(Horde_Perms::EDIT)) {
$calendar_id = $this->event->calendar;
} else {
$calendar_id = Kronolith::getDefaultCalendar(Horde_Perms::EDIT);
}
- if (!$this->event->hasPermission(Horde_Perms::EDIT) &&
- !is_a($share = &$this->event->getShare(), 'PEAR_Error')) {
- $calendar_id .= ':' . $share->get('owner');
+ if (!$this->event->hasPermission(Horde_Perms::EDIT)) {
+ try {
+ $calendar_id .= ':' . $this->event->getShare()->get('owner');
+ } catch (Exception $e) {
+ }
}
$_SESSION['kronolith']['attendees'] = $this->event->attendees;
$_SESSION['kronolith']['resources'] = $this->event->getResources();
var $event;
/**
- * @param Kronolith_Event &$event
+ * @param Kronolith_Event $event
*/
- function Kronolith_View_Event(&$event)
+ function Kronolith_View_Event($event)
{
- $this->event = &$event;
+ $this->event = $event;
}
function getTitle()
{
- if (!$this->event || is_a($this->event, 'PEAR_Error')) {
+ if (!$this->event) {
return _("Not Found");
}
+ if (is_string($this->event)) {
+ return $this->event;
+ }
return $this->event->getTitle();
}
function html($active = true)
{
- global $conf, $prefs;
-
- if (!$this->event || is_a($this->event, 'PEAR_Error')) {
- echo '<h3>' . _("The requested event was not found.") . '</h3>';
- return;
+ if (!$this->event) {
+ echo '<h3>' . _("Event not found") . '</h3>';
+ exit;
}
+ if (is_string($this->event)) {
+ echo '<h3>' . $this->event . '</h3>';
+ exit;
+ }
+
+ global $conf, $prefs;
$createdby = '';
$modifiedby = '';
class Kronolith_View_ExportEvent {
/**
- * @param Kronolith_Event &$event
+ * @param Kronolith_Event $event
*/
- function Kronolith_View_ExportEvent(&$event)
+ function Kronolith_View_ExportEvent($event)
{
- if (!$event || $event instanceof PEAR_Error) {
+ if (!$event) {
echo '<h3>' . _("Event not found") . '</h3>';
exit;
}
+ if (is_string($event)) {
+ echo '<h3>' . $event . '</h3>';
+ exit;
+ }
$iCal = new Horde_iCalendar('2.0');
if ($event->calendarType == 'internal') {
- $share = &$GLOBALS['kronolith_shares']->getShare($event->calendar);
- if (!is_a($share, 'PEAR_Error')) {
+ try {
+ $share = $GLOBALS['kronolith_shares']->getShare($event->calendar);
$iCal->setAttribute(
'X-WR-CALNAME',
Horde_String::convertCharset($share->get('name'),
Horde_Nls::getCharset(),
'utf-8'));
+ } catch (Exception $e) {
}
}
- $vEvent = &$event->toiCalendar($iCal);
+ $vEvent = $event->toiCalendar($iCal);
$iCal->addComponent($vEvent);
$content = $iCal->exportvCalendar();
$this->_currentCalendars = array(true);
}
- $this->_events = Kronolith::listEvents($startDate, $endDate);
- if (is_a($this->_events, 'PEAR_Error')) {
- $GLOBALS['notification']->push($this->_events, 'horde.error');
+ try {
+ $this->_events = Kronolith::listEvents($startDate, $endDate);
+ } catch (Exception $e) {
+ $GLOBALS['notification']->push($e, 'horde.error');
$this->_events = array();
}
if (!is_array($this->_events)) {
$day->mday++;
}
$endDate = new Horde_Date($day);
- $allevents = Kronolith::listEvents($this->startDate, $endDate);
- if (is_a($allevents, 'PEAR_Error')) {
- $GLOBALS['notification']->push($allevents, 'horde.error');
+ try {
+ $allevents = Kronolith::listEvents($this->startDate, $endDate);
+ } catch (Exception $e) {
+ $GLOBALS['notification']->push($e, 'horde.error');
$allevents = array();
}
for ($i = $this->startDay; $i <= $this->endDay; ++$i) {
'month' => 12,
'mday' => 31));
- $this->_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']);
- if (is_a($this->_events, 'PEAR_Error')) {
- $GLOBALS['notification']->push($this->_events, 'horde.error');
+ try {
+ $this->_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']);
+ } catch (Exception $e) {
+ $GLOBALS['notification']->push($e, 'horde.error');
$this->_events = array();
}
if (!is_array($this->_events)) {
// List the events of tomorrow (none, since recurrence has exception)
$a = $kron->listEvents($start, $end);
-if (is_a($a, 'PEAR_Error')) {
- var_dump($a->getMessage());
-} else {
- var_dump($a);
-}
+var_dump($a);
$start = new Horde_Date(259200);
$end = new Horde_Date(345600);
$actionID = Horde_Util::getFormData('actionID', 'edit');
switch ($actionID) {
case 'edit':
- $share = &$shares->getShareById(Horde_Util::getFormData('cid'));
+ $share = $shares->getShareById(Horde_Util::getFormData('cid'));
if (!is_a($share, 'PEAR_Error')) {
- $perm = &$share->getPermission();
+ $perm = $share->getPermission();
} elseif (($category = Horde_Util::getFormData('share')) !== null) {
- $share = &$shares->getShare($category);
- if (!is_a($share, 'PEAR_Error')) {
- $perm = &$share->getPermission();
+ try {
+ $share = $shares->getShare($category);
+ $perm = $share->getPermission();
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
}
}
- if (is_a($share, 'PEAR_Error')) {
- $notification->push($share, 'horde.error');
- } elseif (!Horde_Auth::getAuth() ||
- (isset($share) &&
- !Horde_Auth::isAdmin() &&
- Horde_Auth::getAuth() != $share->get('owner'))) {
+ if (!Horde_Auth::getAuth() ||
+ (isset($share) &&
+ !Horde_Auth::isAdmin() &&
+ Horde_Auth::getAuth() != $share->get('owner'))) {
exit('permission denied');
}
break;
case 'editform':
- $share = &$shares->getShareById(Horde_Util::getFormData('cid'));
+ $share = $shares->getShareById(Horde_Util::getFormData('cid'));
if (is_a($share, 'PEAR_Error')) {
$notification->push(_("Attempt to edit a non-existent share."), 'horde.error');
} else {
Horde_Auth::getAuth() != $share->get('owner'))) {
exit('permission denied');
}
- $perm = &$share->getPermission();
+ $perm = $share->getPermission();
// Process owner and owner permissions.
$old_owner = $share->get('owner');
// 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 {
+ try {
+ $result = $form->execute();
$notification->push(sprintf(_("The calendar \"%s\" has been created."), $vars->get('name')), 'horde.success');
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
}
header('Location: ' . Horde::applicationUrl('resources/', true));
}
$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(), Horde_Perms::DELETE)) {
- $notification->push(_("You are not allowed to delete this resource."), 'horde.error');
+try {
+ $resource = Kronolith::getDriver('Resource')->getResource($vars->get('c'));
+ if (!$resource->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
+ $notification->push(_("You are not allowed to delete this resource."), 'horde.error');
+ header('Location: ' . Horde::applicationUrl('resources/', true));
+ exit;
+ }
+} catch (Exception $e) {
+ $notification->push($e, 'horde.error');
header('Location: ' . Horde::applicationUrl('resources/', true));
exit;
}
// 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) {
+ try {
+ $result = $form->execute();
$notification->push(sprintf(_("The resource \"%s\" has been deleted."), $resource->get('name')), 'horde.success');
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
}
header('Location: ' . Horde::applicationUrl('resources/', true));
}
$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(), Horde_Perms::EDIT)) {
- $notification->push(_("You are not allowed to change this resource."), 'horde.error');
+try {
+ $resource = Kronolith::getDriver('Resource')->getResource($vars->get('c'));
+ if (!$resource->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+ $notification->push(_("You are not allowed to change this resource."), 'horde.error');
+ header('Location: ' . Horde::applicationUrl('resources/', true));
+ exit;
+ }
+} catch (Exception $e) {
+ $notification->push($e, 'horde.error');
header('Location: ' . Horde::applicationUrl('resources/', true));
exit;
}
// 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 {
+ try {
+ $result = $form->execute();
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');
}
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
}
header('Location: ' . Horde::applicationUrl('resources/', true));
// 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 {
+ try {
+ $result = $form->execute();
$notification->push(sprintf(_("The calendar \"%s\" has been created."), $vars->get('name')), 'horde.success');
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
}
header('Location: ' . Horde::applicationUrl('resources/groups/', true));
}
$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/groups/', true));
- exit;
-} elseif (!$resource->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
- $notification->push(_("You are not allowed to delete this resource group."), 'horde.error');
+try {
+ $resource = Kronolith::getDriver('Resource')->getResource($vars->get('c'));
+ if (!$resource->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
+ $notification->push(_("You are not allowed to delete this resource group."), 'horde.error');
+ header('Location: ' . Horde::applicationUrl('resources/groups/', true));
+ exit;
+ }
+} catch (Exception $e) {
+ $notification->push($e, 'horde.error');
header('Location: ' . Horde::applicationUrl('resources/groups/', true));
exit;
}
// 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) {
+ try {
+ $result = $form->execute();
$notification->push(sprintf(_("The resource group \"%s\" has been deleted."), $resource->get('name')), 'horde.success');
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
}
header('Location: ' . Horde::applicationUrl('resources/groups/', true));
}
$vars = Horde_Variables::getDefaultVariables();
-$d = Kronolith::getDriver('Resource');
-$group = $d->getResource($vars->get('c'));
-
-if ($group instanceof PEAR_Error) {
- $notification->push($group, 'horde.error');
- header('Location: ' . Horde::applicationUrl('resources/groups/', true));
- exit;
-} elseif (!$group->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
- $notification->push(_("You are not allowed to change this resource."), 'horde.error');
+try {
+ $group = Kronolith::getDriver('Resource')->getResource($vars->get('c'));
+ if (!$group->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+ $notification->push(_("You are not allowed to change this resource."), 'horde.error');
+ header('Location: ' . Horde::applicationUrl('resources/groups/', true));
+ exit;
+ }
+} catch (Exception $e) {
+ $notification->push($e, 'horde.error');
header('Location: ' . Horde::applicationUrl('resources/groups/', true));
exit;
}
// Execute if the form is valid.
if ($form->validate($vars)) {
$original_name = $group->get('name');
- $result = $form->execute();
- if ($result instanceof PEAR_Error) {
- $notification->push($result, 'horde.error');
- } else {
+ try {
+ $result = $form->execute();
if ($result->get('name') != $original_name) {
$notification->push(sprintf(_("The resource group \"%s\" has been renamed to \"%s\"."), $original_name, $group->get('name')), 'horde.success');
} else {
$notification->push(sprintf(_("The resource group \"%s\" has been saved."), $original_name), 'horde.success');
}
+ } catch (Exception $e) {
+ $notification->push($e, 'horde.error');
}
header('Location: ' . Horde::applicationUrl('resources/groups/', true));
// potentially have an agenda preference set.
$users = array();
foreach (array_keys($calendars) as $calendarId) {
- $calendar = $GLOBALS['shares']->getShare($calendarId);
- if (is_a($calendar, 'PEAR_Error')) {
+ try {
+ $calendar = $GLOBALS['shares']->getShare($calendarId);
+ } catch (Exception $e) {
continue;
}
$users = array_merge($users, $calendar->listUsers(Horde_Perms::READ));
}
// Save event.
- $event = &$kronolith_driver->getEvent();
+ $event = $kronolith_driver->getEvent();
$event->fromiCalendar($components[0]);
- $result = $event->save();
- if (is_a($result, 'PEAR_Error')) {
- $cli->message(' ' . $result->getMessage(), 'cli.error');
+ try {
+ $event->save();
+ } catch (Exception $e) {
+ $cli->message(' ' . $e->getMessage(), 'cli.error');
continue;
}
$count++;