mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 20:29:29 +00:00
Update der Caldav Schnittstelle
This commit is contained in:
+13
-10
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__).'/../include/wochenplan.class.php');
|
||||
require_once(dirname(__FILE__).'/../include/functions.inc.php');
|
||||
require_once(dirname(__FILE__).'/../include/mitarbeiter.class.php');
|
||||
/**
|
||||
* CalDAV backend
|
||||
*/
|
||||
@@ -43,7 +45,8 @@ class MySabre_CalDAV_Backend extends Sabre_CalDAV_Backend_Abstract
|
||||
public function getCalendarsForUser($principalUri)
|
||||
{
|
||||
//error_log("Caldav_Backend.php/getCalendarsForUser($principalUri)");
|
||||
$user = $this->getUser();
|
||||
//$user = $this->getUser();
|
||||
$user = mb_substr($principalUri,11);
|
||||
$calendars = array();
|
||||
$calendar = array(
|
||||
'id' => $user,
|
||||
@@ -115,7 +118,6 @@ class MySabre_CalDAV_Backend extends Sabre_CalDAV_Backend_Abstract
|
||||
*/
|
||||
public function updateCalendar($calendarId, array $mutations)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -130,8 +132,10 @@ class MySabre_CalDAV_Backend extends Sabre_CalDAV_Backend_Abstract
|
||||
throw new Sabre_DAV_Exception('Not Implemented');
|
||||
}
|
||||
|
||||
|
||||
public function getCalendarData($user, $objectUri=null)
|
||||
{
|
||||
$starttime = microtime(true);
|
||||
$bn = new benutzer();
|
||||
if(!$bn->load($user))
|
||||
die('User invalid');
|
||||
@@ -169,8 +173,7 @@ class MySabre_CalDAV_Backend extends Sabre_CalDAV_Backend_Abstract
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO Datum eventuell anpassen derzeit nur aktuell +/- 6 Monate
|
||||
$begin = mktime(0,0,0,date('m')-6,date('d'),date('Y'));
|
||||
$begin = mktime(0,0,0,date('m'),date('d')-14,date('Y'));
|
||||
$ende = mktime(0,0,0,date('m')+6,date('d'),date('Y'));
|
||||
}
|
||||
$db_stpl_table = 'stundenplan';
|
||||
@@ -198,11 +201,9 @@ class MySabre_CalDAV_Backend extends Sabre_CalDAV_Backend_Abstract
|
||||
{
|
||||
foreach($val as $row)
|
||||
{
|
||||
// error_log("search dtstart:".$dtstart." unr:".$unr);
|
||||
// error_log("row dtstart:".$row['dtstart']." unr:".$row['unr'][0]);
|
||||
//einzelnen Eintrag holen
|
||||
if($row['dtstart']==$dtstart && $row['unr'][0]==$unr)
|
||||
{
|
||||
error_log("found!");
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
@@ -210,7 +211,8 @@ class MySabre_CalDAV_Backend extends Sabre_CalDAV_Backend_Abstract
|
||||
else
|
||||
$data=array_merge($data, $val);
|
||||
}
|
||||
|
||||
$endtime = microtime(true);
|
||||
//error_log("getCalendarData time:".($endtime-$starttime));
|
||||
//$data.="\nEND:VCALENDAR";
|
||||
return $data;
|
||||
}
|
||||
@@ -265,7 +267,7 @@ END:VTIMEZONE\n".$event."\nEND:VCALENDAR";
|
||||
$user = $calendarId;
|
||||
$data = $this->getCalendarData($user);
|
||||
|
||||
//error_log("Caldav_Backend.php/getCalendarObjects($calendarId) data:".print_r($data,true));
|
||||
//error_log("Caldav_Backend.php/getCalendarObjects($calendarId) ");
|
||||
$return = array();
|
||||
foreach($data as $row)
|
||||
{
|
||||
@@ -295,7 +297,8 @@ END:VTIMEZONE\n".$event."\nEND:VCALENDAR";
|
||||
public function getCalendarObject($calendarId,$objectUri)
|
||||
{
|
||||
//error_log("Caldav_Backend.php/getCalendarObject($calendarId, $objectUri)");
|
||||
$user = $this->getUser();
|
||||
//$user = $this->getUser();
|
||||
$user = $calendarId;
|
||||
$data = $this->getCalendarData($user,$objectUri);
|
||||
if(count($data)==0)
|
||||
{
|
||||
|
||||
+61
-9
@@ -31,6 +31,7 @@ class MySabre_DAVACL_PrincipalBackend implements Sabre_DAVACL_IPrincipalBackend
|
||||
*/
|
||||
protected $groupMembersTableName;
|
||||
|
||||
protected $result_ma;
|
||||
/**
|
||||
* Sets up the backend.
|
||||
*
|
||||
@@ -40,6 +41,9 @@ class MySabre_DAVACL_PrincipalBackend implements Sabre_DAVACL_IPrincipalBackend
|
||||
public function __construct($auth)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
|
||||
$ma = new mitarbeiter();
|
||||
$this->result_ma = $ma->getMitarbeiter(null,null,null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,26 +77,54 @@ class MySabre_DAVACL_PrincipalBackend implements Sabre_DAVACL_IPrincipalBackend
|
||||
//error_log('Principal.php/getPrincipalsByPrefix('.$prefixPath.')');
|
||||
$principals = array();
|
||||
$user = $this->getUser();
|
||||
|
||||
if($prefixPath=='principals')
|
||||
{
|
||||
|
||||
$principals[] = array(
|
||||
'id' => 1,
|
||||
'id' => $user,
|
||||
'uri' => 'principals/'.$user,
|
||||
'{DAV:}displayname' => $user,
|
||||
'{http://sabredav.org/ns}email-address' => $user.'@example.com',
|
||||
);
|
||||
}
|
||||
elseif($prefixPath=='principals/oesi')
|
||||
{
|
||||
$principals[] = array(
|
||||
'id' => 2,
|
||||
/* $principals[] = array(
|
||||
'id' => $user.'proxyread',
|
||||
'uri' => 'principals/'.$user.'/calendar-proxy-read',
|
||||
'{DAV:}displayname' => '',
|
||||
'{http://sabredav.org/ns}email-address' => '',
|
||||
);*/
|
||||
//$ma = new mitarbeiter();
|
||||
//$result = $ma->getMitarbeiter(null,null,null);
|
||||
/*
|
||||
$i=0;
|
||||
foreach($this->result_ma as $row)
|
||||
{
|
||||
$i++;
|
||||
//if($i>10)
|
||||
// break;
|
||||
if($row->uid==$user)
|
||||
continue;
|
||||
$principals[] = array(
|
||||
'id' => $row->uid,
|
||||
'uri' => 'principals/'.$row->uid,
|
||||
'{DAV:}displayname' => $row->uid,
|
||||
'{http://sabredav.org/ns}email-address' => $row->uid.'@example.com',
|
||||
);
|
||||
$principals[] = array(
|
||||
'id' => $row->uid.'proxyread',
|
||||
'uri' => 'principals/'.$row->uid.'/calendar-proxy-read',
|
||||
'{DAV:}displayname' => '',
|
||||
'{http://sabredav.org/ns}email-address' => '',
|
||||
);
|
||||
|
||||
}*/
|
||||
}
|
||||
else //if($prefixPath=='principals/oesi')
|
||||
{
|
||||
$user = mb_substr($path,11);
|
||||
$principals[] = array(
|
||||
'id' => 3,
|
||||
'uri' => 'principals/'.$user.'/calendar-proxy-write',
|
||||
'id' => $user.'proxyread',
|
||||
'uri' => 'principals/'.$user.'/calendar-proxy-read',
|
||||
'{DAV:}displayname' => '',
|
||||
'{http://sabredav.org/ns}email-address' => '',
|
||||
);
|
||||
@@ -114,7 +146,9 @@ class MySabre_DAVACL_PrincipalBackend implements Sabre_DAVACL_IPrincipalBackend
|
||||
{
|
||||
//$path = principals/oesi
|
||||
//error_log('Principal.php/getPrincipalByPath('.$path.')');
|
||||
$user = $this->getUser();
|
||||
//$user = $this->getUser();
|
||||
$user = mb_substr($path,11);
|
||||
//error_log('user: '.$user);
|
||||
$result = array(
|
||||
'id' => $user,
|
||||
'uri' => 'principals/'.$user,
|
||||
@@ -150,7 +184,25 @@ class MySabre_DAVACL_PrincipalBackend implements Sabre_DAVACL_IPrincipalBackend
|
||||
public function getGroupMembership($principal)
|
||||
{
|
||||
//$principal = username
|
||||
// error_log('Principal.php/getGroupMembership('.$principal.')');
|
||||
$result = array();
|
||||
if(preg_match('/^principals\/[0-9A-Za-z\-]*$/',$principal))
|
||||
{
|
||||
$user = mb_substr($principal,11);
|
||||
//$ma = new mitarbeiter();
|
||||
//$result_ma = $ma->getMitarbeiter(null,null,null);
|
||||
$i=0;
|
||||
foreach($this->result_ma as $row)
|
||||
{
|
||||
$i++;
|
||||
//if($i>10)
|
||||
// break;
|
||||
if($row->uid==$user)
|
||||
continue;
|
||||
|
||||
$result[]='principals/'.$row->uid.'/calendar-proxy-read';
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
+13
-4
@@ -5,17 +5,26 @@ require_once '../include/sabredav/lib/Sabre/autoload.php';
|
||||
require_once 'auth.class.php';
|
||||
require_once 'Caldav_Backend.php';
|
||||
require_once('Principal.php');
|
||||
|
||||
/*
|
||||
//PHP Error To Exception
|
||||
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
|
||||
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
|
||||
}
|
||||
set_error_handler("exception_error_handler");
|
||||
*/
|
||||
// Backends
|
||||
$authBackend = new myAuth();
|
||||
$principalBackend = new MySabre_DAVACL_PrincipalBackend($authBackend);
|
||||
$calendarBackend = new MySabre_CalDAV_Backend($authBackend);
|
||||
|
||||
$tree = array(
|
||||
/*$tree = array(
|
||||
new Sabre_DAVACL_PrincipalCollection($principalBackend),
|
||||
new Sabre_CalDAV_CalendarRootNode($principalBackend, $calendarBackend)
|
||||
);
|
||||
|
||||
);*/
|
||||
$tree = array(
|
||||
new Sabre_CalDAV_Principal_Collection($principalBackend),
|
||||
new Sabre_CalDAV_CalendarRootNode($principalBackend, $calendarBackend)
|
||||
);
|
||||
|
||||
// The object tree needs in turn to be passed to the server class
|
||||
$server = new Sabre_DAV_Server($tree);
|
||||
|
||||
Reference in New Issue
Block a user