Abgleich mit Live-Daten
This commit is contained in:
+130
-130
@@ -1,131 +1,131 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ICS.php
|
||||
* =======
|
||||
* Use this class to create an .ics file.
|
||||
*
|
||||
* Usage
|
||||
* -----
|
||||
* Basic usage - generate ics file contents (see below for available properties):
|
||||
* $ics = new ICS($props);
|
||||
* $ics_file_contents = $ics->to_string();
|
||||
*
|
||||
* Setting properties after instantiation
|
||||
* $ics = new ICS();
|
||||
* $ics->set('summary', 'My awesome event');
|
||||
*
|
||||
* You can also set multiple properties at the same time by using an array:
|
||||
* $ics->set(array(
|
||||
* 'dtstart' => 'now + 30 minutes',
|
||||
* 'dtend' => 'now + 1 hour'
|
||||
* ));
|
||||
*
|
||||
* Available properties
|
||||
* --------------------
|
||||
* description
|
||||
* String description of the event.
|
||||
* dtend
|
||||
* A date/time stamp designating the end of the event. You can use either a
|
||||
* DateTime object or a PHP datetime format string (e.g. "now + 1 hour").
|
||||
* dtstart
|
||||
* A date/time stamp designating the start of the event. You can use either a
|
||||
* DateTime object or a PHP datetime format string (e.g. "now + 1 hour").
|
||||
* location
|
||||
* String address or description of the location of the event.
|
||||
* summary
|
||||
* String short summary of the event - usually used as the title.
|
||||
* url
|
||||
* A url to attach to the the event. Make sure to add the protocol (http://
|
||||
* or https://).
|
||||
*/
|
||||
|
||||
class ICS {
|
||||
const DT_FORMAT = 'Ymd\THis\Z';
|
||||
|
||||
protected $properties = array();
|
||||
private $available_properties = array(
|
||||
'description',
|
||||
'dtend',
|
||||
'dtstart',
|
||||
'location',
|
||||
'summary',
|
||||
'url'
|
||||
);
|
||||
|
||||
public function __construct($props) {
|
||||
$this->set($props);
|
||||
}
|
||||
|
||||
public function set($key, $val = false) {
|
||||
if (is_array($key)) {
|
||||
foreach ($key as $k => $v) {
|
||||
$this->set($k, $v);
|
||||
}
|
||||
} else {
|
||||
if (in_array($key, $this->available_properties)) {
|
||||
$this->properties[$key] = $this->sanitize_val($val, $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function to_string() {
|
||||
$rows = $this->build_props();
|
||||
return implode("\r\n", $rows);
|
||||
}
|
||||
|
||||
private function build_props() {
|
||||
// Build ICS properties - add header
|
||||
$ics_props = array(
|
||||
'BEGIN:VCALENDAR',
|
||||
'VERSION:2.0',
|
||||
'PRODID:-//hacksw/handcal//NONSGML v1.0//EN',
|
||||
'CALSCALE:GREGORIAN',
|
||||
'BEGIN:VEVENT'
|
||||
);
|
||||
|
||||
// Build ICS properties - add header
|
||||
$props = array();
|
||||
foreach($this->properties as $k => $v) {
|
||||
$props[strtoupper($k . ($k === 'url' ? ';VALUE=URI' : ''))] = $v;
|
||||
}
|
||||
|
||||
// Set some default values
|
||||
$props['DTSTAMP'] = $this->format_timestamp('now');
|
||||
$props['UID'] = uniqid();
|
||||
|
||||
// Append properties
|
||||
foreach ($props as $k => $v) {
|
||||
$ics_props[] = "$k:$v";
|
||||
}
|
||||
|
||||
// Build ICS properties - add footer
|
||||
$ics_props[] = 'END:VEVENT';
|
||||
$ics_props[] = 'END:VCALENDAR';
|
||||
|
||||
return $ics_props;
|
||||
}
|
||||
|
||||
private function sanitize_val($val, $key = false) {
|
||||
switch($key) {
|
||||
case 'dtend':
|
||||
case 'dtstamp':
|
||||
case 'dtstart':
|
||||
$val = $this->format_timestamp($val);
|
||||
break;
|
||||
default:
|
||||
$val = $this->escape_string($val);
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
private function format_timestamp($timestamp) {
|
||||
$dt = new DateTime($timestamp);
|
||||
return $dt->format(self::DT_FORMAT);
|
||||
}
|
||||
|
||||
private function escape_string($str) {
|
||||
return preg_replace('/([\,;])/','\\\$1', $str);
|
||||
}
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ICS.php
|
||||
* =======
|
||||
* Use this class to create an .ics file.
|
||||
*
|
||||
* Usage
|
||||
* -----
|
||||
* Basic usage - generate ics file contents (see below for available properties):
|
||||
* $ics = new ICS($props);
|
||||
* $ics_file_contents = $ics->to_string();
|
||||
*
|
||||
* Setting properties after instantiation
|
||||
* $ics = new ICS();
|
||||
* $ics->set('summary', 'My awesome event');
|
||||
*
|
||||
* You can also set multiple properties at the same time by using an array:
|
||||
* $ics->set(array(
|
||||
* 'dtstart' => 'now + 30 minutes',
|
||||
* 'dtend' => 'now + 1 hour'
|
||||
* ));
|
||||
*
|
||||
* Available properties
|
||||
* --------------------
|
||||
* description
|
||||
* String description of the event.
|
||||
* dtend
|
||||
* A date/time stamp designating the end of the event. You can use either a
|
||||
* DateTime object or a PHP datetime format string (e.g. "now + 1 hour").
|
||||
* dtstart
|
||||
* A date/time stamp designating the start of the event. You can use either a
|
||||
* DateTime object or a PHP datetime format string (e.g. "now + 1 hour").
|
||||
* location
|
||||
* String address or description of the location of the event.
|
||||
* summary
|
||||
* String short summary of the event - usually used as the title.
|
||||
* url
|
||||
* A url to attach to the the event. Make sure to add the protocol (http://
|
||||
* or https://).
|
||||
*/
|
||||
|
||||
class ICS {
|
||||
const DT_FORMAT = 'Ymd\THis\Z';
|
||||
|
||||
protected $properties = array();
|
||||
private $available_properties = array(
|
||||
'description',
|
||||
'dtend',
|
||||
'dtstart',
|
||||
'location',
|
||||
'summary',
|
||||
'url'
|
||||
);
|
||||
|
||||
public function __construct($props) {
|
||||
$this->set($props);
|
||||
}
|
||||
|
||||
public function set($key, $val = false) {
|
||||
if (is_array($key)) {
|
||||
foreach ($key as $k => $v) {
|
||||
$this->set($k, $v);
|
||||
}
|
||||
} else {
|
||||
if (in_array($key, $this->available_properties)) {
|
||||
$this->properties[$key] = $this->sanitize_val($val, $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function to_string() {
|
||||
$rows = $this->build_props();
|
||||
return implode("\r\n", $rows);
|
||||
}
|
||||
|
||||
private function build_props() {
|
||||
// Build ICS properties - add header
|
||||
$ics_props = array(
|
||||
'BEGIN:VCALENDAR',
|
||||
'VERSION:2.0',
|
||||
'PRODID:-//hacksw/handcal//NONSGML v1.0//EN',
|
||||
'CALSCALE:GREGORIAN',
|
||||
'BEGIN:VEVENT'
|
||||
);
|
||||
|
||||
// Build ICS properties - add header
|
||||
$props = array();
|
||||
foreach($this->properties as $k => $v) {
|
||||
$props[strtoupper($k . ($k === 'url' ? ';VALUE=URI' : ''))] = $v;
|
||||
}
|
||||
|
||||
// Set some default values
|
||||
$props['DTSTAMP'] = $this->format_timestamp('now');
|
||||
$props['UID'] = uniqid();
|
||||
|
||||
// Append properties
|
||||
foreach ($props as $k => $v) {
|
||||
$ics_props[] = "$k:$v";
|
||||
}
|
||||
|
||||
// Build ICS properties - add footer
|
||||
$ics_props[] = 'END:VEVENT';
|
||||
$ics_props[] = 'END:VCALENDAR';
|
||||
|
||||
return $ics_props;
|
||||
}
|
||||
|
||||
private function sanitize_val($val, $key = false) {
|
||||
switch($key) {
|
||||
case 'dtend':
|
||||
case 'dtstamp':
|
||||
case 'dtstart':
|
||||
$val = $this->format_timestamp($val);
|
||||
break;
|
||||
default:
|
||||
$val = $this->escape_string($val);
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
private function format_timestamp($timestamp) {
|
||||
$dt = new DateTime($timestamp);
|
||||
return $dt->format(self::DT_FORMAT);
|
||||
}
|
||||
|
||||
private function escape_string($str) {
|
||||
return preg_replace('/([\,;])/','\\\$1', $str);
|
||||
}
|
||||
}
|
||||
+568
-568
File diff suppressed because it is too large
Load Diff
+986
-986
File diff suppressed because it is too large
Load Diff
+796
-796
File diff suppressed because it is too large
Load Diff
+51
-56
@@ -1,56 +1,51 @@
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//ZContent.net//ZapCalLib 1.0//EN
|
||||
CALSCALE:GREGORIAN
|
||||
METHOD:PUBLISH
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20250912
|
||||
DTEND:20250921
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251002
|
||||
DTEND:20251005
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251020
|
||||
DTEND:20251103
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251223
|
||||
DTEND:20251228
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251230
|
||||
DTEND:20260102
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251231
|
||||
DTEND:20260102
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251231
|
||||
DTEND:20260101
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20260102
|
||||
DTEND:20260111
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20260109
|
||||
DTEND:20260110
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20260201
|
||||
DTEND:20260204
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//ZContent.net//ZapCalLib 1.0//EN
|
||||
CALSCALE:GREGORIAN
|
||||
METHOD:PUBLISH
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251002
|
||||
DTEND:20251005
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251020
|
||||
DTEND:20251103
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251223
|
||||
DTEND:20251228
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251230
|
||||
DTEND:20260102
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251231
|
||||
DTEND:20260102
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251231
|
||||
DTEND:20260101
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20260102
|
||||
DTEND:20260111
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20260109
|
||||
DTEND:20260110
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20260201
|
||||
DTEND:20260204
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
|
||||
+51
-56
@@ -1,56 +1,51 @@
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//ZContent.net//ZapCalLib 1.0//EN
|
||||
CALSCALE:GREGORIAN
|
||||
METHOD:PUBLISH
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20250912
|
||||
DTEND:20250921
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251002
|
||||
DTEND:20251005
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251020
|
||||
DTEND:20251103
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251223
|
||||
DTEND:20251228
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251230
|
||||
DTEND:20260102
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251231
|
||||
DTEND:20260102
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251231
|
||||
DTEND:20260101
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20260102
|
||||
DTEND:20260111
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20260109
|
||||
DTEND:20260110
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20260201
|
||||
DTEND:20260204
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//ZContent.net//ZapCalLib 1.0//EN
|
||||
CALSCALE:GREGORIAN
|
||||
METHOD:PUBLISH
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251002
|
||||
DTEND:20251005
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251020
|
||||
DTEND:20251103
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251223
|
||||
DTEND:20251228
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251230
|
||||
DTEND:20260102
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251231
|
||||
DTEND:20260102
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20251231
|
||||
DTEND:20260101
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20260102
|
||||
DTEND:20260111
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20260109
|
||||
DTEND:20260110
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Urlaub
|
||||
DTSTART:20260201
|
||||
DTEND:20260204
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
|
||||
+51
-51
@@ -1,52 +1,52 @@
|
||||
<?php
|
||||
|
||||
require_once("./zapcallib.php");
|
||||
include './../inc/config.inc.php';
|
||||
|
||||
$startdate= date('Y-m-d',(strtotime ( '-180 days' ) ));
|
||||
// SQL-Abfrage, um Urlaubstermine abzurufen
|
||||
$sql = 'SELECT DATE_ADD(start, INTERVAL 1 DAY) AS stadate , DATE_ADD(ende, INTERVAL 1 DAY) AS enddate FROM urlaub WHERE start >= "' . $startdate . '"';
|
||||
$sql = 'SELECT start AS stadate , DATE_ADD(ende, INTERVAL 1 DAY) AS enddate FROM urlaub WHERE start >= "' . $startdate . '"';
|
||||
#echo $sql;
|
||||
$result = mysqli_query($con, $sql);
|
||||
|
||||
// create the ical object
|
||||
$icalobj = new ZCiCal();
|
||||
|
||||
$title = "Urlaub";
|
||||
|
||||
// Iteriere durch die Ergebnisse und füge Events zur iCal-Datei hinzu
|
||||
while ($row = mysqli_fetch_assoc($result)) {
|
||||
// create the event within the ical object
|
||||
$eventobj = new ZCiCalNode("VEVENT", $icalobj->curnode);
|
||||
|
||||
// add title
|
||||
$eventobj->addNode(new ZCiCalDataNode("SUMMARY:" . $title));
|
||||
|
||||
// add start date
|
||||
$eventobj->addNode(new ZCiCalDataNode("DTSTART:" . ZCiCal::fromSqlDateTime($row["stadate"])));
|
||||
|
||||
// add end date
|
||||
$eventobj->addNode(new ZCiCalDataNode("DTEND:" . ZCiCal::fromSqlDateTime($row["enddate"])));
|
||||
|
||||
}
|
||||
|
||||
// iCal-Datei ausgeben
|
||||
file_put_contents("kalender.ics", $icalobj->export());
|
||||
file_put_contents("kalender.ical", $icalobj->export());
|
||||
echo "Aktualisierung angestossen. Bitte Kalender pruefen.<br>Wenn in dieser Liste der Eintrag steht, dann sind Anfragen und Telefonanlage vorbereitet!<br><br>";
|
||||
#echo file_get_contents('./kalender.ical', true);
|
||||
$handle = fopen("./kalender.ical", "r");
|
||||
if ($handle) {
|
||||
while (($line = fgets($handle)) !== false) {
|
||||
// process the line read.
|
||||
echo $line . "<br>";
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
}
|
||||
echo"<br>Der letzte oder vorherige Eintrag bei DTSTART und DTEND sollte das gewuenschte Urlaubsdatum plus einen Tag haben.<br>
|
||||
20240330 steht fuer den 30.03.2024.<br>
|
||||
";
|
||||
|
||||
<?php
|
||||
|
||||
require_once("./zapcallib.php");
|
||||
include './../inc/config.inc.php';
|
||||
|
||||
$startdate= date('Y-m-d',(strtotime ( '-180 days' ) ));
|
||||
// SQL-Abfrage, um Urlaubstermine abzurufen
|
||||
$sql = 'SELECT DATE_ADD(start, INTERVAL 1 DAY) AS stadate , DATE_ADD(ende, INTERVAL 1 DAY) AS enddate FROM urlaub WHERE start >= "' . $startdate . '"';
|
||||
$sql = 'SELECT start AS stadate , DATE_ADD(ende, INTERVAL 1 DAY) AS enddate FROM urlaub WHERE start >= "' . $startdate . '"';
|
||||
#echo $sql;
|
||||
$result = mysqli_query($con, $sql);
|
||||
|
||||
// create the ical object
|
||||
$icalobj = new ZCiCal();
|
||||
|
||||
$title = "Urlaub";
|
||||
|
||||
// Iteriere durch die Ergebnisse und füge Events zur iCal-Datei hinzu
|
||||
while ($row = mysqli_fetch_assoc($result)) {
|
||||
// create the event within the ical object
|
||||
$eventobj = new ZCiCalNode("VEVENT", $icalobj->curnode);
|
||||
|
||||
// add title
|
||||
$eventobj->addNode(new ZCiCalDataNode("SUMMARY:" . $title));
|
||||
|
||||
// add start date
|
||||
$eventobj->addNode(new ZCiCalDataNode("DTSTART:" . ZCiCal::fromSqlDateTime($row["stadate"])));
|
||||
|
||||
// add end date
|
||||
$eventobj->addNode(new ZCiCalDataNode("DTEND:" . ZCiCal::fromSqlDateTime($row["enddate"])));
|
||||
|
||||
}
|
||||
|
||||
// iCal-Datei ausgeben
|
||||
file_put_contents("kalender.ics", $icalobj->export());
|
||||
file_put_contents("kalender.ical", $icalobj->export());
|
||||
echo "Aktualisierung angestossen. Bitte Kalender pruefen.<br>Wenn in dieser Liste der Eintrag steht, dann sind Anfragen und Telefonanlage vorbereitet!<br><br>";
|
||||
#echo file_get_contents('./kalender.ical', true);
|
||||
$handle = fopen("./kalender.ical", "r");
|
||||
if ($handle) {
|
||||
while (($line = fgets($handle)) !== false) {
|
||||
// process the line read.
|
||||
echo $line . "<br>";
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
}
|
||||
echo"<br>Der letzte oder vorherige Eintrag bei DTSTART und DTEND sollte das gewuenschte Urlaubsdatum plus einen Tag haben.<br>
|
||||
20240330 steht fuer den 30.03.2024.<br>
|
||||
";
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user