Fix moving events to another calendar.
authorJan Schneider <jan@horde.org>
Sat, 12 Jun 2010 17:00:31 +0000 (19:00 +0200)
committerJan Schneider <jan@horde.org>
Sat, 12 Jun 2010 17:00:31 +0000 (19:00 +0200)
kronolith/edit.php
kronolith/js/kronolith.js
kronolith/lib/Ajax/Application.php

index ae8b436..00e710b 100644 (file)
@@ -146,7 +146,7 @@ if ($exception = Horde_Util::getFormData('del_exception')) {
                           $share->hasPermission($GLOBALS['registry']->getAuth(), Kronolith::PERMS_DELEGATE)))) {
                         $kronolith_driver->open($source);
                         try {
-                            $res = $kronolith_driver->move(Horde_Util::getFormData('eventID'), $target);
+                            $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');
index d81ef15..ccfcfa1 100644 (file)
@@ -4693,7 +4693,8 @@ KronolithCore = {
             return;
         }
 
-        var cal = $F('kronolithEventTarget'),
+        var cal = $F('kronolithEventCalendar'),
+            target = $F('kronolithEventTarget'),
             eventid = $F('kronolithEventId'),
             viewDates = this.viewDates(this.date, this.view),
             start = viewDates[0].dateString(),
@@ -4702,7 +4703,7 @@ KronolithCore = {
         kronolithETagAc.shutdown();
         $('kronolithEventSave').disable();
         $('kronolithEventSaveAsNew').disable();
-        this.startLoading(cal, start + end);
+        this.startLoading(target, start + end);
         this.doAction('saveEvent',
                       $H($('kronolithEventForm').serialize({ hash: true }))
                           .merge({
index 3d1af5a..6e015e8 100644 (file)
@@ -87,7 +87,7 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
      */
     public function saveEvent()
     {
-        $result = $this->_signedResponse($this->_vars->cal);
+        $result = $this->_signedResponse($this->_vars->targetcalendar);
 
         if (!($kronolith_driver = $this->_getDriver($this->_vars->targetcalendar))) {
             return $result;
@@ -110,6 +110,34 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
             }
         }
 
+        if ($this->_vars->cal &&
+            $this->_vars->cal != $this->_vars->targetcalendar) {
+            if (strpos($kronolith_driver->calendar, ':')) {
+                list($target, $user) = explode(':', $kronolith_driver->calendar, 2);
+            } else {
+                $target = $kronolith_driver->calendar;
+                $user = $GLOBALS['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);
+                $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)))) {
+                    $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');
+                return $result;
+            }
+        }
+
         try {
             $event = $kronolith_driver->getEvent($this->_vars->event);
         } catch (Horde_Exception_NotFound $e) {
@@ -835,7 +863,14 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
      */
     protected function _saveEvent($event)
     {
-        $result = $this->_signedResponse($this->_vars->cal ? $this->_vars->cal : ($event->calendarType . '|' . $event->calendar));
+        if ($this->_vars->targetcalendar) {
+            $cal = $this->_vars->targetcalendar;
+        } elseif ($this->_vars->cal) {
+            $cal = $this->_vars->cal;
+        } else {
+            $cal = $event->calendarType . '|' . $event->calendar;
+        }
+        $result = $this->_signedResponse($cal);
         try {
             $event->save();
             $end = new Horde_Date($this->_vars->view_end);