* See the COPYING-README file.
*/
-require_once ('../../../lib/base.php');
-require_once('../../../3rdparty/when/When.php');
+
+require_once('when/When.php');
-function addoutput($event, $vevent, $return_event){
- $return_event['id'] = (int)$event['id'];
- $return_event['title'] = htmlspecialchars($event['summary']);
- $return_event['description'] = isset($vevent->DESCRIPTION)?htmlspecialchars($vevent->DESCRIPTION->value):'';
- $last_modified = $vevent->__get('LAST-MODIFIED');
- if ($last_modified){
- $lastmodified = $last_modified->getDateTime()->format('U');
- }else{
- $lastmodified = 0;
- }
- $return_event['lastmodified'] = (int)$lastmodified;
- return $return_event;
-}
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('calendar');
-OC_JSON::checkLoggedIn();
-OC_JSON::checkAppEnabled('calendar');
+$start = (version_compare(PHP_VERSION, '5.3.0', '>='))?DateTime::createFromFormat('U', $_GET['start']):new DateTime('@' . $_GET['start']);
+$end = (version_compare(PHP_VERSION, '5.3.0', '>='))?DateTime::createFromFormat('U', $_GET['end']):new DateTime('@' . $_GET['end']);
-$start = DateTime::createFromFormat('U', $_GET['start']);
-$end = DateTime::createFromFormat('U', $_GET['end']);
+$events = OC_Calendar_App::getrequestedEvents($_GET['calendar_id'], $start, $end);
-$events = OC_Calendar_Object::allInPeriod($_GET['calendar_id'], $start, $end);
-$user_timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
-$return = array();
+$output = array();
foreach($events as $event){
- $object = OC_VObject::parse($event['calendardata']);
- $vevent = $object->VEVENT;
- $dtstart = $vevent->DTSTART;
- $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
- $return_event = array();
- $start_dt = $dtstart->getDateTime();
- $end_dt = $dtend->getDateTime();
- if ($dtstart->getDateType() == Sabre_VObject_Element_DateTime::DATE){
- $return_event['allDay'] = true;
- }else{
- $return_event['allDay'] = false;
- $start_dt->setTimezone(new DateTimeZone($user_timezone));
- $end_dt->setTimezone(new DateTimeZone($user_timezone));
- }
-
- // Handle exceptions to recurring events
- $exceptionDateObjects = $vevent->select('EXDATE');
- $exceptionDateMap = Array();
- foreach ($exceptionDateObjects as $exceptionObject) {
- foreach($exceptionObject->getDateTimes() as $datetime) {
- $ts = $datetime->getTimestamp();
- $exceptionDateMap[idate('Y',$ts)][idate('m', $ts)][idate('d', $ts)] = true;
- }
- }
-
- //Repeating Events
- if($event['repeating'] == 1){
- $duration = (double) $end_dt->format('U') - (double) $start_dt->format('U');
- $r = new When();
- $r->recur((string) $start_dt->format('Ymd\THis'))->rrule((string) $vevent->RRULE);
- while($result = $r->next()){
- if($result->format('U') > $_GET['end']){
- break;
- }
-
- // Check for exceptions to recurring events
- $ts = $result->getTimestamp();
- if (isset($exceptionDateMap[idate('Y',$ts)][idate('m', $ts)][idate('d', $ts)])) {
- continue;
- }
- unset($ts);
-
- if($return_event['allDay'] == true){
- $return_event['start'] = $result->format('Y-m-d');
- $return_event['end'] = date('Y-m-d', $result->format('U') + --$duration);
- }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[] = addoutput($event, $vevent, $return_event);
- }
- }else{
- $return_event = array();
- if ($dtstart->getDateType() == Sabre_VObject_Element_DateTime::DATE){
- $return_event['allDay'] = true;
- $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_event['allDay'] = false;
- }
- $return[] = addoutput($event, $vevent, $return_event);
- }
+ $output[] = OC_Calendar_App::generateEventOutput($event, $start, $end);
}
-OC_JSON::encodedPrint($return);
-?>
+OCP\JSON::encodedPrint($output);
- ?>
public static function getWeekofMonth(){
return OC_Calendar_Object::getWeekofMonth(self::$l10n);
}
-
+
+ /*
+ * @brief checks the access for a calendar / an event
+ * @param (int) $id - id of the calendar / event
+ * @param (string) $type - type of the id (calendar/event)
+ * @return (string) $access - level of access
+ */
+ public static function getaccess($id, $type){
+ if($type == self::CALENDAR){
+ $calendar = self::getCalendar($id, false, false);
+ if($calendar['userid'] == OCP\USER::getUser()){
+ return 'owner';
+ }
+ $isshared = OC_Calendar_Share::check_access(OCP\USER::getUser(), $id, OC_Calendar_Share::CALENDAR);
+ if($isshared){
+ $writeaccess = OC_Calendar_Share::is_editing_allowed(OCP\USER::getUser(), $id, OC_Calendar_Share::CALENDAR);
+ if($writeaccess){
+ return 'rw';
+ }else{
+ return 'r';
+ }
+ }else{
+ return false;
+ }
+ }elseif($type == self::EVENT){
+ if(OC_Calendar_Object::getowner($id) == OCP\USER::getUser()){
+ return 'owner';
+ }
+ $isshared = OC_Calendar_Share::check_access(OCP\USER::getUser(), $id, OC_Calendar_Share::EVENT);
+ if($isshared){
+ $writeaccess = OC_Calendar_Share::is_editing_allowed(OCP\USER::getUser(), $id, OC_Calendar_Share::EVENT);
+ if($writeaccess){
+ return 'rw';
+ }else{
+ return 'r';
+ }
+ }else{
+ return false;
+ }
+ }
+ }
+
+ /*
+ * @brief analyses the parameter for calendar parameter and returns the objects
+ * @param (string) $calendarid - calendarid
+ * @param (int) $start - unixtimestamp of start
+ * @param (int) $end - unixtimestamp of end
+ * @return (array) $events
+ */
+ public static function getrequestedEvents($calendarid, $start, $end){
+ $events = array();
+ if($calendarid == 'shared_rw' || $_GET['calendar_id'] == 'shared_r'){
+ $calendars = OC_Calendar_Share::allSharedwithuser(OCP\USER::getUser(), OC_Calendar_Share::CALENDAR, 1, ($_GET['calendar_id'] == 'shared_rw')?'rw':'r');
+ foreach($calendars as $calendar){
+ $calendarevents = OC_Calendar_Object::allInPeriod($calendar['calendarid'], $start, $end);
+ $events = array_merge($events, $calendarevents);
+ }
+ $singleevents = OC_Calendar_Share::allSharedwithuser(OCP\USER::getUser(), OC_Calendar_Share::EVENT, 1, ($_GET['calendar_id'] == 'shared_rw')?'rw':'r');
+ foreach($singleevents as $singleevent){
+ $event = OC_Calendar_Object::find($singleevent['eventid']);
+ $events[] = $event;
+ }
+ }else{
+ $calendar_id = $_GET['calendar_id'];
+ if (is_numeric($calendar_id)) {
+ $calendar = self::getCalendar($calendar_id);
+ OCP\Response::enableCaching(0);
+ OCP\Response::setETagHeader($calendar['ctag']);
+ $events = OC_Calendar_Object::allInPeriod($calendar_id, $start, $end);
+ } else {
+ OC_Hook::emit('OC_Calendar', 'getEvents', array('calendar_id' => $calendar_id, 'events' => &$events));
+ }
+ }
+ return $events;
+ }
+
+ /*
+ * @brief generates the output for an event which will be readable for our js
+ * @param (mixed) $event - event object / array
+ * @param (int) $start - unixtimestamp of start
+ * @param (int) $end - unixtimestamp of end
+ * @return (array) $output - readable output
+ */
+ public static function generateEventOutput($event, $start, $end){
+ $output = array();
+
+ if(isset($event['calendardata'])){
+ $object = OC_VObject::parse($event['calendardata']);
+ $vevent = $object->VEVENT;
+ }else{
+ $vevent = $event['vevent'];
+ }
+
+ $last_modified = @$vevent->__get('LAST-MODIFIED');
+ $lastmodified = ($last_modified)?$last_modified->getDateTime()->format('U'):0;
+
+ $output = array('id'=>(int)$event['id'],
+ 'title' => htmlspecialchars(($event['summary']!=NULL || $event['summary'] != '')?$event['summary']: self::$l10n->t('unnamed')),
+ 'description' => isset($vevent->DESCRIPTION)?htmlspecialchars($vevent->DESCRIPTION->value):'',
+ 'lastmodified'=>$lastmodified);
+
+ $dtstart = $vevent->DTSTART;
+ $start_dt = $dtstart->getDateTime();
+ $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
+ $end_dt = $dtend->getDateTime();
+
+ if ($dtstart->getDateType() == Sabre_VObject_Element_DateTime::DATE){
+ $output['allDay'] = true;
+ }else{
+ $output['allDay'] = false;
+ $start_dt->setTimezone(new DateTimeZone(self::$tz));
+ $end_dt->setTimezone(new DateTimeZone(self::$tz));
+ }
++
++ // Handle exceptions to recurring events
++ $exceptionDateObjects = $vevent->select('EXDATE');
++ $exceptionDateMap = Array();
++ foreach ($exceptionDateObjects as $exceptionObject) {
++ foreach($exceptionObject->getDateTimes() as $datetime) {
++ $ts = $datetime->getTimestamp();
++ $exceptionDateMap[idate('Y',$ts)][idate('m', $ts)][idate('d', $ts)] = true;
++ }
++ }
++
+ 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);
+ /*$r = new iCal_Repeat_Generator(array('RECUR' => $start_dt,
+ * 'RRULE' => (string)$vevent->RRULE
+ * 'RDATE' => (string)$vevent->RDATE
+ * 'EXRULE' => (string)$vevent->EXRULE
+ * 'EXDATE' => (string)$vevent->EXDATE));*/
+ while($result = $r->next()){
+ if($result < $start){
+ continue;
+ }
+ if($result > $end){
+ break;
+ }
++ // Check for exceptions to recurring events
++ $ts = $result->getTimestamp();
++ if (isset($exceptionDateMap[idate('Y',$ts)][idate('m', $ts)][idate('d', $ts)])) {
++ continue;
++ }
++ unset($ts);
++
+ if($output['allDay'] == true){
+ $output['start'] = $result->format('Y-m-d');
+ $output['end'] = date('Y-m-d', $result->format('U') + --$duration);
+ }else{
+ $output['start'] = $result->format('Y-m-d H:i:s');
+ $output['end'] = date('Y-m-d H:i:s', $result->format('U') + $duration);
+ }
+ }
+ }else{
+ if($output['allDay'] == true){
+ $output['start'] = $start_dt->format('Y-m-d');
+ $end_dt->modify('-1 sec');
+ $output['end'] = $end_dt->format('Y-m-d');
+ }else{
+ $output['start'] = $start_dt->format('Y-m-d H:i:s');
+ $output['end'] = $end_dt->format('Y-m-d H:i:s');
+ }
+ }
+ return $output;
+ }
}