95 lines
3.3 KiB
PHP
Executable File
95 lines
3.3 KiB
PHP
Executable File
<?php
|
|
include('inc/check_login.php');
|
|
include('inc/db.php');
|
|
|
|
// Aktuelle Kalenderwoche berechnen
|
|
$current_week = date('W');
|
|
|
|
// SQL-Abfrage mit JOIN zwischen meetings und colors
|
|
$sql = "SELECT * FROM meetings
|
|
JOIN colors ON meetings.color_id = colors.id
|
|
WHERE WEEK(meeting_date, 1) = $current_week
|
|
ORDER BY meeting_date DESC LIMIT 1";
|
|
|
|
$result = mysqli_query($conn, $sql);
|
|
if (!$result) {
|
|
die("Fehler in der SQL-Abfrage: " . mysqli_error($conn));
|
|
}
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
// Funktion, die basierend auf der Hintergrundfarbe die optimale Textfarbe zurückgibt
|
|
function get_readable_text_color($hex_code)
|
|
{
|
|
// Entferne das # falls vorhanden
|
|
$hex_code = ltrim($hex_code, '#');
|
|
|
|
// Erweitere 3-stellige Hex-Codes auf 6 Stellen
|
|
if (strlen($hex_code) == 3) {
|
|
$hex_code = $hex_code[0] . $hex_code[0] . $hex_code[1] . $hex_code[1] . $hex_code[2] . $hex_code[2];
|
|
}
|
|
|
|
// Konvertiere Hex zu RGB
|
|
$r = hexdec(substr($hex_code, 0, 2));
|
|
$g = hexdec(substr($hex_code, 2, 2));
|
|
$b = hexdec(substr($hex_code, 4, 2));
|
|
|
|
// Berechne die Luminanz (Helligkeit)
|
|
// Die menschliche Wahrnehmung von Helligkeit ist nicht linear
|
|
$luminance = (0.299 * $r + 0.587 * $g + 0.114 * $b) / 255;
|
|
|
|
// Gib Weiß (#FFFFFF) für dunkle Farben und Schwarz (#000000) für helle Farben zurück
|
|
return $luminance > 0.5 ? '#000000' : '#FFFFFF';
|
|
}
|
|
|
|
include('inc/header.php');
|
|
|
|
// Wochentags-Übersetzung
|
|
$german_weekdays = [
|
|
'Mon' => 'Mo.',
|
|
'Tue' => 'Di.',
|
|
'Wed' => 'Mi.',
|
|
'Thu' => 'Do.',
|
|
'Fri' => 'Fr.',
|
|
'Sat' => 'Sa.',
|
|
'Sun' => 'So.',
|
|
];
|
|
?>
|
|
|
|
<div class="container py-5">
|
|
<div class="text-center mb-5">
|
|
<h1 class="display-4 fw-bold">DoMiLi</h1>
|
|
<p class="lead">Farbe für Kalenderwoche <strong><?= $current_week ?></strong></p>
|
|
</div>
|
|
|
|
<?php if ($row): ?>
|
|
<?php
|
|
$english_weekday = date('D', strtotime($row['meeting_date']));
|
|
$german_weekday = $german_weekdays[$english_weekday] ?? '';
|
|
?>
|
|
<div class="card mx-auto bg-light shadow" style="max-width: 400px;">
|
|
<div class="card-body text-center">
|
|
<h5 class="card-title mb-3">Farbe der Woche</h5>
|
|
<div class="rounded mb-3 mx-auto d-flex justify-content-center align-items-center" style="height: min(100px, 25vw); background-color: <?= htmlspecialchars($row['hex_code']) ?>; text-shadow: 1px 1px 2px rgba(0,0,0,0.5);">
|
|
<p class="fs-5 fw-semibold m-0" style="color: <?= get_readable_text_color($row['hex_code']) ?>;"><?= htmlspecialchars($row['name']) ?></p>
|
|
</div>
|
|
|
|
<p class="text-muted">nächster Termin:</p>
|
|
<p class="text-muted fw-bold"><?= $german_weekday . ' ' . date('d.m.Y H:i', strtotime($row['meeting_date'])) ?></p>
|
|
</div>
|
|
<div class="d-flex justify-content-center my-3" style="max-width: 400px; margin-left: auto; margin-right: auto;">
|
|
<a href="#" class="btn btn-sm btn-outline-danger me-4">Absagen</a>
|
|
<a href="#" class="btn btn-sm btn-outline-secondary">Verschiebung beantragen</a>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<?php else: ?>
|
|
<div class="alert alert-warning text-center">
|
|
Keine Farbe für diese Woche festgelegt.
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
</div>
|
|
|
|
<?php include('inc/footer.php'); ?>
|