diff --git a/apps/calendar/ajax/editevent.php b/apps/calendar/ajax/editevent.php index a60b0946ad2fb97fc0b5b6f60e00ad892ce21926..46feb068499e0e96897cc95005dc75f1e01bf5e5 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 e6dc8136601ff0133c6157b38f44a07a84c9668e..63c729340791e1ec6ea733a512ef8b57a7ad8502 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 5ee2ffb6276e3a4711d7b7bf6a110b809ae65ced..66aeb1a35ba8ecfd598150f47d46f82b9679a42f 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 834a454fca2a6028e7081b435c70f9922dd81d25..6b315a3921345e509c9b4e54a0827e2fc58f8e40 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 639ef91ee7cd42e16f06f031a54d96fb52a3580b..28a185411e0b7711c4a1a6381fde5e0f41dcd5e2 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 e943bee705762c4378cc1af6728e18b5d976808e..af5ecd8281680671b63275c8c12bebdc71b07544 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 9a343a23764094ebd52302edd474beaefa0dcd45..221df2b3af016365195603950fcaaf3447b711d1 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 ae969f2dc3b6d8658a659fa33eb298a10ba3bd63..b3acfc4a072220167d44466e2b75424398a3a865 100644 --- a/apps/calendar/templates/part.editevent.php +++ b/apps/calendar/templates/part.editevent.php @@ -1,6 +1,7 @@ <div id="event" title="<?php echo $l->t("Edit an event");?>"> <form id="event_form"> <input type="hidden" name="id" value="<?php echo $_['id'] ?>"> + <input type="hidden" name="lastmodified" value="<?php echo $_['lastmodified'] ?>"> <?php echo $this->inc("part.eventform"); ?> <div style="width: 100%;text-align: center;color: #FF1D1D;" id="errorbox"></div> <span id="actions">