Skip to content

Commit

Permalink
Globals, wrapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Oct 1, 2015
1 parent 84efab6 commit 8db98a6
Showing 1 changed file with 43 additions and 18 deletions.
61 changes: 43 additions & 18 deletions kronolith/lib/Ajax/Application/Handler.php
Expand Up @@ -190,6 +190,8 @@ public function getEvent()
*/
public function saveEvent()
{
global $injector, $notification, $registry;

$result = $this->_signedResponse($this->vars->targetcalendar);

if (!($kronolith_driver = $this->_getDriver($this->vars->targetcalendar))) {
Expand All @@ -200,13 +202,16 @@ public function saveEvent()
unset($this->vars->event);
}
if (!$this->vars->event) {
$perms = $GLOBALS['injector']->getInstance('Horde_Core_Perms');
$perms = $injector->getInstance('Horde_Core_Perms');
if ($perms->hasAppPermission('max_events') !== true &&
$perms->hasAppPermission('max_events') <= Kronolith::countEvents()) {
Horde::permissionDeniedError(
'kronolith',
'max_events',
sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events'))
sprintf(
_("You are not allowed to create more than %d events."),
$perms->hasAppPermission('max_events')
)
);
return $result;
}
Expand All @@ -216,27 +221,37 @@ public function saveEvent()
$this->vars->cal &&
$this->vars->cal != $this->vars->targetcalendar) {
if (strpos($kronolith_driver->calendar, '\\')) {
list($target, $user) = explode('\\', $kronolith_driver->calendar, 2);
list($target, $user) = explode(
'\\', $kronolith_driver->calendar, 2
);
} else {
$target = $kronolith_driver->calendar;
$user = $GLOBALS['registry']->getAuth();
$user = $registry->getAuth();
}
$kronolith_driver = $this->_getDriver($this->vars->cal);
// Only delete the event from the source calendar if this user has
// permissions to do so.
try {
$sourceShare = Kronolith::getInternalCalendar($kronolith_driver->calendar);
$sourceShare = Kronolith::getInternalCalendar(
$kronolith_driver->calendar
);
$share = Kronolith::getInternalCalendar($target);
if ($sourceShare->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE) &&
(($user == $GLOBALS['registry']->getAuth() &&
$share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) ||
($user != $GLOBALS['registry']->getAuth() &&
$share->hasPermission($GLOBALS['registry']->getAuth(), Kronolith::PERMS_DELEGATE)))) {
if ($sourceShare->hasPermission($registry->getAuth(), Horde_Perms::DELETE) &&
(($user == $registry->getAuth() &&
$share->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) ||
($user != $registry->getAuth() &&
$share->hasPermission($registry->getAuth(), Kronolith::PERMS_DELEGATE)))) {
$kronolith_driver->move($this->vars->event, $target);
$kronolith_driver = $this->_getDriver($this->vars->targetcalendar);
}
} catch (Exception $e) {
$GLOBALS['notification']->push(sprintf(_("There was an error moving the event: %s"), $e->getMessage()), 'horde.error');
$notification->push(
sprintf(
_("There was an error moving the event: %s"),
$e->getMessage()
),
'horde.error'
);
return $result;
}
}
Expand All @@ -248,16 +263,22 @@ public function saveEvent()
// be empty, so this will create a new event.
$event = $kronolith_driver->getEvent($this->vars->event);
} catch (Horde_Exception_NotFound $e) {
$GLOBALS['notification']->push(_("The requested event was not found."), 'horde.error');
$notification->push(
_("The requested event was not found."),
'horde.error'
);
return $result;
} catch (Exception $e) {
$GLOBALS['notification']->push($e);
$notification->push($e);
return $result;
}
}

if (!$event->hasPermission(Horde_Perms::EDIT)) {
$GLOBALS['notification']->push(_("You do not have permission to edit this event."), 'horde.warning');
$notification->push(
_("You do not have permission to edit this event."),
'horde.warning'
);
return $result;
}

Expand Down Expand Up @@ -305,7 +326,9 @@ public function saveEvent()
$newEvent = $kronolith_driver->getEvent();
$newEvent->readForm();
$newEvent->uid = null;
$result = $this->_saveEvent($newEvent, $event, $this->vars, true);
$result = $this->_saveEvent(
$newEvent, $event, $this->vars, true
);
}

}
Expand All @@ -319,7 +342,7 @@ public function saveEvent()
);
$result = $this->_saveEvent($event);
} catch (Exception $e) {
$GLOBALS['notification']->push($e);
$notification->push($e);
return $result;
}
}
Expand All @@ -328,15 +351,17 @@ public function saveEvent()
$type = $event->status == Kronolith::STATUS_CANCELLED
? Kronolith::ITIP_CANCEL
: Kronolith::ITIP_REQUEST;
Kronolith::sendITipNotifications($event, $GLOBALS['notification'], $type);
Kronolith::sendITipNotifications($event, $notification, $type);
}
if (!empty($removed_attendees)) {
foreach ($removed_attendees as $email) {
$to_cancel[$email] = $old_attendees[$email];
}
$cancelEvent = clone $event;
$cancelEvent->attendees = $to_cancel;
Kronolith::sendITipNotifications($cancelEvent, $GLOBALS['notification'], Kronolith::ITIP_CANCEL);
Kronolith::sendITipNotifications(
$cancelEvent, $notification, Kronolith::ITIP_CANCEL
);
}
Kronolith::notifyOfResourceRejection($event);

Expand Down

0 comments on commit 8db98a6

Please sign in to comment.