2011-10-01 22:27:30 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2011-10-19 00:25:54 +04:00
|
|
|
* Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
|
2011-10-01 22:27:30 +04:00
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
require_once('../../../lib/base.php');
|
|
|
|
OC_JSON::checkLoggedIn();
|
|
|
|
$data = OC_Calendar_Object::find($_POST["id"]);
|
|
|
|
$calendarid = $data["calendarid"];
|
|
|
|
$cal = $calendarid;
|
2011-10-19 00:25:54 +04:00
|
|
|
$id = $_POST['id'];
|
2011-10-01 22:27:30 +04:00
|
|
|
$calendar = OC_Calendar_Calendar::findCalendar($calendarid);
|
2011-10-19 00:25:54 +04:00
|
|
|
if(OC_User::getUser() != $calendar['userid']){
|
2011-10-01 22:27:30 +04:00
|
|
|
OC_JSON::error();
|
|
|
|
exit;
|
|
|
|
}
|
2011-10-19 00:25:54 +04:00
|
|
|
$allday = $_POST['allDay'];
|
|
|
|
$delta = new DateInterval('P0D');
|
|
|
|
$delta->d = $_POST['dayDelta'];
|
|
|
|
$delta->i = $_POST['minuteDelta'];
|
|
|
|
|
2011-11-10 01:16:24 +04:00
|
|
|
$vcalendar = OC_Calendar_Object::parse($data['calendardata']);
|
2011-10-19 00:25:54 +04:00
|
|
|
$vevent = $vcalendar->VEVENT;
|
|
|
|
|
2011-11-10 01:17:09 +04:00
|
|
|
$last_modified = $vevent->__get('LAST-MODIFIED');
|
|
|
|
if($last_modified && $_POST['lastmodified'] != $last_modified->getDateTime()->format('U')){
|
|
|
|
OC_JSON::error();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2011-10-01 22:27:30 +04:00
|
|
|
$dtstart = $vevent->DTSTART;
|
|
|
|
$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
|
2011-10-19 00:25:54 +04:00
|
|
|
$start_type = $dtstart->getDateType();
|
|
|
|
$end_type = $dtend->getDateType();
|
|
|
|
if ($allday && $start_type != Sabre_VObject_Element_DateTime::DATE){
|
|
|
|
$start_type = $end_type = Sabre_VObject_Element_DateTime::DATE;
|
|
|
|
$dtend->setDateTime($dtend->getDateTime()->modify('+1 day'), $end_type);
|
2011-10-01 22:27:30 +04:00
|
|
|
}
|
2011-10-19 00:25:54 +04:00
|
|
|
if (!$allday && $start_type == Sabre_VObject_Element_DateTime::DATE){
|
|
|
|
$start_type = $end_type = Sabre_VObject_Element_DateTime::LOCALTZ;
|
2011-10-01 22:27:30 +04:00
|
|
|
}
|
2011-10-19 00:25:54 +04:00
|
|
|
$dtstart->setDateTime($dtstart->getDateTime()->add($delta), $start_type);
|
|
|
|
$dtend->setDateTime($dtend->getDateTime()->add($delta), $end_type);
|
|
|
|
unset($vevent->DURATION);
|
|
|
|
|
|
|
|
$now = new DateTime();
|
|
|
|
$last_modified = new Sabre_VObject_Element_DateTime('LAST-MODIFIED');
|
|
|
|
$last_modified->setDateTime($now, Sabre_VObject_Element_DateTime::UTC);
|
|
|
|
$vevent->__set('LAST-MODIFIED', $last_modified);
|
|
|
|
|
|
|
|
$dtstamp = new Sabre_VObject_Element_DateTime('DTSTAMP');
|
|
|
|
$dtstamp->setDateTime($now, Sabre_VObject_Element_DateTime::UTC);
|
|
|
|
$vevent->DTSTAMP = $dtstamp;
|
2011-10-01 22:27:30 +04:00
|
|
|
|
|
|
|
$result = OC_Calendar_Object::edit($id, $vcalendar->serialize());
|
2011-11-10 01:17:09 +04:00
|
|
|
OC_JSON::success(array('lastmodified'=>(int)$now->format('U')));
|