summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Häusler <msquare@notrademark.de>2011-10-11 19:47:49 +0200
committerPhilip Häusler <msquare@notrademark.de>2011-10-11 19:47:49 +0200
commit304af8e8f015ac896ad0683c6407a3269e981d97 (patch)
tree32454b2c7eaa432c6cfabf3809e60d2f2d2d0d0b
parent1854e1455abcb23d3dc2c1ad206525227d08587d (diff)
#27 ical export, beginn
-rw-r--r--db/update.sql14
-rw-r--r--includes/pages/user_ical.php34
-rw-r--r--includes/pages/user_myshifts.php3
-rw-r--r--public/index.php6
4 files changed, 55 insertions, 2 deletions
diff --git a/db/update.sql b/db/update.sql
new file mode 100644
index 00000000..c2ebf441
--- /dev/null
+++ b/db/update.sql
@@ -0,0 +1,14 @@
+/* Update für #27, iCal-Export */
+ALTER TABLE `User` ADD `ical_key` VARCHAR( 32 ) NOT NULL ,
+ADD UNIQUE (
+`ical_key`
+);
+
+INSERT INTO `engelsystem`.`Privileges` (
+`id` ,
+`name` ,
+`desc`
+)
+VALUES (
+NULL , 'ical', 'iCal Schicht Export'
+); \ No newline at end of file
diff --git a/includes/pages/user_ical.php b/includes/pages/user_ical.php
new file mode 100644
index 00000000..181a7781
--- /dev/null
+++ b/includes/pages/user_ical.php
@@ -0,0 +1,34 @@
+<?php
+
+
+// Öffentlich zugängliche Funktion zum Abrufen von iCal-Exports der eigenen Schichten
+function user_ical() {
+ if (isset ($_REQUEST['key']) && preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key']))
+ $key = $_REQUEST['key'];
+ else
+ die("Missing key.");
+
+ $user = sql_select("SELECT * FROM `User` WHERE `ical_key`='" . sql_escape($key) . "' LIMIT 1");
+ if (count($user) == 0)
+ die("Key invalid.");
+
+ $user = $user[0];
+
+ $shifts = sql_select("SELECT * FROM `ShiftEntry` JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`) WHERE `UID`=" . sql_escape($user['UID']) . " ORDER BY `start`");
+
+ header("Content-Type: text/calendar");
+ echo "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//-//Engelsystem//DE\nCALSCALE:GREGORIAN\n";
+ foreach ($shifts as $shift) {
+ echo "BEGIN:VEVENT\n";
+ echo "UID:" . md5($shift['start'] . $shift['end'] . $shift['name']) . "\n";
+ echo "SUMMARY:" . str_replace("\n", "\\n", $shift['name']) . "\n";
+ echo "DESCRIPTION:" . str_replace("\n", "\\n", $shift['Comment']) . "\n";
+ echo "DTSTART;TZID=Europe/Berlin:" . date("Ymd\THis", $shift['start']) . "\n";
+ echo "DTEND;TZID=Europe/Berlin:" . date("Ymd\THis", $shift['end']) . "\n";
+ echo "LOCATION:" . $shift['Name'] . "\n";
+ echo "END:VEVENT\n";
+ }
+ echo "END:VCALENDAR\n";
+ die();
+}
+?>
diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php
index 4dc4cc81..60c5bba0 100644
--- a/includes/pages/user_myshifts.php
+++ b/includes/pages/user_myshifts.php
@@ -1,7 +1,7 @@
<?php
-//
+// Zeigt die Schichten an, die ein Benutzer belegt
function user_myshifts() {
global $LETZTES_AUSTRAGEN;
global $user, $privileges;
@@ -44,6 +44,7 @@ function user_myshifts() {
header("Location: " . page_link_to('user_myshifts'));
}
$shifts = sql_select("SELECT * FROM `ShiftEntry` JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`) WHERE `UID`=" . sql_escape($user['UID']) . " ORDER BY `start`");
+
$html = "";
foreach ($shifts as $shift) {
if (time() > $shift['end'])
diff --git a/public/index.php b/public/index.php
index 2a5a273b..1a58852b 100644
--- a/public/index.php
+++ b/public/index.php
@@ -34,8 +34,12 @@ if (isset ($_REQUEST['p']) && preg_match("/^[a-z0-9_]*$/i", $_REQUEST['p']) && s
$title = Get_Text($p);
$content = "";
+if ($p == "ical") {
+ require_once ('includes/pages/user_ical.php');
+ user_ical();
+}
// Recht dafür vorhanden?
-if (in_array($p, $privileges)) {
+elseif (in_array($p, $privileges)) {
if ($p == "news") {
require_once ('includes/pages/user_news.php');
$content = user_news();