This commit is contained in:
Bart Visscher 2011-10-18 22:25:54 +02:00
Родитель bb5ccc5731
Коммит a8bca282df
2 изменённых файлов: 38 добавлений и 106 удалений

Просмотреть файл

@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de>
* Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
@ -11,93 +11,43 @@ OC_JSON::checkLoggedIn();
$data = OC_Calendar_Object::find($_POST["id"]);
$calendarid = $data["calendarid"];
$cal = $calendarid;
$id = $_POST["id"];
$id = $_POST['id'];
$calendar = OC_Calendar_Calendar::findCalendar($calendarid);
if(OC_User::getUser() != $calendar["userid"]){
if(OC_User::getUser() != $calendar['userid']){
OC_JSON::error();
exit;
}
$newdate = $_POST["newdate"];
$caldata = array();
//modified part of editeventform.php
$object = Sabre_VObject_Reader::read($data['calendardata']);
$vevent = $object->VEVENT;
$allday = $_POST['allDay'];
$delta = new DateInterval('P0D');
$delta->d = $_POST['dayDelta'];
$delta->i = $_POST['minuteDelta'];
$vcalendar = Sabre_VObject_Reader::read($data['calendardata']);
$vevent = $vcalendar->VEVENT;
$dtstart = $vevent->DTSTART;
$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
switch($dtstart->getDateType()) {
case Sabre_VObject_Element_DateTime::LOCALTZ:
case Sabre_VObject_Element_DateTime::LOCAL:
$startdate = $dtstart->getDateTime()->format('d-m-Y');
$starttime = $dtstart->getDateTime()->format('H:i');
$enddate = $dtend->getDateTime()->format('d-m-Y');
$endtime = $dtend->getDateTime()->format('H:i');
$allday = false;
break;
case Sabre_VObject_Element_DateTime::DATE:
$startdate = $dtstart->getDateTime()->format('d-m-Y');
$starttime = '00:00';
$dtend->getDateTime()->modify('-1 day');
$enddate = $dtend->getDateTime()->format('d-m-Y');
$endtime = '23:59';
$allday = true;
break;
$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);
}
$caldata["title"] = isset($vevent->SUMMARY) ? $vevent->SUMMARY->value : '';
$caldata["location"] = isset($vevent->LOCATION) ? $vevent->LOCATION->value : '';
$caldata["categories"] = array();
if (isset($vevent->CATEGORIES)){
$caldata["categories"] = explode(',', $vevent->CATEGORIES->value);
$caldata["categories"] = array_map('trim', $categories);
if (!$allday && $start_type == Sabre_VObject_Element_DateTime::DATE){
$start_type = $end_type = Sabre_VObject_Element_DateTime::LOCALTZ;
}
foreach($caldata["categories"] as $category){
if (!in_array($category, $category_options)){
array_unshift($category_options, $category);
}
}
$caldata["repeat"] = isset($vevent->CATEGORY) ? $vevent->CATEGORY->value : '';
$caldata["description"] = isset($vevent->DESCRIPTION) ? $vevent->DESCRIPTION->value : '';
//end part of editeventform.php
$startdatearray = explode("-", $startdate);
$starttimearray = explode(":", $starttime);
$startunix = mktime($starttimearray[0], $starttimearray[1], 0, $startdatearray[1], $startdatearray[0], $startdatearray[2]);
$enddatearray = explode("-", $enddate);
$endtimearray = explode(":", $endtime);
$endunix = mktime($endtimearray[0], $endtimearray[1], 0, $enddatearray[1], $enddatearray[0], $enddatearray[2]);
$difference = $endunix - $startunix;
if(strlen($newdate) > 10){
$newdatestringarray = explode("-", $newdate);
if($newdatestringarray[1] == "allday"){
$allday = true;
$newdatestringarray[1] = "00:00";
}else{
if($allday == true){
$difference = 3600;
}
$allday = false;
}
}else{
$newdatestringarray = array();
$newdatestringarray[0] = $newdate;
$newdatestringarray[1] = $starttime;
}
$newdatearray = explode(".", $newdatestringarray[0]);
$newtimearray = explode(":", $newdatestringarray[1]);
$newstartunix = mktime($newtimearray[0], $newtimearray[1], 0, $newdatearray[1], $newdatearray[0], $newdatearray[2]);
$newendunix = $newstartunix + $difference;
if($allday == true){
$caldata["allday"] = true;
}else{
unset($caldata["allday"]);
}
$caldata["from"] = date("d-m-Y", $newstartunix);
$caldata["fromtime"] = date("H:i", $newstartunix);
$caldata["to"] = date("d-m-Y", $newendunix);
$caldata["totime"] = date("H:i", $newendunix);
//modified part of editevent.php
$vcalendar = Sabre_VObject_Reader::read($data["calendardata"]);
OC_Calendar_Object::updateVCalendarFromRequest($caldata, $vcalendar);
$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;
$result = OC_Calendar_Object::edit($id, $vcalendar->serialize());
OC_JSON::success();
//end part of editevent.php
?>

Просмотреть файл

@ -191,10 +191,14 @@ Calendar={
}
},"json");
},
moveevent:function(eventid, newstartdate){
$.post(OC.filePath('calendar', 'ajax', 'moveevent.php'), { id: eventid, newdate: newstartdate},
moveEvent:function(event, dayDelta, minuteDelta, allDay, revertFunc){
$.post(OC.filePath('calendar', 'ajax', 'moveevent.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, allDay: allDay?1:0},
function(data) {
console.log("Event moved successfully");
if (data.status == 'success'){
console.log("Event moved successfully");
}else{
revertFunc();
}
});
},
showadvancedoptions:function(){
@ -227,9 +231,6 @@ Calendar={
+ '<span class="summary">' + event.title + '</span>'
+ '<span class="description">' + event.description + '</span>';
},
addDateInfo:function(selector, date){
$(selector).data('date_info', date);
},
lockTime:function(){
if($('#allday_checkbox').is(':checked')) {
$("#fromtime").attr('disabled', true)
@ -384,26 +385,6 @@ Calendar={
$(button).closest('tr').prev().show().next().remove();
},
},
OneWeek:{
createEventLabel:function(event){
var time = '';
if (!event['allday']){
time = '<strong>' + Calendar.UI.formatTime(event['startdate']) + ' - ' + Calendar.UI.formatTime(event['enddate']) + '</strong> ';
}
return $(document.createElement('p'))
.html(time + event['description'])
},
},
OneMonth:{
createEventLabel:function(event){
var time = '';
if (!event['allday']){
time = '<strong>' + Calendar.UI.formatTime(event['startdate']) + '</strong> ';
}
return $(document.createElement('p'))
.html(time + event['description'])
},
},
List:{
removeEvents:function(){
this.eventContainer = $('#listview #events').empty();
@ -494,6 +475,7 @@ $(document).ready(function(){
},
dayClick: Calendar.UI.newEvent,
eventClick: Calendar.UI.editEvent,
eventDrop: Calendar.UI.moveEvent,
eventMouseover: Calendar.UI.createEventPopup,
eventMouseout: Calendar.UI.hideEventPopup,
eventSources: eventSources