diff --git a/apps/calendar/ajax/editevent.php b/apps/calendar/ajax/editevent.php index a60b0946ad..46feb06849 100644 --- a/apps/calendar/ajax/editevent.php +++ b/apps/calendar/ajax/editevent.php @@ -35,6 +35,13 @@ if($errarr){ exit; } $vcalendar = OC_Calendar_Object::parse($data['calendardata']); + + $last_modified = $vcalendar->VEVENT->__get('LAST-MODIFIED'); + if($last_modified && $_POST['lastmodified'] != $last_modified->getDateTime()->format('U')){ + OC_JSON::error(array('modified'=>true)); + exit; + } + OC_Calendar_Object::updateVCalendarFromRequest($_POST, $vcalendar); $result = OC_Calendar_Object::edit($id, $vcalendar->serialize()); if ($data['calendarid'] != $cal) { diff --git a/apps/calendar/ajax/editeventform.php b/apps/calendar/ajax/editeventform.php index e6dc813660..63c7293407 100644 --- a/apps/calendar/ajax/editeventform.php +++ b/apps/calendar/ajax/editeventform.php @@ -63,9 +63,16 @@ foreach($categories as $category){ } $repeat = isset($vevent->CATEGORY) ? $vevent->CATEGORY->value : ''; $description = isset($vevent->DESCRIPTION) ? $vevent->DESCRIPTION->value : ''; +$last_modified = $vevent->__get('LAST-MODIFIED'); +if ($last_modified){ + $lastmodified = $last_modified->getDateTime()->format('U'); +}else{ + $lastmodified = 0; +} $tmpl = new OC_Template('calendar', 'part.editevent'); $tmpl->assign('id', $id); +$tmpl->assign('lastmodified', $lastmodified); $tmpl->assign('calendar_options', $calendar_options); $tmpl->assign('category_options', $category_options); $tmpl->assign('repeat_options', $repeat_options); diff --git a/apps/calendar/ajax/events.php b/apps/calendar/ajax/events.php index 5ee2ffb627..66aeb1a35b 100644 --- a/apps/calendar/ajax/events.php +++ b/apps/calendar/ajax/events.php @@ -40,9 +40,16 @@ foreach($events as $event) $return_event['end'] = $end_dt->format('Y-m-d H:i:s'); $return_event['allDay'] = false; } - $return_event['id'] = $event['id']; + $return_event['id'] = (int)$event['id']; $return_event['title'] = $event['summary']; $return_event['description'] = isset($vevent->DESCRIPTION)?$vevent->DESCRIPTION->value:''; + $last_modified = $vevent->__get('LAST-MODIFIED'); + if ($last_modified){ + $lastmodified = $last_modified->getDateTime()->format('U'); + }else{ + $lastmodified = 0; + } + $return_event['lastmodified'] = (int)$lastmodified; $return[] = $return_event; } OC_JSON::encodedPrint($return); diff --git a/apps/calendar/ajax/moveevent.php b/apps/calendar/ajax/moveevent.php index 834a454fca..6b315a3921 100644 --- a/apps/calendar/ajax/moveevent.php +++ b/apps/calendar/ajax/moveevent.php @@ -25,6 +25,12 @@ $delta->i = $_POST['minuteDelta']; $vcalendar = OC_Calendar_Object::parse($data['calendardata']); $vevent = $vcalendar->VEVENT; +$last_modified = $vevent->__get('LAST-MODIFIED'); +if($last_modified && $_POST['lastmodified'] != $last_modified->getDateTime()->format('U')){ + OC_JSON::error(); + exit; +} + $dtstart = $vevent->DTSTART; $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); $start_type = $dtstart->getDateType(); @@ -50,4 +56,4 @@ $dtstamp->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); $vevent->DTSTAMP = $dtstamp; $result = OC_Calendar_Object::edit($id, $vcalendar->serialize()); -OC_JSON::success(); +OC_JSON::success(array('lastmodified'=>(int)$now->format('U'))); diff --git a/apps/calendar/ajax/resizeevent.php b/apps/calendar/ajax/resizeevent.php index 639ef91ee7..28a185411e 100644 --- a/apps/calendar/ajax/resizeevent.php +++ b/apps/calendar/ajax/resizeevent.php @@ -25,6 +25,12 @@ $delta->i = $_POST['minuteDelta']; $vcalendar = OC_Calendar_Object::parse($data['calendardata']); $vevent = $vcalendar->VEVENT; +$last_modified = $vevent->__get('LAST-MODIFIED'); +if($last_modified && $_POST['lastmodified'] != $last_modified->getDateTime()->format('U')){ + OC_JSON::error(); + exit; +} + $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); $end_type = $dtend->getDateType(); $dtend->setDateTime($dtend->getDateTime()->add($delta), $end_type); @@ -40,4 +46,4 @@ $dtstamp->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); $vevent->DTSTAMP = $dtstamp; $result = OC_Calendar_Object::edit($id, $vcalendar->serialize()); -OC_JSON::success(); +OC_JSON::success(array('lastmodified'=>$now->format('U'))); diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js index e943bee705..af5ecd8281 100644 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -108,23 +108,27 @@ Calendar={ }, moveEvent:function(event, dayDelta, minuteDelta, allDay, revertFunc){ $('.tipsy').remove(); - $.post(OC.filePath('calendar', 'ajax', 'moveevent.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, allDay: allDay?1:0}, + $.post(OC.filePath('calendar', 'ajax', 'moveevent.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, allDay: allDay?1:0, lastmodified: event.lastmodified}, function(data) { if (data.status == 'success'){ + event.lastmodified = data.lastmodified; console.log("Event moved successfully"); }else{ revertFunc(); + $('#calendar_holder').fullCalendar('refetchEvents'); } }); }, resizeEvent:function(event, dayDelta, minuteDelta, revertFunc){ $('.tipsy').remove(); - $.post(OC.filePath('calendar', 'ajax', 'resizeevent.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta}, + $.post(OC.filePath('calendar', 'ajax', 'resizeevent.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, lastmodified: event.lastmodified}, function(data) { if (data.status == 'success'){ + event.lastmodified = data.lastmodified; console.log("Event resized successfully"); }else{ revertFunc(); + $('#calendar_holder').fullCalendar('refetchEvents'); } }); }, diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php index 9a343a2376..221df2b3af 100644 --- a/apps/calendar/lib/object.php +++ b/apps/calendar/lib/object.php @@ -307,6 +307,7 @@ class OC_Calendar_Object{ */ public static function parse($data){ try { + Sabre_VObject_Reader::$elementMap['LAST-MODIFIED'] = 'Sabre_VObject_Element_DateTime'; $calendar = Sabre_VObject_Reader::read($data); return $calendar; } catch (Exception $e) { diff --git a/apps/calendar/templates/part.editevent.php b/apps/calendar/templates/part.editevent.php index ae969f2dc3..b3acfc4a07 100644 --- a/apps/calendar/templates/part.editevent.php +++ b/apps/calendar/templates/part.editevent.php @@ -1,6 +1,7 @@