Files
thetool/Layout/default/Calendar/Index.php
Daniel Spitzer 363dbd5436 Kalenderupdate
* Komplette Verwaltung von Kalender Rechte von internen und externen Mitarbeiteren
2025-10-05 17:36:42 +02:00

612 lines
28 KiB
PHP

<?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/header.php"); ?>
<link href="<?= self::getResourcePath() ?>assets/css/datatables-std.css?<?= date('U') ?>" rel="stylesheet"
type="text/css"/>
<div class="row">
<div class="col-12">
<div class="page-title-box">
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="<?= self::getUrl("Dashboard") ?>"><?= MFAPPNAME_SLUG ?></a>
</li>
<li class="breadcrumb-item active">Kalender Verwaltung</li>
</ol>
</div>
<h4 class="page-title">Kalender Verwaltung</h4>
</div>
</div>
</div>
<div class="card">
<div class="card-body mb-3">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a
class="nav-link active"
id="home-tab"
data-toggle="tab"
href="#home"
role="tab"
aria-controls="home"
aria-selected="true"
>Vorlagen</a>
</li>
<li class="nav-item">
<a
class="nav-link"
id="profile-tab"
data-toggle="tab"
href="#user-tab"
role="tab"
aria-controls="user-tab"
aria-selected="false"
>Benutzer</a>
</li>
</ul>
<!-- Tab Inhalte -->
<div class="tab-content" id="myTabContent">
<div
class="tab-pane fade show active"
id="home"
role="tabpanel"
aria-labelledby="home-tab"
>
<div class="row">
<div class="col-12">
<a class="btn btn-primary mb-2 float-right"
href="<?= self::getUrl("CalendarTemplate", "add") ?>"><i
class="fas fa-plus"></i> Neuen Vorlage anlegen</a>
</div>
</div>
<table id="datatable2" class="table table-striped table-hover table-sm">
<thead>
<tr>
<th class="text-center">Termintyp</th>
<th class="text-center">Vorlagen Name</th>
<th class="text-center">Reminder</th>
<th class="text-center">Vorlagen Text</th>
<th class="edit-width"></th>
</tr>
<tr id="filterrow2">
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($calendartemplates as $calendartemplate): ?>
<tr>
<td class="text-center"><?= $calendarTemplateEventTypes[$calendartemplate->event_type] ?></td>
<td><?= $calendartemplate->name ?></td>
<td class="text-center"><?= ($calendartemplate->is_reminder) ? 'Ja' : 'Nein' ?></td>
<td><?= $calendartemplate->text ?></td>
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
<a href="<?= self::getUrl("CalendarTemplate", "edit", ["id" => $calendartemplate->id]) ?>"><i
class="far fa-edit" title="Bearbeiten"></i></a>
<a href="<?= self::getUrl("CalendarTemplate", "delete", ["id" => $calendartemplate->id]) ?>"
onclick="if(!confirm('Vorlage wirklich löschen?')) return false;" class="text-danger"
title="Löschen"><i class="fas fa-trash"></i></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<div
class="tab-pane fade col-12"
id="user-tab"
role="tabpanel"
aria-labelledby="profile-tab"
>
<div class="row">
<div class="col-12">
<a class="btn btn-primary mb-2 float-right"
href="<?= self::getUrl("Calendar", "add") ?>"><i
class="fas fa-plus"></i> Neuen Benutzer anlegen</a>
</div>
</div>
<table id="datatable" class="table table-striped table-hover table-sm" style="width:100%">
<thead>
<tr>
<th class="text-center">Name</th>
<th class="text-center">GO Kalender ID</th>
<th class="text-center">Microsoft Id</th>
<th class="text-center">Kalenderrechte</th>
<th class="text-center">Webhook</th>
<th class="text-center">Webhook Timeout</th>
<th class="text-center">Aktiv</th>
<th class="text-center">Admin</th>
<th class="edit-width" style="width: 50px !important;text-decoration: underline"></th>
</tr>
<tr id="filterrow">
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($calendars as $calendar):
// ÄNDERUNG: Rechte zusammenfassen mit korrektem Array-Zugriff
$calenadarRights = json_decode($calendar->rights, true);
$rightsTooltip = "";
$readCount = 0;
$allCount = 0;
if (is_array($calenadarRights)) {
foreach ($calenadarRights as $key => $value) {
if ($key != $calendar->go_calendar_id) {
// Zähle read und all
if ($value == 'read') {
$readCount++;
} elseif ($value == 'all') {
$allCount++;
}
// Baue Tooltip-Text - nutze calendarsById für Zugriff
$calName = "Unbekannt";
if (isset($calendarsById[$key])) { // Sucht nach go_calendar_id = $key
if ($calendarsById[$key]->user_id && ($calendarsById[$key]->user->name)) {
$calName = $calendarsById[$key]->user->name;
} elseif ($calendarsById[$key]->calendar_name) {
$calName = $calendarsById[$key]->calendar_name;
}
}
$rightsTooltip .= $calName . ": " . $value . "&#10;";
}
}
}
// Kompakte Anzeige: "X read, Y all"
$rightsSummary = "";
if ($readCount > 0) {
$rightsSummary .= $readCount . " read";
}
if ($allCount > 0) {
if ($rightsSummary) $rightsSummary .= ", ";
$rightsSummary .= $allCount . " all";
}
if (!$rightsSummary) {
$rightsSummary = "keine";
}
?>
<tr>
<td>
<?= $calendar->user_id ? $calendar->user->name : $calendar->calendar_name ?>
<?php if ($calendar->user_id): ?>
<span class="badge badge-success badge-sm ml-1">Mitarbeiter</span>
<?php else: ?>
<span class="badge badge-info badge-sm ml-1">Extern</span>
<?php endif; ?>
</td>
<td class="text-center"><?= $calendar->go_calendar_id ?></td>
<td class="text-nowrap"><?= $calendar->microsoft_id ?></td>
<td class="text-center">
<?php
// Erstelle HTML für Popover-Inhalt
$popoverContent = '<div class="p-2">';
if ($readCount > 0 || $allCount > 0) {
$popoverContent .= '<table class="table table-sm table-borderless mb-0" style="font-size: 0.85rem;">';
$popoverContent .= '<thead><tr><th>Kalender</th><th class="text-center">Recht</th></tr></thead><tbody>';
// Sortiere nach Namen für bessere Übersicht
$sortedRights = [];
foreach ($calenadarRights as $key => $value) {
if ($key != $calendar->go_calendar_id) {
$calName = "Unbekannt";
if (isset($calendarsById[$key])) {
if ($calendarsById[$key]->user_id && ($calendarsById[$key]->user) && ($calendarsById[$key]->user->name)) {
$calName = $calendarsById[$key]->user->name;
} elseif (isset($calendarsById[$key]->calendar_name)) {
$calName = $calendarsById[$key]->calendar_name;
}
}
$sortedRights[$calName] = $value;
}
}
ksort($sortedRights);
foreach ($sortedRights as $name => $right) {
$badgeClass = ($right == 'all') ? 'badge-success' : 'badge-info';
$badgeText = ($right == 'all') ? 'Alle Rechte' : 'Lesen';
$popoverContent .= '<tr>';
$popoverContent .= '<td class="pt-1 pb-0 text-left">' . htmlspecialchars($name) . '</td>';
$popoverContent .= '<td class="text-center pt-1 pb-0"><span class="badge ' . $badgeClass . ' badge-sm">' . $badgeText . '</span></td>';
$popoverContent .= '</tr>';
}
$popoverContent .= '</tbody></table>';
} else {
$popoverContent .= '<em class="text-muted">Keine Rechte vergeben</em>';
}
$popoverContent .= '</div>';
$popoverContentEscaped = htmlspecialchars($popoverContent, ENT_QUOTES, 'UTF-8');
?>
<span class="badge badge-primary calendar-rights-badge"
style="cursor: help; position: relative;">
<i class="fas fa-shield-alt mr-1"></i><?= $rightsSummary ?>
<div class="rights-tooltip" style="display: none; position: absolute; z-index: 10000; background: white; border: 1px solid #ccc; border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); min-width: 300px; max-width: 400px; left: auto; right: 100%; top: 50%; transform: translateY(-50%); margin-right: 10px; padding: 0;">
<div style="background: #f8f9fa; border-bottom: 1px solid #dee2e6; padding: 8px 12px; border-radius: 6px 6px 0 0;">
<strong style="font-size: 0.9rem; color: #212523">Kalenderrechte</strong>
</div>
<?= $popoverContent ?>
</div>
</span>
</td>
<td class="text-nowrap"><?= $calendar->subscription_id ?></td>
<td class="text-center"><?= ($calendar->expirationDateTime) ? date("d.m.Y H:i", $calendar->expirationDateTime) : '' ?></td>
<td class="text-center"><?= ($calendar->active == 1) ? '<i class="fa-regular fa-circle-check mr-1"></i>' : '<i class="fa-regular fa-circle-xmark mr-1"></i>' ?></td>
<td class="text-center">
<?php if ($calendar->calendar_admin == 1): ?>
<span class="badge badge-danger" title="Bekommt automatisch 'all'-Rechte auf neue Benutzer">
<i class="fas fa-user-shield mr-1"></i>Admin
</span>
<?php endif; ?>
</td>
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
<a href="<?= self::getUrl("Calendar", "edit", ["id" => $calendar->id]) ?>"><i
class="far fa-edit" title="Bearbeiten"></i></a>
<?php if (!$calendar->user_id): ?>
<a href="<?= self::getUrl("Calendar", "delete", ["id" => $calendar->id]) ?>"
onclick="if(!confirm('Kalender Benutzer wirklich löschen?')) return false;" class="text-danger"
title="Löschen"><i class="fas fa-trash"></i></a>
<?php endif; ?>
</td>
</tr>
<?php
endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<script type="text/javascript">
let table;
let table2;
let tableInitialized = false;
var hidesearch = [4];
if (typeof hidesearch === "undefined") {
var hidesearch;
hidesearch = [100];
}
if (typeof pageLength === "undefined") {
var pageLength;
pageLength = 25;
}
if (typeof cstmdom === "undefined") {
var cstmdom;
cstmdom = "flBrtip";
}
if (typeof columndefs === "undefined") {
var columndefs;
columndefs = "";
}
if (typeof columnfilter === "undefined") {
var columnfilter;
columnfilter = "";
}
if (typeof columnoptions === "undefined") {
var columnoptions;
columnoptions = "";
}
$('#filterrow2 th').each(function (i) {
let title = $('#datatable2 thead th').eq($(this).index()).text();
if (hidesearch.includes($(this).index())) {
} else if (columnfilter.includes($(this).index())) {
$(this).html('<select style="padding: 0;height: 28px;;text-align: center;" id="selectsearch" class="form-control form-control-select form-control-special" data-index="' + i + '">' + columnoptions + '</select>');
} else {
$(this).html('<input type="text" placeholder="' + title + '" class="form-control" data-index="' + i + '" value="" />');
}
});
table2 = $('#datatable2').DataTable({
responsive: {
breakpoints: [
{name: 'desktop', width: Infinity},
{name: 'tablet', width: 1024},
{name: 'fablet', width: 768},
{name: 'phone', width: 480}
]
},
pageLength: pageLength,
buttons: [
{
extend: 'excelHtml5',
text: 'XLSX Export',
className: 'btn-success margina d-none d-lg-block',
exportOptions: {
columns: ['th:not(:last-child)'],
format: {
body: function (data, row, column, node) {
data = $('<p>' + data + '</p>').text();
return $.isNumeric(data.replace(',', '.')) ? data.replace(',', '.') : data;
}
}
}
}
], columnDefs: [
columndefs
],
"language": {
"url": "/datatables/json/german.json?v1"
},
orderCellsTop: true,
stateSave: true,
stateDuration: 60 * 60 * 24 * 30,
"initComplete": function () {
$('#datatable2_filter').append('<i id="clear_cookie2" class="fas fa-times clear-fa" title="Filter löschen" aria-hidden="true" ></i>');
$('#clear_cookie2').click(function () {
$('#filterrow2 input').val('');
$('#filterrow2 select').val('');
table2.search('').columns().search('').draw();
});
$('.calendar-rights-badge').each(function() {
var content = $(this).attr('data-popover-content');
$(this).popover({
container: 'body',
html: true,
trigger: 'hover focus',
placement: 'left',
title: 'Kalenderrechte',
content: content
});
});
},
"dom": cstmdom
});
$('#filterrow2').on('keyup', 'input', function () {
table2
.column($(this).data('index'))
.search(this.value)
.draw();
});
$('#selectsearch').change(function () {
table2
.column($(this).data('index'))
.search(this.value)
.draw();
});
let state2 = table2.state.loaded();
if (state2) {
table2.columns().eq(0).each(function (colIdx) {
var colSearch = state2.columns[colIdx].search;
if (colSearch.search) {
$('#filterrow2').find("[data-index='" + colIdx + "']").val(colSearch.search);
}
});
table2.draw();
}
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
var target = $(e.target).attr("href"); // z.B. #table
if (target === '#user-tab' && !tableInitialized) {
// Initialisierung der DataTable
var hidesearch = [6, 7, 8];
if (typeof hidesearch === "undefined") {
var hidesearch;
hidesearch = [100];
}
console.log(hidesearch);
if (typeof pageLength === "undefined") {
var pageLength;
pageLength = 25;
}
if (typeof cstmdom === "undefined") {
var cstmdom;
cstmdom = "flBrtip";
}
if (typeof columndefs === "undefined") {
var columndefs;
columndefs = "";
}
if (typeof columnfilter === "undefined") {
var columnfilter;
columnfilter = "";
}
if (typeof columnoptions === "undefined") {
var columnoptions;
columnoptions = "";
}
$('#filterrow th').each(function (i) {
let title = $('#datatable thead th').eq($(this).index()).text();
if (hidesearch.includes($(this).index())) {
} else if (columnfilter.includes($(this).index())) {
$(this).html('<select style="padding: 0;height: 28px;;text-align: center;" id="selectsearch" class="form-control form-control-select form-control-special" data-index="' + i + '">' + columnoptions + '</select>');
} else {
$(this).html('<input type="text" placeholder="' + title + '" class="form-control" data-index="' + i + '" value="" />');
}
});
table = $('#datatable').DataTable({
responsive: {
breakpoints: [
{name: 'desktop', width: Infinity},
{name: 'tablet', width: 1024},
{name: 'fablet', width: 768},
{name: 'phone', width: 480}
]
},
pageLength: pageLength,
buttons: [
{
extend: 'excelHtml5',
text: 'XLSX Export',
className: 'btn-success margina d-none d-lg-block',
exportOptions: {
columns: ['th:not(:last-child)'],
format: {
body: function (data, row, column, node) {
data = $('<p>' + data + '</p>').text();
return $.isNumeric(data.replace(',', '.')) ? data.replace(',', '.') : data;
}
}
}
}
], columnDefs: [
columndefs
],
"language": {
"url": "/datatables/json/german.json?v1"
},
orderCellsTop: true,
stateSave: true,
stateDuration: 60 * 60 * 24 * 30,
"initComplete": function () {
$('#datatable_filter').append('<i id="clear_cookie" class="fas fa-times clear-fa" title="Filter löschen" aria-hidden="true" ></i>');
$('#clear_cookie').click(function () {
$('#filterrow input').val('');
$('#filterrow select').val('');
table.search('').columns().search('').draw();
});
$('.calendar-rights-badge').each(function() {
var content = $(this).attr('data-popover-content');
$(this).popover({
container: 'body',
html: true,
trigger: 'hover focus',
placement: 'left',
title: 'Kalenderrechte',
content: content
});
});
},
"dom": cstmdom
});
$('#filterrow').on('keyup', 'input', function () {
table
.column($(this).data('index'))
.search(this.value)
.draw();
});
$('#selectsearch').change(function () {
table
.column($(this).data('index'))
.search(this.value)
.draw();
});
let state = table.state.loaded();
if (state) {
table.columns().eq(0).each(function (colIdx) {
var colSearch = state.columns[colIdx].search;
if (colSearch.search) {
$('#filterrow').find("[data-index='" + colIdx + "']").val(colSearch.search);
}
});
table.draw();
}
tableInitialized = true;
} else if (target === '#table' && tableInitialized) {
table.columns.adjust().responsive.recalc();
}
});
$(document).ready(function() {
var tooltipTimer;
$(document).on('mouseenter', '.calendar-rights-badge', function() {
var $tooltip = $(this).find('.rights-tooltip');
clearTimeout(tooltipTimer);
// Verstecke alle anderen Tooltips
$('.rights-tooltip').not($tooltip).stop(true, true).fadeOut(150);
// Zeige diesen Tooltip
$tooltip.stop(true, true).fadeIn(250);
});
$(document).on('mouseleave', '.calendar-rights-badge', function() {
var $tooltip = $(this).find('.rights-tooltip');
// Verzögertes Ausblenden
tooltipTimer = setTimeout(function() {
$tooltip.stop(true, true).fadeOut(200);
}, 100);
});
// Verhindere dass Tooltip verschwindet wenn man drüber hovert
$(document).on('mouseenter', '.rights-tooltip', function() {
clearTimeout(tooltipTimer);
$(this).stop(true, true).show();
});
$(document).on('mouseleave', '.rights-tooltip', function() {
var $this = $(this);
tooltipTimer = setTimeout(function() {
$this.stop(true, true).fadeOut(200);
}, 100);
});
$('[data-toggle="popover"]').popover({
container: 'body',
html: true,
trigger: 'hover focus',
placement: 'left'
});
var activeTab = localStorage.getItem('calendarActiveTab');
if (activeTab) {
$('.nav-tabs a[href="' + activeTab + '"]').tab('show');
}
// Tab-Wechsel speichern
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
var activeTab = $(e.target).attr('href');
localStorage.setItem('calendarActiveTab', activeTab);
});
});
</script>
<!--script type="text/javascript"
src="<?= self::getResourcePath() ?>assets/js/datatables-std.js?<?= date('U') ?>"></script-->
<?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/footer.php"); ?>