ical export for available shifts
This commit is contained in:
parent
3271f72dcf
commit
1633d62772
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
// Öffentlich zugängliche Funktion zum Abrufen von iCal-Exports der eigenen Schichten
|
// Öffentlich zugängliche Funktion zum Abrufen von iCal-Exports der eigenen Schichten
|
||||||
function user_ical() {
|
function user_ical() {
|
||||||
|
global $ical_shifts;
|
||||||
|
|
||||||
if (isset ($_REQUEST['key']) && preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key']))
|
if (isset ($_REQUEST['key']) && preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key']))
|
||||||
$key = $_REQUEST['key'];
|
$key = $_REQUEST['key'];
|
||||||
else
|
else
|
||||||
|
@ -14,21 +16,26 @@ function user_ical() {
|
||||||
|
|
||||||
$user = $user[0];
|
$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`");
|
if (isset ($_REQUEST['export']) && $_REQUEST['export'] == 'user_shifts') {
|
||||||
|
require_once ('includes/pages/user_shifts.php');
|
||||||
header("Content-Type: text/calendar");
|
view_user_shifts();
|
||||||
echo "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//-//Engelsystem//DE\nCALSCALE:GREGORIAN\n";
|
} else {
|
||||||
foreach ($shifts as $shift) {
|
$ical_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`");
|
||||||
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";
|
|
||||||
|
header("Content-Type: text/calendar; charset=utf-8");
|
||||||
|
echo "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//-//Engelsystem//DE\r\nCALSCALE:GREGORIAN\r\n";
|
||||||
|
foreach ($ical_shifts as $shift) {
|
||||||
|
echo "BEGIN:VEVENT\r\n";
|
||||||
|
echo "UID:" . md5($shift['start'] . $shift['end'] . $shift['name']) . "\r\n";
|
||||||
|
echo "SUMMARY:" . str_replace("\n", "\\n", preg_replace("/[^a-z]*/i", '', $shift['name'])) . "\r\n";
|
||||||
|
echo "DESCRIPTION:" . str_replace("\n", "\\n", $shift['Comment']) . "\r\n";
|
||||||
|
echo "DTSTART;TZID=Europe/Berlin:" . date("Ymd\THis", $shift['start']) . "\r\n";
|
||||||
|
echo "DTEND;TZID=Europe/Berlin:" . date("Ymd\THis", $shift['end']) . "\r\n";
|
||||||
|
echo "LOCATION:" . $shift['Name'] . "\r\n";
|
||||||
|
echo "END:VEVENT\r\n";
|
||||||
|
}
|
||||||
|
echo "END:VCALENDAR\r\n";
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -95,9 +95,4 @@ function user_myshifts() {
|
||||||
'reset_link' => page_link_to('user_myshifts') . '&reset'
|
'reset_link' => page_link_to('user_myshifts') . '&reset'
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
function user_reset_ical_key($user) {
|
|
||||||
$user['ical_key'] = md5($user['Nick'] . time() . rand());
|
|
||||||
sql_query("UPDATE `User` SET `ical_key`='" . sql_escape($user['ical_key']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "' LIMIT 1");
|
|
||||||
}
|
|
||||||
?>
|
?>
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
function user_shifts() {
|
function user_shifts() {
|
||||||
global $user, $privileges;
|
global $user, $privileges;
|
||||||
|
|
||||||
// Löschen einzelner Schicht-Einträge (Also Belegung einer Schicht von Engeln) durch Admins
|
// Löschen einzelner Schicht-Einträge (Also Belegung einer Schicht von Engeln) durch Admins
|
||||||
if (isset ($_REQUEST['entry_id']) && in_array('user_shifts_admin', $privileges)) {
|
if (isset ($_REQUEST['entry_id']) && in_array('user_shifts_admin', $privileges)) {
|
||||||
if (isset ($_REQUEST['entry_id']) && preg_match("/^[0-9]*$/", $_REQUEST['entry_id']))
|
if (isset ($_REQUEST['entry_id']) && preg_match("/^[0-9]*$/", $_REQUEST['entry_id']))
|
||||||
|
@ -210,37 +211,62 @@ function user_shifts() {
|
||||||
'comment' => ""
|
'comment' => ""
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
|
return view_user_shifts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function view_user_shifts() {
|
||||||
|
global $user, $privileges;
|
||||||
|
global $ical_shifts;
|
||||||
|
|
||||||
$days = sql_select("SELECT DISTINCT DATE(FROM_UNIXTIME(`start`)) AS `id`, DATE(FROM_UNIXTIME(`start`)) AS `name` FROM `Shifts`");
|
$days = sql_select("SELECT DISTINCT DATE(FROM_UNIXTIME(`start`)) AS `id`, DATE(FROM_UNIXTIME(`start`)) AS `name` FROM `Shifts`");
|
||||||
$rooms = sql_select("SELECT `RID` AS `id`, `Name` AS `name` FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
|
$rooms = sql_select("SELECT `RID` AS `id`, `Name` AS `name` FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
|
||||||
$types = sql_select("SELECT `id`, `name` FROM `AngelTypes`");
|
$types = sql_select("SELECT `id`, `name` FROM `AngelTypes`");
|
||||||
$filled = array(array('id' => '1', 'name' => 'Volle'), array('id' => '0', 'name' => 'Freie'));
|
$filled = array (
|
||||||
|
array (
|
||||||
|
'id' => '1',
|
||||||
|
'name' => 'Volle'
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'id' => '0',
|
||||||
|
'name' => 'Freie'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
if (!isset ($_SESSION['user_shifts']))
|
if (!isset ($_SESSION['user_shifts']))
|
||||||
$_SESSION['user_shifts'] = array ();
|
$_SESSION['user_shifts'] = array ();
|
||||||
|
|
||||||
if (!isset ($_SESSION['user_shifts']['filled'])) {
|
if (!isset ($_SESSION['user_shifts']['filled'])) {
|
||||||
$_SESSION['user_shifts']['filled'] = array (0);
|
$_SESSION['user_shifts']['filled'] = array (
|
||||||
|
0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(array('rooms', 'types', 'filled') as $key) {
|
foreach (array (
|
||||||
|
'rooms',
|
||||||
|
'types',
|
||||||
|
'filled'
|
||||||
|
) as $key) {
|
||||||
if (isset ($_REQUEST[$key])) {
|
if (isset ($_REQUEST[$key])) {
|
||||||
$filtered = array_filter($_REQUEST[$key], 'is_numeric');
|
$filtered = array_filter($_REQUEST[$key], 'is_numeric');
|
||||||
if (!empty($filtered))
|
if (!empty ($filtered))
|
||||||
$_SESSION['user_shifts'][$key] = $filtered;
|
$_SESSION['user_shifts'][$key] = $filtered;
|
||||||
unset($filtered);
|
unset ($filtered);
|
||||||
}
|
}
|
||||||
if (!isset ($_SESSION['user_shifts'][$key]))
|
if (!isset ($_SESSION['user_shifts'][$key]))
|
||||||
$_SESSION['user_shifts'][$key] = array_map('get_ids_from_array', $$key);
|
$_SESSION['user_shifts'][$key] = array_map('get_ids_from_array', $$key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_REQUEST['days'])) {
|
if (isset ($_REQUEST['days'])) {
|
||||||
$filtered = array_filter($_REQUEST['days'], create_function('$a', 'return preg_match("/^\d\d\d\d-\d\d-\d\d\\$/", $a);'));
|
$filtered = array_filter($_REQUEST['days'], create_function('$a', 'return preg_match("/^\d\d\d\d-\d\d-\d\d\\$/", $a);'));
|
||||||
if (!empty($filtered))
|
if (!empty ($filtered))
|
||||||
$_SESSION['user_shifts']['days'] = $filtered;
|
$_SESSION['user_shifts']['days'] = $filtered;
|
||||||
unset($filtered);
|
unset ($filtered);
|
||||||
}
|
}
|
||||||
if (!isset ($_SESSION['user_shifts']['days']))
|
if (!isset ($_SESSION['user_shifts']['days']))
|
||||||
$_SESSION['user_shifts']['days'] = array(date('Y-m-d'));
|
$_SESSION['user_shifts']['days'] = array (
|
||||||
|
date('Y-m-d')
|
||||||
|
);
|
||||||
|
|
||||||
$shifts = sql_select("SELECT * FROM `Shifts`
|
$shifts = sql_select("SELECT * FROM `Shifts`
|
||||||
WHERE `RID` IN (" . implode(',', $_SESSION['user_shifts']['rooms']) . ")
|
WHERE `RID` IN (" . implode(',', $_SESSION['user_shifts']['rooms']) . ")
|
||||||
|
@ -262,7 +288,7 @@ function user_shifts() {
|
||||||
JOIN `AngelTypes`
|
JOIN `AngelTypes`
|
||||||
ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id`)
|
ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id`)
|
||||||
WHERE ";
|
WHERE ";
|
||||||
if($shift_has_special_needs)
|
if ($shift_has_special_needs)
|
||||||
$query .= "`shift_id` = " . sql_escape($shift['SID']);
|
$query .= "`shift_id` = " . sql_escape($shift['SID']);
|
||||||
else
|
else
|
||||||
$query .= "`room_id` = " . sql_escape($shift['RID']);
|
$query .= "`room_id` = " . sql_escape($shift['RID']);
|
||||||
|
@ -295,22 +321,39 @@ function user_shifts() {
|
||||||
$shift_row .= join(", ", $entry_list);
|
$shift_row .= join(", ", $entry_list);
|
||||||
$shift_row .= '<br />';
|
$shift_row .= '<br />';
|
||||||
}
|
}
|
||||||
if (($is_free && in_array(0, $_SESSION['user_shifts']['filled']))
|
if (($is_free && in_array(0, $_SESSION['user_shifts']['filled'])) || (!$is_free && in_array(1, $_SESSION['user_shifts']['filled']))) {
|
||||||
|| (!$is_free && in_array(1, $_SESSION['user_shifts']['filled']))) {
|
|
||||||
$shifts_table .= $shift_row . '</td></tr>';
|
$shifts_table .= $shift_row . '</td></tr>';
|
||||||
$row_count++;
|
$row_count++;
|
||||||
|
$ical_shifts[] = $shift;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($user['ical_key'] == "")
|
||||||
|
user_reset_ical_key($user);
|
||||||
|
|
||||||
return template_render('../templates/user_shifts.html', array (
|
return template_render('../templates/user_shifts.html', array (
|
||||||
'room_select' => make_select($rooms, $_SESSION['user_shifts']['rooms'], "rooms", "Räume"),
|
'room_select' => make_select($rooms, $_SESSION['user_shifts']['rooms'], "rooms", "Räume"),
|
||||||
'day_select' => make_select($days, $_SESSION['user_shifts']['days'], "days", "Tage"),
|
'day_select' => make_select($days, $_SESSION['user_shifts']['days'], "days", "Tage"),
|
||||||
'type_select' => make_select($types, $_SESSION['user_shifts']['types'], "types", "Aufgaben"),
|
'type_select' => make_select($types, $_SESSION['user_shifts']['types'], "types", "Aufgaben"),
|
||||||
'filled_select' => make_select($filled, $_SESSION['user_shifts']['filled'], "filled", "Besetzung"),
|
'filled_select' => make_select($filled, $_SESSION['user_shifts']['filled'], "filled", "Besetzung"),
|
||||||
'shifts_table' => $shifts_table
|
'shifts_table' => $shifts_table,
|
||||||
|
'ical_link' => make_user_shifts_ical_link($user['ical_key']),
|
||||||
|
'reset_link' => page_link_to('user_myshifts') . '&reset'
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function make_user_shifts_ical_link($key) {
|
||||||
|
$link = "";
|
||||||
|
foreach ($_SESSION['user_shifts']['rooms'] as $room)
|
||||||
|
$link .= '&rooms[]=' . $room;
|
||||||
|
foreach ($_SESSION['user_shifts']['days'] as $day)
|
||||||
|
$link .= '&days[]=' . $day;
|
||||||
|
foreach ($_SESSION['user_shifts']['types'] as $type)
|
||||||
|
$link .= '&types[]=' . $type;
|
||||||
|
foreach ($_SESSION['user_shifts']['filled'] as $filled)
|
||||||
|
$link .= '&filled[]=' . $filled;
|
||||||
|
return page_link_to_absolute('ical') . $link . '&export=user_shifts&key=' . $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_ids_from_array($array) {
|
function get_ids_from_array($array) {
|
||||||
|
@ -319,16 +362,16 @@ function get_ids_from_array($array) {
|
||||||
|
|
||||||
function make_select($items, $selected, $name, $title = null) {
|
function make_select($items, $selected, $name, $title = null) {
|
||||||
$html_items = array ();
|
$html_items = array ();
|
||||||
if(isset($title))
|
if (isset ($title))
|
||||||
$html_items[] = '<li class="heading">' . $title . '</li>' . "\n";
|
$html_items[] = '<li class="heading">' . $title . '</li>' . "\n";
|
||||||
|
|
||||||
foreach ($items as $i)
|
foreach ($items as $i)
|
||||||
$html_items[] = '<li><label><input type="checkbox" name="' . $name . '[]" value="' . $i['id'] . '"' . (in_array($i['id'], $selected)? ' checked="checked"' : '') . '> ' . $i['name'] . '</label></li>';
|
$html_items[] = '<li><label><input type="checkbox" name="' . $name . '[]" value="' . $i['id'] . '"' . (in_array($i['id'], $selected) ? ' checked="checked"' : '') . '> ' . $i['name'] . '</label></li>';
|
||||||
$html = '<div class="selection ' . $name . '">' . "\n";
|
$html = '<div class="selection ' . $name . '">' . "\n";
|
||||||
$html .= '<ul id="selection_' . $name . '">' . "\n";
|
$html .= '<ul id="selection_' . $name . '">' . "\n";
|
||||||
$html .= implode("\n", $html_items);
|
$html .= implode("\n", $html_items);
|
||||||
$html .= '</ul>' . "\n";
|
$html .= '</ul>' . "\n";
|
||||||
$html .= buttons(array(
|
$html .= buttons(array (
|
||||||
button("javascript: check_all('selection_" . $name . "')", "Alle", ""),
|
button("javascript: check_all('selection_" . $name . "')", "Alle", ""),
|
||||||
button("javascript: uncheck_all('selection_" . $name . "')", "Keine", "")
|
button("javascript: uncheck_all('selection_" . $name . "')", "Keine", "")
|
||||||
));
|
));
|
||||||
|
|
|
@ -19,6 +19,11 @@ $tshirt_sizes = array (
|
||||||
'XL-G' => "XL Girl"
|
'XL-G' => "XL Girl"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function user_reset_ical_key($user) {
|
||||||
|
$user['ical_key'] = md5($user['Nick'] . time() . rand());
|
||||||
|
sql_query("UPDATE `User` SET `ical_key`='" . sql_escape($user['ical_key']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "' LIMIT 1");
|
||||||
|
}
|
||||||
|
|
||||||
function UID2Nick($UID) {
|
function UID2Nick($UID) {
|
||||||
if ($UID > 0)
|
if ($UID > 0)
|
||||||
$SQL = "SELECT Nick FROM `User` WHERE UID='" . sql_escape($UID) . "'";
|
$SQL = "SELECT Nick FROM `User` WHERE UID='" . sql_escape($UID) . "'";
|
||||||
|
|
|
@ -165,7 +165,7 @@ elseif ($p == "faq") {
|
||||||
$content = Get_Text("no_access_text");
|
$content = Get_Text("no_access_text");
|
||||||
} else {
|
} else {
|
||||||
// Sonst zur Loginseite leiten
|
// Sonst zur Loginseite leiten
|
||||||
header("Location: " . page_link_to("login"));
|
redirect(page_link_to("login"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,3 +24,9 @@
|
||||||
%shifts_table%
|
%shifts_table%
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<h2>iCal Export</h2>
|
||||||
|
<p>
|
||||||
|
Zum abonnieren in Deiner Kalender-Software benutze folgenden öffentlichen Link (daher bitte geheimhalten, im Notfall Deinen <a href="%reset_link%">Key zurücksetzen</a>):
|
||||||
|
<br/>
|
||||||
|
<a href="%ical_link%">%ical_link%</a>
|
||||||
|
</p>
|
||||||
|
|
Loading…
Reference in New Issue