show shared calendars

This commit is contained in:
Georg Ehrke 2012-02-11 14:02:51 +01:00
parent 66ac6c232c
commit db23ec5c1c
4 changed files with 36 additions and 26 deletions

View File

@ -1,37 +1,32 @@
<?php <?php
/** /**
* Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de> * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
* This file is licensed under the Affero General Public License version 3 or * This file is licensed under the Affero General Public License version 3 or
* later. * later.
* See the COPYING-README file. * See the COPYING-README file.
*/ */
require_once ('../../../lib/base.php'); require_once ('../../../lib/base.php');
require_once('../../../3rdparty/when/When.php'); require_once('../../../3rdparty/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;
}
OC_JSON::checkLoggedIn(); OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('calendar'); OC_JSON::checkAppEnabled('calendar');
$start = DateTime::createFromFormat('U', $_GET['start']); $start = DateTime::createFromFormat('U', $_GET['start']);
$end = DateTime::createFromFormat('U', $_GET['end']); $end = DateTime::createFromFormat('U', $_GET['end']);
if($_GET['calendar_id'] == 'shared'){
$events = OC_Calendar_Object::allInPeriod($_GET['calendar_id'], $start, $end); $calendars = OC_Calendar_Share::allSharedwithuser(OC_USER::getUser(), OC_Calendar_Share::CALENDAR, 1);
$events = array();
foreach($calendars as $calendar){
$calendarevents = OC_Calendar_Object::allInPeriod($calendar['calendarid'], $start, $end);
$events = array_merge($events, $calendarevents);
}
}else{
$events = OC_Calendar_Object::allInPeriod($_GET['calendar_id'], $start, $end);
}
$user_timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get()); $user_timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$return = array(); $return = array();
foreach($events as $event){ foreach($events as $event){
$object = OC_VObject::parse($event['calendardata']); $object = OC_VObject::parse($event['calendardata']);
$vevent = $object->VEVENT; $vevent = $object->VEVENT;
@ -47,7 +42,6 @@ foreach($events as $event){
$start_dt->setTimezone(new DateTimeZone($user_timezone)); $start_dt->setTimezone(new DateTimeZone($user_timezone));
$end_dt->setTimezone(new DateTimeZone($user_timezone)); $end_dt->setTimezone(new DateTimeZone($user_timezone));
} }
//Repeating Events
if($event['repeating'] == 1){ if($event['repeating'] == 1){
$duration = (double) $end_dt->format('U') - (double) $start_dt->format('U'); $duration = (double) $end_dt->format('U') - (double) $start_dt->format('U');
$r = new When(); $r = new When();
@ -63,7 +57,7 @@ foreach($events as $event){
$return_event['start'] = $result->format('Y-m-d H:i:s'); $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_event['end'] = date('Y-m-d H:i:s', $result->format('U') + $duration);
} }
$return[] = addoutput($event, $vevent, $return_event); $return[] = OC_Calendar_App::prepareForOutput($event, $vevent, $return_event);
} }
}else{ }else{
$return_event = array(); $return_event = array();
@ -77,7 +71,7 @@ foreach($events as $event){
$return_event['end'] = $end_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_event['allDay'] = false;
} }
$return[] = addoutput($event, $vevent, $return_event); $return[] = OC_Calendar_App::prepareForOutput($event, $vevent, $return_event);
} }
} }
OC_JSON::encodedPrint($return); OC_JSON::encodedPrint($return);

View File

@ -19,6 +19,7 @@ $eventSources = array();
foreach($calendars as $calendar){ foreach($calendars as $calendar){
$eventSources[] = OC_Calendar_Calendar::getEventSourceInfo($calendar); $eventSources[] = OC_Calendar_Calendar::getEventSourceInfo($calendar);
} }
$eventSources[] = array('url' => 'ajax/events.php?calendar_id=shared', 'backgroundColor' => '#1D2D44', 'borderColor' => '#888', 'textColor' => 'white', 'editable'=>'false');
//Fix currentview for fullcalendar //Fix currentview for fullcalendar
if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'month') == "oneweekview"){ if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'month') == "oneweekview"){
OC_Preferences::setValue(OC_USER::getUser(), "calendar", "currentview", "agendaWeek"); OC_Preferences::setValue(OC_USER::getUser(), "calendar", "currentview", "agendaWeek");

View File

@ -114,4 +114,19 @@ class OC_Calendar_App{
public static function getWeekofMonth(){ public static function getWeekofMonth(){
return OC_Calendar_Object::getWeekofMonth(self::$l10n); return OC_Calendar_Object::getWeekofMonth(self::$l10n);
} }
public static function prepareForOutput($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;
}
} }

View File

@ -17,21 +17,21 @@ class OC_Calendar_Share{
* @param: (string) $type - use const self::CALENDAR or self::EVENT * @param: (string) $type - use const self::CALENDAR or self::EVENT
* @return: (array) $return - information about calendars * @return: (array) $return - information about calendars
*/ */
public static function allSharedwithuser($userid, $type){ public static function allSharedwithuser($userid, $type, $active=null){
$group_where = 'false'; $group_where = '';
$groups = OC_Group::getUserGroups($userid); $groups = OC_Group::getUserGroups($userid);
$i = 0; $i = 0;
foreach($groups as $group){ foreach($groups as $group){
if($i == 0){ if($i == 0){
$group_where = ''; $group_where = 'OR (';
}else{ }else{
$group_where .= ' OR '; $group_where .= ' OR ';
} }
$group_where .= ' (share = "' . $group . '" and sharetype = "group") '; $group_where .= ' (share = "' . $group . '" and sharetype = "group") ';
$i++; $i++;
} }
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . $type . ' WHERE (share = ? AND sharetype = "user") OR (' . $group_where . ')'); $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*calendar_share_' . $type . ' WHERE ((share = ? AND sharetype = "user") ' . $group_where . ') AND owner <> ?' . ((!is_null($active) && $active)?' AND active = 1':''));
$result = $stmt->execute(array($userid)); $result = $stmt->execute(array($userid, $userid));
$return = array(); $return = array();
while( $row = $result->fetchRow()){ while( $row = $result->fetchRow()){
$return[] = $row; $return[] = $row;