Caldav Schnittstelle korrigiert

- Fehler behoben bei dem Reservierungen nicht korrekt angezeigt wurden wenn diese in der Woche der Zeitumstellung liegen
- Fehler behoben wodurch es zu doppelten Einträgen im Kalender kam wenn sich die Endezeit eines Termines ändert
This commit is contained in:
oesi
2016-09-28 13:30:46 +02:00
parent c4dd21a6d0
commit bb54104111
3 changed files with 97 additions and 96 deletions
+30 -31
View File
@@ -23,7 +23,7 @@
class datum
{
public $ts_day=86400; // Timestamp eines Tages
/**
* Konstruktor
*
@@ -103,13 +103,12 @@ class datum
*/
public function jump_week($datum, $wochen)
{
$stunde_vor=date("G",$datum);
// Eine Woche sind 604800 Sekunden
$datum+=604800*$wochen;
$stunde_nach=date("G",$datum);
if ($stunde_nach!=$stunde_vor)
$datum+=3600;
return $datum;
$days = $wochen * 7;
$datetime=new DateTime();
$datetime->setTimestamp($datum);
$datetime->modify($days.' day');
return $datetime->format("U");
}
/**
@@ -159,7 +158,7 @@ class datum
else
return false;
}
/**
* Zieht ein Datum von einem anderen ab, und gibt die differenz in Tagen zurueck (mit Vorzeichen)
* @param $datum1
@@ -196,7 +195,7 @@ class datum
if($start=='' && $ende!='' && $dateende>=$dateref)
return true;
// Ende nicht gesetzt; Start gesetzt
// Ende nicht gesetzt; Start gesetzt
if($ende=='' && $start!='' && $datestart<=$dateref)
return true;
@@ -237,7 +236,7 @@ class datum
return $h1.':'.$m1;
}
/**
* Subtrahiert 2 Zeiten ($zeit1-$zeit2) Stunde:Minute
* Es liefert keine Uhrzeit zurueck sondern Stunden und Minuten
@@ -268,7 +267,7 @@ class datum
return $h1.':'.$m1;
}
/**
* Prueft und Liefert ein Datum im angegeben Format
* fuer die Formatierung wird die Funktion formatDatum verwendet
@@ -278,9 +277,9 @@ class datum
* Eintraege wie zB 'last Monday' oder 'a' auch in ein Datum umgewandelt werden.
* @return Formatierten Timestamp wenn ok, false im Fehlerfall
*/
function checkformatDatum($datum, $format='Y-m-d H:i:s', $strict=false)
function checkformatDatum($datum, $format='Y-m-d H:i:s', $strict=false)
{
@list($day, $month, $year) = @explode(".", $datum);
if (@checkdate($month, $day, $year))
return $this->formatDatum($datum, $format, $strict);
@@ -293,7 +292,7 @@ class datum
@list($year, $month, $day) = @explode("-", $datum);
if (@checkdate($month, $day, $year))
return $this->formatDatum($datum, $format, $strict);
if (strlen($datum)==6)
{
$year="20".substr($datum,0,2);
@@ -301,7 +300,7 @@ class datum
$day=substr($datum,4,2);
if (@checkdate($month, $day, $year))
return $this->formatDatum($datum, $format, $strict);
}
}
else if (strlen($datum)==8)
{
$year=substr($datum,0,4);
@@ -309,15 +308,15 @@ class datum
$day=substr($datum, 6,2);
if (@checkdate($month, $day, $year))
return $this->formatDatum($datum, $format, $strict);
$year=substr($datum,5,4);
$year=substr($datum,5,4);
$month=substr($datum,3,2);
$day=substr($datum, 0,2);
if (@checkdate($month, $day, $year))
return $this->formatDatum($datum, $format, $strict);
}
return false;
}
}
return false;
}
/**
@@ -334,18 +333,18 @@ class datum
{
if(trim($datum)=='')
return '';
$ts='';
$error=false;
//2008-12-31
if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})",$datum, $regs))
$ts = mktime(0,0,0,$regs[2],$regs[3],$regs[1]);
//2008-12-31 12:30
if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2})",$datum, $regs))
$ts = mktime($regs[4],$regs[5],0,$regs[2],$regs[3],$regs[1]);
//2008-12-31 12:30:15
if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})",$datum, $regs))
$ts = mktime($regs[4],$regs[5],$regs[6],$regs[2],$regs[3],$regs[1]);
@@ -355,20 +354,20 @@ class datum
//1.12.2008
if(mb_ereg("([0-9]{1,2}).([0-9]{1,2}).([0-9]{4})",$datum, $regs))
$ts = mktime(0,0,0,$regs[2],$regs[1],$regs[3]);
//1.12.2008 12:30
if(mb_ereg("([0-9]{1,2}).([0-9]{1,2}).([0-9]{4}) ([0-9]{2}):([0-9]{2})",$datum, $regs))
$ts = mktime($regs[4],$regs[5],0,$regs[2],$regs[1],$regs[3]);
//1.12.2008 12:30:15
if(mb_ereg("([0-9]{1,2}).([0-9]{1,2}).([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2})",$datum, $regs))
$ts = mktime($regs[4],$regs[5],$regs[6],$regs[2],$regs[1],$regs[3]);
}
if($ts=='' && !$strict)
{
$ts = strtotime($datum);
if(!$ts || $ts==-1)
{
//wenn strtotime fehlschlaegt liefert diese -1 zurueck, ab php5.1.0 jedoch false
@@ -378,9 +377,9 @@ class datum
if($ts!='' && !$error)
return date($format, $ts);
return false;
}
}
?>
+3 -3
View File
@@ -2384,7 +2384,7 @@ class wochenplan extends basis_db
/**
* Unterricht der ueber mehrere Stunden geht wird nicht einzeln Exportiert,
* sondern zusammengeblockt. (in maximal 4er Bloecke)
* sondern zusammengeblockt.
*
* Es wird nur ein Eintrag geschrieben, die restlichen werden uebersprungen.
* Vor dem Ueberspringen des Eintrages werden jedoch noch die dazu Gruppierten Eintraege
@@ -2499,7 +2499,7 @@ class wochenplan extends basis_db
$end_date_time_ical = $eda[2].$eda[1].$eda[0].'T'.sprintf('%02s',($eta[0])).$eta[1].$eta[2]; //neu gruppieren der Startzeit und des Startdatums
echo $this->crlf.'BEGIN:VEVENT'.$this->crlf
.'UID:'.'FH'.str_replace(',',' ',$lvb.$this->std_plan[$i][$j][$idx]->ort.$this->std_plan[$i][$j][$idx]->lektor.$lehrfach[$idx].$start_date_time_ical.$this->crlf)
.'UID:'.'FH'.str_replace(',',' ',$lvb.$this->std_plan[$i][$j][$idx]->ort.$this->std_plan[$i][$j][$idx]->lektor.$lehrfach[$idx].$start_date_time_ical.$end_date_time_ical.$this->crlf)
.'SUMMARY:'.str_replace(',',' ',$lehrfach[$idx].' '.$this->std_plan[$i][$j][$idx]->ort.' - '.$lvb.$this->crlf)
.'DESCRIPTION:'.str_replace(',',' ',$lehrfach[$idx].'\n'.$this->std_plan[$i][$j][$idx]->lektor.'\n'.$lvb.'\n'.$this->std_plan[$i][$j][$idx]->ort.(LVPLAN_ANMERKUNG_ANZEIGEN?'\n'.$this->std_plan[$i][$j][$idx]->anmerkung:'').$this->crlf)
.'LOCATION:'.$this->std_plan[$i][$j][$idx]->ort.$this->crlf
@@ -2541,7 +2541,7 @@ class wochenplan extends basis_db
$start_date_time_ical = $sda[2].$sda[1].$sda[0].'T'.sprintf('%02s',($sta[0])).$sta[1].$sta[2]; //neu gruppieren der Startzeit und des Startdatums
$end_date_time_ical = $eda[2].$eda[1].$eda[0].'T'.sprintf('%02s',($eta[0])).$eta[1].$eta[2]; //neu gruppieren der Startzeit und des Startdatums
$UID = 'FH'.$lvb.$this->std_plan[$i][$j][$idx]->ort.$this->std_plan[$i][$j][$idx]->lektor.$lehrfach[$idx].$start_date_time_ical;
$UID = 'FH'.$lvb.$this->std_plan[$i][$j][$idx]->ort.$this->std_plan[$i][$j][$idx]->lektor.$lehrfach[$idx].$start_date_time_ical.$end_date_time_ical;
$Summary = $lehrfach[$idx].' '.$this->std_plan[$i][$j][$idx]->ort.' - '.$lvb;
$description = $lehrfach[$idx].'\n'.$this->std_plan[$i][$j][$idx]->lektor.'\n'.$lvb.'\n'.$this->std_plan[$i][$j][$idx]->ort;
+64 -62
View File
@@ -2,17 +2,18 @@
require_once(dirname(__FILE__).'/../include/wochenplan.class.php');
require_once(dirname(__FILE__).'/../include/functions.inc.php');
require_once(dirname(__FILE__).'/../include/mitarbeiter.class.php');
require_once(dirname(__FILE__).'/../include/datum.class.php');
/**
* CalDAV backend
*/
class MySabre_CalDAV_Backend extends \Sabre\CalDAV\Backend\AbstractBackend
class MySabre_CalDAV_Backend extends \Sabre\CalDAV\Backend\AbstractBackend
{
/**
* Creates the backend
*
* Creates the backend
*
* @param AuthBackend $auth
*/
public function __construct($auth)
public function __construct($auth)
{
$this->auth = $auth;
}
@@ -31,18 +32,18 @@ class MySabre_CalDAV_Backend extends \Sabre\CalDAV\Backend\AbstractBackend
* Every project is an array with the following keys:
* * id, a unique id that will be used by other functions to modify the
* calendar. This can be the same as the uri or a database key.
* * uri, which the basename of the uri with which the calendar is
* * uri, which the basename of the uri with which the calendar is
* accessed.
* * principalUri. The owner of the calendar. Almost always the same as
* principalUri passed to this method.
*
* Furthermore it can contain webdav properties in clark notation. A very
* common one is '{DAV:}displayname'.
* common one is '{DAV:}displayname'.
*
* @param string $principalUri
* @return array
* @param string $principalUri
* @return array
*/
public function getCalendarsForUser($principalUri)
public function getCalendarsForUser($principalUri)
{
//error_log("Caldav_Backend.php/getCalendarsForUser($principalUri)");
//$user = $this->getUser();
@@ -75,7 +76,7 @@ class MySabre_CalDAV_Backend extends \Sabre\CalDAV\Backend\AbstractBackend
* @param string $calendarUri
* @param array $properties
*/
public function createCalendar($principalUri,$calendarUri, array $properties)
public function createCalendar($principalUri,$calendarUri, array $properties)
{
throw new \Sabre\DAV\Exception('Not Implemented');
}
@@ -108,43 +109,44 @@ class MySabre_CalDAV_Backend extends \Sabre\CalDAV\Backend\AbstractBackend
* )
* )
*
* In this example it was forbidden to update {DAV:}displayname.
* In this example it was forbidden to update {DAV:}displayname.
* (403 Forbidden), which in turn also caused {DAV:}owner to fail
* (424 Failed Dependency) because the request needs to be atomic.
*
* @param string $calendarId
* @param array $mutations
* @return bool|array
* @param array $mutations
* @return bool|array
*/
public function updateCalendar($calendarId, array $mutations)
public function updateCalendar($calendarId, array $mutations)
{
return false;
}
/**
* Delete a calendar and all it's objects
*
* @param string $calendarId
* Delete a calendar and all it's objects
*
* @param string $calendarId
* @return void
*/
public function deleteCalendar($calendarId)
public function deleteCalendar($calendarId)
{
throw new \Sabre\DAV\Exception('Not Implemented');
}
public function getCalendarData($user, $objectUri=null)
{
$datum_obj = new datum();
$starttime = microtime(true);
$bn = new benutzer();
if(!$bn->load($user))
die('User invalid');
if(check_lektor($user))
$type='lektor';
else
$type='student';
// Stundenplanobjekt erzeugen
$stdplan = new wochenplan($type);
$stdplan->crlf="\n";
@@ -156,7 +158,7 @@ class MySabre_CalDAV_Backend extends \Sabre\CalDAV\Backend\AbstractBackend
}
if(!is_null($objectUri))
{
$unr = mb_substr($objectUri, mb_strpos($objectUri,'-')+1);
$unr = mb_substr($objectUri, (mb_strpos($objectUri,'-')+1), mb_strpos($objectUri,'@')-(mb_strpos($objectUri,'-')+1));
$dtstart = mb_substr($objectUri,0,mb_strpos($objectUri,'-'));
if(mb_strlen($dtstart)==15)
@@ -170,14 +172,14 @@ class MySabre_CalDAV_Backend extends \Sabre\CalDAV\Backend\AbstractBackend
$sekunde = mb_substr($dtstart,13,2);
$begin = mktime($stunde, $minute, $sekunde, $monat, $tag-1, $jahr);
$ende = mktime($stunde, $minute, $sekunde, $monat, $tag+1, $jahr);
//error_log("getCalendarData unr: $unr dtstart: $dtstart");
//error_log("getCalendarData unr: $unr dtstart: $dtstart size:".(mb_strlen($objectUri)-mb_strpos($objectUri,'@')));
//error_log($begin.'/'.$ende);
}
else
{
//error_log("dtstart laenge abnormal: $dtstart");
$begin = mktime(0,0,0,date('m'),date('d')-14,date('Y'));
$ende = mktime(0,0,0,date('m')+6,date('d'),date('Y'));
$ende = mktime(0,0,0,date('m')+6,date('d'),date('Y'));
}
}
else
@@ -195,10 +197,10 @@ class MySabre_CalDAV_Backend extends \Sabre\CalDAV\Backend\AbstractBackend
$i++;
if(!date("w",$begin))
$begin=jump_day($begin,1);
$stdplan->init_stdplan();
$datum=$begin;
$begin+=604800; // eine Woche
$begin = $datum_obj->jump_week($begin,1);
// Stundenplan einer Woche laden
if(!$stdplan->load_week($datum,$db_stpl_table))
@@ -224,7 +226,7 @@ class MySabre_CalDAV_Backend extends \Sabre\CalDAV\Backend\AbstractBackend
//error_log("\n\nDATA".print_r($data,true));
//error_log("getCalendarData time:".($endtime-$starttime));
//$data.="\nEND:VCALENDAR";
return $data;
return $data;
}
public function makeCal($event)
{
@@ -250,28 +252,28 @@ END:STANDARD
END:VTIMEZONE\n".$event."\nEND:VCALENDAR";
}
/**
* Returns all calendar objects within a calendar.
* Returns all calendar objects within a calendar.
*
* Every item contains an array with the following keys:
* * id - unique identifier which will be used for subsequent updates
* * calendardata - The iCalendar-compatible calnedar data
* * uri - a unique key which will be used to construct the uri. This can be any arbitrary string.
* * lastmodified - a timestamp of the last modification time
* * etag - An arbitrary string, surrounded by double-quotes. (e.g.:
* * etag - An arbitrary string, surrounded by double-quotes. (e.g.:
* ' "abcdef"')
* * calendarid - The calendarid as it was passed to this function.
*
* Note that the etag is optional, but it's highly encouraged to return for
* Note that the etag is optional, but it's highly encouraged to return for
* speed reasons.
*
* The calendardata is also optional. If it's not returned
* 'getCalendarObject' will be called later, which *is* expected to return
* The calendardata is also optional. If it's not returned
* 'getCalendarObject' will be called later, which *is* expected to return
* calendardata.
*
* @param string $calendarId
* @return array
*
* @param string $calendarId
* @return array
*/
public function getCalendarObjects($calendarId)
public function getCalendarObjects($calendarId)
{
//$user = $this->getUser();
$user = $calendarId;
@@ -290,7 +292,7 @@ END:VTIMEZONE\n".$event."\nEND:VCALENDAR";
$return[] = array("id"=>$row['UID'],
"calendardata"=>$this->makeCal($row['data']),
"uri"=>$uri,
"uri"=>$uri.'@'.md5($row['UID']),
"lastmodified"=>$row['updateamum'],
"etag"=>'"'.$row['UID'].'"',
"calendarid"=>$calendarId);
@@ -303,15 +305,15 @@ END:VTIMEZONE\n".$event."\nEND:VCALENDAR";
* Returns information from a single calendar object, based on it's object
* uri.
*
* The returned array must have the same keys as getCalendarObjects. The
* 'calendardata' object is required here though, while it's not required
* The returned array must have the same keys as getCalendarObjects. The
* 'calendardata' object is required here though, while it's not required
* for getCalendarObjects.
*
* @param string $calendarId
* @param string $objectUri
* @return array
*
* @param string $calendarId
* @param string $objectUri
* @return array
*/
public function getCalendarObject($calendarId,$objectUri)
public function getCalendarObject($calendarId,$objectUri)
{
//error_log("Caldav_Backend.php/getCalendarObject($calendarId, $objectUri)");
//$user = $this->getUser();
@@ -330,7 +332,7 @@ END:VTIMEZONE\n".$event."\nEND:VCALENDAR";
{
$ret = array("id"=>$data['UID'],
"calendardata"=>$this->makeCal($data['data']),
"uri"=>'principals/'.$user.'/LVPlan/'.$data['dtstart'].'-'.$data['unr'][0],
"uri"=>'principals/'.$user.'/LVPlan/'.$data['dtstart'].'-'.$data['unr'][0].'@'.md5($data['UID']),
"lastmodified"=>$data['updateamum'],
"etag"=>'"'.$data['UID'].'"',
"calendarid"=>$calendarId);
@@ -339,39 +341,39 @@ END:VTIMEZONE\n".$event."\nEND:VCALENDAR";
}
/**
* Creates a new calendar object.
*
* @param string $calendarId
* @param string $objectUri
* @param string $calendarData
* Creates a new calendar object.
*
* @param string $calendarId
* @param string $objectUri
* @param string $calendarData
* @return void
*/
public function createCalendarObject($calendarId,$objectUri,$calendarData)
public function createCalendarObject($calendarId,$objectUri,$calendarData)
{
throw new \Sabre\DAV\Exception('Not Implemented');
}
/**
* Updates an existing calendarobject, based on it's uri.
*
* @param string $calendarId
* @param string $objectUri
* @param string $calendarData
* Updates an existing calendarobject, based on it's uri.
*
* @param string $calendarId
* @param string $objectUri
* @param string $calendarData
* @return void
*/
public function updateCalendarObject($calendarId,$objectUri,$calendarData)
public function updateCalendarObject($calendarId,$objectUri,$calendarData)
{
throw new \Sabre\DAV\Exception('Not Implemented');
}
/**
* Deletes an existing calendar object.
*
* @param string $calendarId
* @param string $objectUri
* Deletes an existing calendar object.
*
* @param string $calendarId
* @param string $objectUri
* @return void
*/
public function deleteCalendarObject($calendarId,$objectUri)
public function deleteCalendarObject($calendarId,$objectUri)
{
throw new Sabre\DAV\Exception('Not Implemented');
}