nextcloud/apps/calendar/ajax/events.php

94 lines
3.1 KiB
PHP
Raw Normal View History

<?php
/**
* Copyright (c) 2011, 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
2011-11-13 01:02:04 +04:00
require_once ('../../../lib/base.php');
//IS THERE A NATIVE SUPPORT IN SABREDAV ???
require_once('when/When.php');
2011-11-13 01:02:04 +04:00
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('calendar');
if(version_compare(PHP_VERSION, '5.3.0', '>=')){
$start = DateTime::createFromFormat('U', $_GET['start']);
$end = DateTime::createFromFormat('U', $_GET['end']);
}else{
$start = new DateTime('@' . $_GET['start']);
$end = new DateTime('@' . $_GET['end']);
}
2012-02-20 14:35:19 +04:00
if($_GET['calendar_id'] == 'shared_rw' || $_GET['calendar_id'] == 'shared_r'){
$calendars = OC_Calendar_Share::allSharedwithuser(OC_USER::getUser(), OC_Calendar_Share::CALENDAR, 1, ($_GET['calendar_id'] == 'shared_rw')?'rw':'r');
2012-02-11 17:02:51 +04:00
$events = array();
foreach($calendars as $calendar){
$calendarevents = OC_Calendar_Object::allInPeriod($calendar['calendarid'], $start, $end);
$events = array_merge($events, $calendarevents);
}
}else{
2012-03-03 18:06:51 +04:00
$calendar_id = $_GET['calendar_id'];
if (is_numeric($calendar_id)) {
$calendar = OC_Calendar_App::getCalendar($calendar_id);
OC_Response::enableCaching(0);
OC_Response::setETagHeader($calendar['ctag']);
$events = OC_Calendar_Object::allInPeriod($calendar_id, $start, $end);
} else {
$events = array();
OC_Hook::emit('OC_Calendar', 'getEvents', array('calendar_id' => $calendar_id, 'events' => &$events));
2012-02-12 13:40:57 +04:00
}
2012-02-11 17:02:51 +04:00
}
$user_timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$return = array();
2011-11-13 01:02:04 +04:00
foreach($events as $event){
$return_event = OC_Calendar_App::prepareForOutput($event);
$dtstart = $vevent->DTSTART;
$start_dt = $dtstart->getDateTime();
$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
$end_dt = $dtend->getDateTime();
2011-11-13 01:02:04 +04:00
if ($dtstart->getDateType() == Sabre_VObject_Element_DateTime::DATE){
$return_event['allDay'] = true;
2011-10-22 00:47:31 +04:00
}else{
$return_event['allDay'] = false;
$start_dt->setTimezone(new DateTimeZone($user_timezone));
$end_dt->setTimezone(new DateTimeZone($user_timezone));
}
2011-11-13 01:02:04 +04:00
if($event['repeating'] == 1){
$duration = (double) $end_dt->format('U') - (double) $start_dt->format('U');
$r = new When();
$r->recur($start_dt)->rrule((string) $vevent->RRULE);
2011-11-13 01:02:04 +04:00
while($result = $r->next()){
if($result < $start){
continue;
}
if($result > $end){
2011-11-13 01:02:04 +04:00
break;
}
if($return_event['allDay'] == true){
$return_event['start'] = $result->format('Y-m-d');
$return_event['end'] = date('Y-m-d', $result->format('U') + --$duration);
2011-11-13 01:02:04 +04:00
}else{
$return_event['start'] = $result->format('Y-m-d H:i:s');
$return_event['end'] = date('Y-m-d H:i:s', $result->format('U') + $duration);
}
$return[] = $return_event;
2011-11-13 01:02:04 +04:00
}
}else{
if($return_event['allDay'] == true){
2011-11-13 01:02:04 +04:00
$return_event['start'] = $start_dt->format('Y-m-d');
$end_dt->modify('-1 sec');
$return_event['end'] = $end_dt->format('Y-m-d');
}else{
$return_event['start'] = $start_dt->format('Y-m-d H:i:s');
$return_event['end'] = $end_dt->format('Y-m-d H:i:s');
}
$return[] = $return_event;
}
}
OC_JSON::encodedPrint($return);
2012-02-20 14:35:19 +04:00
?>