Fix Calendar Loading Problems

This commit is contained in:
2025-12-18 19:00:05 +01:00
parent afadbbc835
commit bbe05bd765
3 changed files with 228 additions and 177 deletions
+100 -71
View File
@@ -1,33 +1,40 @@
<?php
$events = collection('termine');
if ($events === null): ?>
<div class="container mx-auto py-8">
<h2>Bevorstehende Termine</h2>
<div class="text-red-600">Die Termine können gerade nicht geladen werden.</div>
</div>
<?php return; endif;
// Aktuelles Datum - PHP 8.3 kompatibel
$today = (new DateTime('now'))->format('Ymd');
// Nur zukünftige Termine anzeigen
$future_events = array_filter($events, function ($event) use ($today) {
return isset($event['DTSTART']) && $event['DTSTART'] >= $today;
return isset($event['DTSTART']) && $event['DTSTART'] >= $today;
});
// Termine nach DTSTART in aufsteigender Reihenfolge sortieren
usort($future_events, function ($a, $b) {
return $a['DTSTART'] <=> $b['DTSTART'];
return $a['DTSTART'] <=> $b['DTSTART'];
});
// --- Deutsche Monatsnamen ---
$de_months = [
'01' => 'Jan',
'02' => 'Feb',
'03' => 'Mrz',
'04' => 'Apr',
'05' => 'Mai',
'06' => 'Jun',
'07' => 'Jul',
'08' => 'Aug',
'09' => 'Sep',
'10' => 'Okt',
'11' => 'Nov',
'12' => 'Dez',
'01' => 'Jan',
'02' => 'Feb',
'03' => 'Mrz',
'04' => 'Apr',
'05' => 'Mai',
'06' => 'Jun',
'07' => 'Jul',
'08' => 'Aug',
'09' => 'Sep',
'10' => 'Okt',
'11' => 'Nov',
'12' => 'Dez',
];
?>
@@ -35,8 +42,12 @@ $de_months = [
<h2>Bevorstehende Termine</h2>
<div class="relative flex items-center justify-center">
<button id="scroll-left" class="flex-shrink-0 bg-white p-3 rounded-full shadow-lg hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500 z-10 hidden md:block mr-4">
<svg class="w-6 h-6 text-gray-700" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path></svg>
<button id="scroll-left"
class="flex-shrink-0 bg-white p-3 rounded-full shadow-lg hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500 z-10 hidden md:block mr-4">
<svg class="w-6 h-6 text-gray-700" fill="none" stroke="currentColor" viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path>
</svg>
</button>
<div id="termine-wrapper" class="relative w-full max-w-7xl overflow-hidden">
@@ -49,18 +60,18 @@ $de_months = [
$location = $event['LOCATION'] ?? '';
$desc = $event['DESCRIPTION'] ?? '';
$timezone = $event['DTSTART_TZID'] ?? null;
// Sichere Funktionsaufrufe mit Null-Checks
$date_info = function_exists('format_ics_date_with_timezone')
? format_ics_date_with_timezone($start, $timezone)
$date_info = function_exists('format_ics_date_with_timezone')
? format_ics_date_with_timezone($start, $timezone)
: ['display' => '', 'has_time' => false, 'iso' => ''];
$date = $date_info['display'] ?? '';
$time = ($date_info['has_time'] ?? false) ? substr($date, 11) : 'ganztägig';
$day = substr($date, 0, 2);
$month = substr($date, 3, 2);
$iso_date = $date_info['iso'] ?? '';
// Sichere Array-Zugriffe
$month_name = $de_months[$month] ?? 'Unbek';
$event_summary = htmlspecialchars($summary, ENT_QUOTES, 'UTF-8');
@@ -69,57 +80,64 @@ $de_months = [
$safe_time = htmlspecialchars($time, ENT_QUOTES, 'UTF-8');
?>
<div class="termine-card flex-none w-full md:w-1/2 bg-gradient-to-br from-blue-50 to-blue-100 rounded-2xl transform hover:scale-102 transition-all duration-300 ease-in-out border border-blue-200">
<!-- Inhalt der ersten Karte bleibt unverändert -->
<div class="p-6 flex flex-col h-full">
<div class="flex items-top mb-5">
<div class="relative flex-shrink-0 bg-white rounded-lg shadow-md overflow-hidden w-16 h-16 flex flex-col border border-blue-200">
<!-- Kopfzeile des Kalenders mit Monat -->
<div class="bg-blue-600 text-white text-xs font-semibold py-1 text-center uppercase">
<span data-month><?= $month_name ?></span>
</div>
<div
class="termine-card flex-none w-full md:w-1/2 bg-gradient-to-br from-blue-50 to-blue-100 rounded-2xl transform hover:scale-102 transition-all duration-300 ease-in-out border border-blue-200">
<!-- Inhalt der ersten Karte bleibt unverändert -->
<div class="p-6 flex flex-col h-full">
<div class="flex items-top mb-5">
<div
class="relative flex-shrink-0 bg-white rounded-lg shadow-md overflow-hidden w-16 h-16 flex flex-col border border-blue-200">
<!-- Kopfzeile des Kalenders mit Monat -->
<div class="bg-blue-600 text-white text-xs font-semibold py-1 text-center uppercase">
<span data-month><?= $month_name ?></span>
</div>
<!-- Datumsanzeige -->
<div class="flex-grow flex items-center justify-center">
<div class="text-3xl font-bold text-sf_grau-800" data-day><?= $safe_day ?></div>
</div>
<!-- Datumsanzeige -->
<div class="flex-grow flex items-center justify-center">
<div class="text-3xl font-bold text-sf_grau-800" data-day><?= $safe_day ?></div>
</div>
<!-- Dekorative Elemente - kleine Punkte für Kalendertage -->
<div class="absolute bottom-1 left-0 right-0 flex justify-center space-x-0.5 px-1">
<div class="w-1 h-1 rounded-full bg-sf_blau-200"></div>
<div class="w-1 h-1 rounded-full bg-sf_blau-300"></div>
<div class="w-1 h-1 rounded-full bg-sf_blau-400"></div>
<div class="w-1 h-1 rounded-full bg-sf_blau-500"></div>
<div class="w-1 h-1 rounded-full bg-sf_blau-400"></div>
<div class="w-1 h-1 rounded-full bg-sf_blau-300"></div>
<div class="w-1 h-1 rounded-full bg-sf_blau-200"></div>
<!-- Dekorative Elemente - kleine Punkte für Kalendertage -->
<div class="absolute bottom-1 left-0 right-0 flex justify-center space-x-0.5 px-1">
<div class="w-1 h-1 rounded-full bg-sf_blau-200"></div>
<div class="w-1 h-1 rounded-full bg-sf_blau-300"></div>
<div class="w-1 h-1 rounded-full bg-sf_blau-400"></div>
<div class="w-1 h-1 rounded-full bg-sf_blau-500"></div>
<div class="w-1 h-1 rounded-full bg-sf_blau-400"></div>
<div class="w-1 h-1 rounded-full bg-sf_blau-300"></div>
<div class="w-1 h-1 rounded-full bg-sf_blau-200"></div>
</div>
</div>
<div class="ml-5 flex-grow">
<p class="text-xl font-medium text-sf_grau-900"><?= $event_summary ?></p>
<p class="text-sf_blau-700 text-lg font-medium mt-1">
<?php if ($date_info['has_time'] ?? false): ?>
ab <span class="local-time"
data-iso-date="<?= $safe_iso_date ?>"><?= $safe_time ?></span> Uhr
<?php else: ?>
ganztägig
<?php endif; ?>
</p>
</div>
</div>
<div class="ml-5 flex-grow">
<p class="text-xl font-medium text-sf_grau-900"><?= $event_summary ?></p>
<p class="text-sf_blau-700 text-lg font-medium mt-1">
<?php if ($date_info['has_time'] ?? false): ?>
ab <span class="local-time" data-iso-date="<?= $safe_iso_date ?>"><?= $safe_time ?></span> Uhr
<?php else: ?>
ganztägig
<?php endif; ?>
</p>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<button id="scroll-right" class="flex-shrink-0 bg-white p-3 rounded-full shadow-lg hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500 z-10 hidden md:block ml-4">
<svg class="w-6 h-6 text-gray-700" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path></svg>
<button id="scroll-right"
class="flex-shrink-0 bg-white p-3 rounded-full shadow-lg hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500 z-10 hidden md:block ml-4">
<svg class="w-6 h-6 text-gray-700" fill="none" stroke="currentColor" viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
</svg>
</button>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('DOMContentLoaded', function () {
const termineWrapper = document.getElementById('termine-wrapper');
const termineContainer = document.getElementById('termine-container');
const scrollLeftBtn = document.getElementById('scroll-left');
@@ -143,7 +161,7 @@ $de_months = [
scrollLeftBtn.classList.remove('opacity-50', 'cursor-not-allowed');
scrollLeftBtn.classList.add('hover:bg-gray-100');
}
// Rechter Pfeil deaktivieren, wenn es keine weiteren Termine gibt
if (currentPosition >= maxPosition) {
scrollRightBtn.disabled = true;
@@ -200,23 +218,23 @@ $de_months = [
// Erstelle ein Date-Objekt aus der ISO-Date
// JavaScript erkennt automatisch UTC-Zeiten (mit Z oder +00:00)
const date = new Date(isoDate);
// Prüfe ob das Datum gültig ist
if (isNaN(date.getTime())) {
console.warn('Ungültiges Datum:', isoDate);
return;
}
// Formatiere die Zeit in der lokalen Zeitzone des Browsers
const localTime = date.toLocaleTimeString('de-DE', {
hour: '2-digit',
minute: '2-digit',
hour12: false
});
// Aktualisiere den Text
element.textContent = localTime;
// Debug-Information (kann später entfernt werden)
console.log('Konvertiert:', isoDate, '->', localTime, 'in Zeitzone:', Intl.DateTimeFormat().resolvedOptions().timeZone);
} catch (error) {
@@ -250,32 +268,41 @@ $de_months = [
<style>
/* Versteckt die Scrollbar vollständig, behält aber die Scrollfunktionalität */
#termine-container {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none;
/* IE and Edge */
scrollbar-width: none;
/* Firefox */
overflow-x: visible;
}
#termine-container::-webkit-scrollbar {
display: none; /* Chrome, Safari, Opera */
display: none;
/* Chrome, Safari, Opera */
}
/* Gleiche Kartenbreiten sicherstellen */
@media (min-width: 1280px) {
.termine-card {
width: 100%; /* 100% minus 2 Gaps (2 * 24px) geteilt durch 3 */
width: 100%;
/* 100% minus 2 Gaps (2 * 24px) geteilt durch 3 */
}
#termine-container {
space-x-0; /* Kein Abstand zwischen Karten nötig */
space-x-0;
/* Kein Abstand zwischen Karten nötig */
}
}
/* Auf mobilen Geräten eine Karte anzeigen */
@media (max-width: 1280px) {
.termine-card {
width: 100%; /* Volle Breite */
width: 100%;
/* Volle Breite */
}
#termine-container {
space-x-0; /* Kein Abstand zwischen Karten nötig */
space-x-0;
/* Kein Abstand zwischen Karten nötig */
}
}
@@ -283,9 +310,11 @@ $de_months = [
.termine-card h3 {
overflow: hidden;
text-overflow: ellipsis;
/* white-space: nowrap; */ /* Diese Zeile entfernen oder kommentieren */
/* white-space: nowrap; */
/* Diese Zeile entfernen oder kommentieren */
display: -webkit-box;
-webkit-line-clamp: 2; /* Maximal 2 Zeilen anzeigen */
-webkit-line-clamp: 2;
/* Maximal 2 Zeilen anzeigen */
-webkit-box-orient: vertical;
line-height: 1.3;
}