fix all day events for caldav calendars

This commit is contained in:
Mario Vavti 2019-05-21 12:29:00 +02:00
parent c9d64d75f3
commit f96958adf8
2 changed files with 60 additions and 23 deletions

View File

@ -274,9 +274,12 @@ class Cdav extends Controller {
$timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : ''); $timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : '');
$tz = (($timezone) ? $timezone : date_default_timezone_get()); $tz = (($timezone) ? $timezone : date_default_timezone_get());
$allday = $_REQUEST['allday'];
$title = $_REQUEST['title']; $title = $_REQUEST['title'];
$start = datetime_convert($tz, 'UTC', $_REQUEST['dtstart']); $start = datetime_convert($tz, 'UTC', $_REQUEST['dtstart']);
$dtstart = new \DateTime($start); $dtstart = new \DateTime($start);
if($_REQUEST['dtend']) { if($_REQUEST['dtend']) {
$end = datetime_convert($tz, 'UTC', $_REQUEST['dtend']); $end = datetime_convert($tz, 'UTC', $_REQUEST['dtend']);
$dtend = new \DateTime($end); $dtend = new \DateTime($end);
@ -304,8 +307,12 @@ class Cdav extends Controller {
'DTSTART' => $dtstart 'DTSTART' => $dtstart
] ]
]); ]);
if($dtend) { if($dtend) {
$vcalendar->VEVENT->add('DTEND', $dtend); $vcalendar->VEVENT->add('DTEND', $dtend);
if($allday)
$vcalendar->VEVENT->DTEND['VALUE'] = 'DATE';
else
$vcalendar->VEVENT->DTEND['TZID'] = $tz; $vcalendar->VEVENT->DTEND['TZID'] = $tz;
} }
if($description) if($description)
@ -313,6 +320,9 @@ class Cdav extends Controller {
if($location) if($location)
$vcalendar->VEVENT->add('LOCATION', $location); $vcalendar->VEVENT->add('LOCATION', $location);
if($allday)
$vcalendar->VEVENT->DTSTART['VALUE'] = 'DATE';
else
$vcalendar->VEVENT->DTSTART['TZID'] = $tz; $vcalendar->VEVENT->DTSTART['TZID'] = $tz;
$calendarData = $vcalendar->serialize(); $calendarData = $vcalendar->serialize();
@ -354,6 +364,8 @@ class Cdav extends Controller {
$timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : ''); $timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : '');
$tz = (($timezone) ? $timezone : date_default_timezone_get()); $tz = (($timezone) ? $timezone : date_default_timezone_get());
$allday = $_REQUEST['allday'];
$uri = $_REQUEST['uri']; $uri = $_REQUEST['uri'];
$title = $_REQUEST['title']; $title = $_REQUEST['title'];
$start = datetime_convert($tz, 'UTC', $_REQUEST['dtstart']); $start = datetime_convert($tz, 'UTC', $_REQUEST['dtstart']);
@ -371,12 +383,23 @@ class Cdav extends Controller {
if($title) if($title)
$vcalendar->VEVENT->SUMMARY = $title; $vcalendar->VEVENT->SUMMARY = $title;
if($dtstart) if($dtstart) {
$vcalendar->VEVENT->DTSTART = $dtstart; $vcalendar->VEVENT->DTSTART = $dtstart;
if($dtend) if($allday)
$vcalendar->VEVENT->DTSTART['VALUE'] = 'DATE';
else
$vcalendar->VEVENT->DTSTART['TZID'] = $tz;
}
if($dtend) {
$vcalendar->VEVENT->DTEND = $dtend; $vcalendar->VEVENT->DTEND = $dtend;
if($allday)
$vcalendar->VEVENT->DTEND['VALUE'] = 'DATE';
else
$vcalendar->VEVENT->DTEND['TZID'] = $tz;
}
else else
unset($vcalendar->VEVENT->DTEND); unset($vcalendar->VEVENT->DTEND);
if($description) if($description)
$vcalendar->VEVENT->DESCRIPTION = $description; $vcalendar->VEVENT->DESCRIPTION = $description;
if($location) if($location)
@ -415,6 +438,8 @@ class Cdav extends Controller {
$timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : ''); $timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : '');
$tz = (($timezone) ? $timezone : date_default_timezone_get()); $tz = (($timezone) ? $timezone : date_default_timezone_get());
$allday = $_REQUEST['allday'];
$uri = $_REQUEST['uri']; $uri = $_REQUEST['uri'];
$start = datetime_convert($tz, 'UTC', $_REQUEST['dtstart']); $start = datetime_convert($tz, 'UTC', $_REQUEST['dtstart']);
$dtstart = new \DateTime($start); $dtstart = new \DateTime($start);
@ -429,13 +454,20 @@ class Cdav extends Controller {
if($dtstart) { if($dtstart) {
$vcalendar->VEVENT->DTSTART = $dtstart; $vcalendar->VEVENT->DTSTART = $dtstart;
if($allday)
$vcalendar->VEVENT->DTSTART['VALUE'] = 'DATE';
else
$vcalendar->VEVENT->DTSTART['TZID'] = $tz;
} }
if($dtend) { if($dtend) {
$vcalendar->VEVENT->DTEND = $dtend; $vcalendar->VEVENT->DTEND = $dtend;
if($allday)
$vcalendar->VEVENT->DTEND['VALUE'] = 'DATE';
else
$vcalendar->VEVENT->DTEND['TZID'] = $tz;
} }
else { else
unset($vcalendar->VEVENT->DTEND); unset($vcalendar->VEVENT->DTEND);
}
$calendarData = $vcalendar->serialize(); $calendarData = $vcalendar->serialize();
@ -1001,6 +1033,9 @@ class Cdav extends Controller {
$title = ['title', t('Event title') ]; $title = ['title', t('Event title') ];
$dtstart = ['dtstart', t('Start date and time')]; $dtstart = ['dtstart', t('Start date and time')];
$dtend = ['dtend', t('End date and time')]; $dtend = ['dtend', t('End date and time')];
$timezone_select = ['timezone_select' , t('Timezone:'), date_default_timezone_get(), '', get_timezones()];
$allday = ['allday', t('All day event'), '', '', [t('No'), t('Yes')]];
$description = ['description', t('Description')]; $description = ['description', t('Description')];
$location = ['location', t('Location')]; $location = ['location', t('Location')];
@ -1061,7 +1096,8 @@ class Cdav extends Controller {
'$resource' => json_encode($resource), '$resource' => json_encode($resource),
'$categories' => $categories, '$categories' => $categories,
'$timezone_select' => ((feature_enabled(local_channel(),'event_tz_select')) ? ['timezone_select' , t('Timezone:'), date_default_timezone_get(), '', get_timezones()] : []) '$timezone_select' => ((feature_enabled(local_channel(),'event_tz_select')) ? $timezone_select : ''),
'$allday' => $allday
]); ]);
@ -1091,8 +1127,8 @@ class Cdav extends Controller {
$filters['comp-filters'][0]['time-range']['end'] = $end; $filters['comp-filters'][0]['time-range']['end'] = $end;
$uris = $caldavBackend->calendarQuery($id, $filters); $uris = $caldavBackend->calendarQuery($id, $filters);
if($uris) { if($uris) {
$objects = $caldavBackend->getMultipleCalendarObjects($id, $uris); $objects = $caldavBackend->getMultipleCalendarObjects($id, $uris);
foreach($objects as $object) { foreach($objects as $object) {
@ -1121,13 +1157,7 @@ class Cdav extends Controller {
$timezone = $recurrent_timezone; $timezone = $recurrent_timezone;
} }
$allDay = false; $allDay = (((string)$vevent->DTSTART['VALUE'] == 'DATE') ? true : false);
// allDay event rules
if(!strpos($dtstart, 'T') && !strpos($dtend, 'T'))
$allDay = true;
if(strpos($dtstart, 'T000000') && strpos($dtend, 'T000000'))
$allDay = true;
$events[] = [ $events[] = [
'calendar_id' => $id, 'calendar_id' => $id,

View File

@ -17,6 +17,8 @@ var resource = {{$resource}};
var default_view = resource !== null ? 'timeGridDay' : 'dayGridMonth'; var default_view = resource !== null ? 'timeGridDay' : 'dayGridMonth';
var default_date = resource !== null ? new Date(resource.dtstart) : new Date(); var default_date = resource !== null ? new Date(resource.dtstart) : new Date();
var allday;
$(document).ready(function() { $(document).ready(function() {
var calendarEl = document.getElementById('calendar'); var calendarEl = document.getElementById('calendar');
calendar = new FullCalendar.Calendar(calendarEl, { calendar = new FullCalendar.Calendar(calendarEl, {
@ -43,7 +45,6 @@ $(document).ready(function() {
dayNamesShort: aStr['dayNamesShort'], dayNamesShort: aStr['dayNamesShort'],
allDayText: aStr['allday'], allDayText: aStr['allday'],
defaultTimedEventDuration: '01:00:00',
snapDuration: '00:15:00', snapDuration: '00:15:00',
dateClick: function(info) { dateClick: function(info) {
@ -53,8 +54,10 @@ $(document).ready(function() {
new_event = {}; new_event = {};
} }
allday = info.allDay;
var dtend = new Date(info.date.toUTCString()); var dtend = new Date(info.date.toUTCString());
if(info.view.type == 'dayGridMonth') { if(allday) {
dtend.setDate(dtend.getDate() + 1); dtend.setDate(dtend.getDate() + 1);
} }
else{ else{
@ -76,7 +79,7 @@ $(document).ready(function() {
$('#event_submit').val('create_event').html('{{$create}}'); $('#event_submit').val('create_event').html('{{$create}}');
$('#event_delete').hide(); $('#event_delete').hide();
new_event = { id: new_event_id, title : 'New event', start: $('#id_dtstart').val(), end: $('#id_dtend').val(), editable: true, color: '#bbb' }; new_event = { id: new_event_id, title: 'New event', start: $('#id_dtstart').val(), end: $('#id_dtend').val(), allDay: info.allDay, editable: true, color: '#bbb' };
calendar.addEvent(new_event); calendar.addEvent(new_event);
}, },
@ -180,6 +183,7 @@ $(document).ready(function() {
}, },
eventResize: function(info) { eventResize: function(info) {
console.log(info);
var event = info.event._def; var event = info.event._def;
var dtstart = new Date(info.event._instance.range.start); var dtstart = new Date(info.event._instance.range.start);
@ -219,7 +223,8 @@ $(document).ready(function() {
'uri': event.extendedProps.uri, 'uri': event.extendedProps.uri,
'timezone_select': event.extendedProps.timezone, 'timezone_select': event.extendedProps.timezone,
'dtstart': dtstart ? dtstart.toUTCString() : '', 'dtstart': dtstart ? dtstart.toUTCString() : '',
'dtend': dtend ? dtend.toUTCString() : '' 'dtend': dtend ? dtend.toUTCString() : '',
'allday': event.allDay ? 1 : 0
}) })
.fail(function() { .fail(function() {
info.revert(); info.revert();
@ -267,7 +272,8 @@ $(document).ready(function() {
'uri': event.extendedProps.uri, 'uri': event.extendedProps.uri,
'timezone_select': event.extendedProps.timezone, 'timezone_select': event.extendedProps.timezone,
'dtstart': dtstart ? dtstart.toUTCString() : '', 'dtstart': dtstart ? dtstart.toUTCString() : '',
'dtend': dtend ? dtend.toUTCString() : '' 'dtend': dtend ? dtend.toUTCString() : '',
'allday': event.allDay ? 1 : 0
}) })
.fail(function() { .fail(function() {
info.revert(); info.revert();
@ -424,7 +430,7 @@ function on_submit() {
'summary': $('#id_title').val(), 'summary': $('#id_title').val(),
'dtstart': $('#id_dtstart').val(), 'dtstart': $('#id_dtstart').val(),
'dtend': $('#id_dtend').val(), 'dtend': $('#id_dtend').val(),
'adjust': 1, 'adjust': allday ? 0 : 1,
'categories': $('#id_categories').val(), 'categories': $('#id_categories').val(),
'desc': $('#id_description').val(), 'desc': $('#id_description').val(),
'location': $('#id_location').val(), 'location': $('#id_location').val(),
@ -452,7 +458,8 @@ function on_submit() {
'dtstart': $('#id_dtstart').val(), 'dtstart': $('#id_dtstart').val(),
'dtend': $('#id_dtend').val(), 'dtend': $('#id_dtend').val(),
'description': $('#id_description').val(), 'description': $('#id_description').val(),
'location': $('#id_location').val() 'location': $('#id_location').val(),
'allday': allday ? 1 : 0
}) })
.done(function() { .done(function() {
var parts = $('#calendar_select').val().split(':'); var parts = $('#calendar_select').val().split(':');