diff options
-rw-r--r-- | apps/calendar/ajax/editeventform.php | 7 | ||||
-rw-r--r-- | apps/calendar/ajax/getcal.php | 60 | ||||
-rw-r--r-- | apps/calendar/lib/object.php | 25 | ||||
-rw-r--r-- | apps/calendar/templates/part.getcal.php | 61 |
4 files changed, 88 insertions, 65 deletions
diff --git a/apps/calendar/ajax/editeventform.php b/apps/calendar/ajax/editeventform.php index 66b0b23568a..e2d32d03d3d 100644 --- a/apps/calendar/ajax/editeventform.php +++ b/apps/calendar/ajax/editeventform.php @@ -28,7 +28,7 @@ if($calendar['userid'] != OC_User::getUser()){ $object = Sabre_VObject_Reader::read($data['calendardata']); $vevent = $object->VEVENT; $dtstart = $vevent->DTSTART; -$dtend = $vevent->DTEND; +$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); switch($dtstart->getDateType()) { case Sabre_VObject_Element_DateTime::LOCALTZ: case Sabre_VObject_Element_DateTime::LOCAL: @@ -55,6 +55,11 @@ if (isset($vevent->CATEGORIES)){ $categories = explode(',', $vevent->CATEGORIES->value); $categories = array_map('trim', $categories); } +foreach($categories as $category){ + if (!in_array($category, $category_options)){ + array_unshift($category_options, $category); + } +} $repeat = isset($vevent->CATEGORY) ? $vevent->CATEGORY->value : ''; $description = isset($vevent->DESCRIPTION) ? $vevent->DESCRIPTION->value : ''; diff --git a/apps/calendar/ajax/getcal.php b/apps/calendar/ajax/getcal.php index 9794a83ce49..7fa4f87cd31 100644 --- a/apps/calendar/ajax/getcal.php +++ b/apps/calendar/ajax/getcal.php @@ -10,6 +10,60 @@ require_once ("../../../lib/base.php"); if(!OC_USER::isLoggedIn()) { die("<script type=\"text/javascript\">document.location = oc_webroot;</script>"); } -$output = new OC_TEMPLATE("calendar", "part.getcal"); -$output -> printpage(); -?> + +$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1); +$events = array(); +$return = array('calendars'=>array()); +foreach($calendars as $calendar) { + $tmp = OC_Calendar_Object::all($calendar['id']); + $events = array_merge($events, $tmp); + $return['calendars'][$calendar['id']] = array( + 'displayname' => $calendar['displayname'], + 'color' => $calendar['calendarcolor'] + ); +} + +$select_year = $_GET["year"]; +$user_timezone = OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone", "Europe/London"); +foreach($events as $event) +{ + if ($select_year != substr($event['startdate'], 0, 4)) + continue; + $object = Sabre_VObject_Reader::read($event['calendardata']); + $vevent = $object->VEVENT; + $dtstart = $vevent->DTSTART; + $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); + $start_dt = $dtstart->getDateTime(); + $start_dt->setTimezone(new DateTimeZone($user_timezone)); + $end_dt = $dtend->getDateTime(); + $end_dt->setTimezone(new DateTimeZone($user_timezone)); + $year = $start_dt->format('Y'); + $month = $start_dt->format('n') - 1; // return is 0 based + $day = $start_dt->format('j'); + $hour = $start_dt->format('G'); + if ($dtstart->getDateType() == Sabre_VObject_Element_DateTime::DATE) { + $hour = 'allday'; + } + + $return_event = array(); + foreach(array('id', 'calendarid', 'objecttype', 'repeating') as $prop) + { + $return_event[$prop] = $event[$prop]; + } + $return_event['startdate'] = explode('|', $start_dt->format('Y|m|d|H|i')); + $return_event['enddate'] = explode('|', $end_dt->format('Y|m|d|H|i')); + $return_event['description'] = $event['summary']; + if ($hour == 'allday') + { + $return_event['allday'] = true; + } + if (isset($return[$year][$month][$day][$hour])) + { + $return[$year][$month][$day][$hour][] = $return_event; + } + else + { + $return[$year][$month][$day][$hour] = array(1 => $return_event); + } +} +OC_JSON::encodedPrint($return); diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php index 0c7649776d5..0c3e497d4f2 100644 --- a/apps/calendar/lib/object.php +++ b/apps/calendar/lib/object.php @@ -286,6 +286,30 @@ class OC_Calendar_Object{ } } + public static function getDTEndFromVEvent($vevent) + { + if ($vevent->DTEND) { + $dtend = $vevent->DTEND; + }else{ + $dtend = clone $vevent->DTSTART; + if ($vevent->DURATION){ + $duration = strval($vevent->DURATION); + $invert = 0; + if ($duration[0] == '-'){ + $duration = substr($duration, 1); + $invert = 1; + } + if ($duration[0] == '+'){ + $duration = substr($duration, 1); + } + $interval = new DateInterval($duration); + $interval->invert = $invert; + $dtend->getDateTime()->add($interval); + } + } + return $dtend; + } + public static function getCategoryOptions($l10n) { return array( @@ -482,6 +506,7 @@ class OC_Calendar_Object{ } $vevent->DTSTART = $dtstart; $vevent->DTEND = $dtend; + unset($vevent->DURATION); if($location != ""){ $vevent->LOCATION = $location; diff --git a/apps/calendar/templates/part.getcal.php b/apps/calendar/templates/part.getcal.php deleted file mode 100644 index af29a3e369c..00000000000 --- a/apps/calendar/templates/part.getcal.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php -/** - * 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. - */ - -$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1); -$events = array(); -$return = array('calendars'=>array()); -foreach($calendars as $calendar) { - $tmp = OC_Calendar_Object::all($calendar['id']); - $events = array_merge($events, $tmp); - $return['calendars'][$calendar['id']] = array( - 'displayname' => $calendar['displayname'], - 'color' => $calendar['calendarcolor'] - ); -} -$select_year = $_GET["year"]; -$user_timezone = OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone", "Europe/London"); -foreach($events as $event) -{ - if ($select_year != substr($event['startdate'], 0, 4)) - continue; - $start_dt = new DateTime($event['startdate'], new DateTimeZone('UTC')); - $start_dt->setTimezone(new DateTimeZone($user_timezone)); - $end_dt = new DateTime($event['enddate'], new DateTimeZone('UTC')); - $end_dt->setTimezone(new DateTimeZone($user_timezone)); - $year = $start_dt->format('Y'); - $month = $start_dt->format('n') - 1; // return is 0 based - $day = $start_dt->format('j'); - $hour = $start_dt->format('G'); - - // hack - if (strstr($event['calendardata'], 'DTSTART;VALUE=DATE:')) { - $hour = 'allday'; - } - $return_event = array(); - foreach(array('id', 'calendarid', 'objecttype', 'repeating') as $prop) - { - $return_event[$prop] = $event[$prop]; - } - $return_event['startdate'] = explode('|', $start_dt->format('Y|m|d|H|i')); - $return_event['enddate'] = explode('|', $end_dt->format('Y|m|d|H|i')); - $return_event['description'] = $event['summary']; - if ($hour == 'allday') - { - $return_event['allday'] = true; - } - if (isset($return[$year][$month][$day][$hour])) - { - $return[$year][$month][$day][$hour][] = $return_event; - } - else - { - $return[$year][$month][$day][$hour] = array(1 => $return_event); - } -} -OC_JSON::encodedPrint($return); -?> |