v1.3.2 - Farbvorgabe angepasst

This commit is contained in:
Borgal
2026-02-02 12:10:30 +01:00
parent 2a96df9381
commit 63ed57d009
3 changed files with 74 additions and 50 deletions

View File

@@ -97,7 +97,7 @@ $result = mysqli_query($conn, "
c.is_special,
COUNT(m.id) AS usage_count
FROM colors c
LEFT JOIN meetings m ON c.id = m.color_id
LEFT JOIN meetings m ON c.id = m.color_id AND m.is_skipped = 0
GROUP BY c.id, c.name, c.hex_code, c.is_special
ORDER BY $order_by
");

View File

@@ -64,6 +64,7 @@ function get_current_meeting($conn)
$sql = "SELECT id, meeting_date, color_id, reason
FROM meetings
WHERE is_completed = 0
AND is_skipped = 0
ORDER BY meeting_date ASC
LIMIT 1";
$result = mysqli_query($conn, $sql);

View File

@@ -9,18 +9,18 @@ $message_type = '';
$edit_mode = false;
$edit_meeting = null;
// --- Funktion: Zufallsfarbe mit inverser Gewichtung (alle Termine, keine Sonderfarben) ---
// --- Funktion: Zufallsfarbe mit inverser Gewichtung OHNE übersprungene Termine ---
function get_weighted_random_color($conn)
{
// Zählt ALLE Termine (vergangen + geplant) für jede reguläre Farbe
$colors = [];
// 🔥 Wichtig: Nur nicht-übersprungene Termine zählen
$result = mysqli_query($conn, "
SELECT
c.id,
c.name,
COUNT(m.id) AS usage_count
FROM colors c
LEFT JOIN meetings m ON c.id = m.color_id
LEFT JOIN meetings m ON c.id = m.color_id AND m.is_skipped = 0
WHERE c.is_special = 0
GROUP BY c.id, c.name
");
@@ -73,7 +73,8 @@ if ($is_admin && isset($_GET['action']) && $_GET['action'] == 'delete' && isset(
// --- Nur Admins: Bearbeiten ---
if ($is_admin && isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
$id = (int)$_GET['id'];
$stmt = mysqli_prepare($conn, "SELECT id, meeting_date, color_id, reason FROM meetings WHERE id = ?");
// 🔥 is_skipped mit abfragen
$stmt = mysqli_prepare($conn, "SELECT id, meeting_date, color_id, reason, is_skipped FROM meetings WHERE id = ?");
mysqli_stmt_bind_param($stmt, "i", $id);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
@@ -98,6 +99,7 @@ if ($is_admin && $_SERVER["REQUEST_METHOD"] == "POST") {
$color_id = (int)($_POST['color_id'] ?? 0);
$reason = trim($_POST['reason'] ?? 'Zufallsfarbe');
$id = !empty($_POST['id']) ? (int)$_POST['id'] : null;
$is_skipped = !empty($_POST['is_skipped']) ? 1 : 0;
if (empty($meeting_date_only) || !$color_id) {
$message = "Datum und Farbe sind erforderlich.";
@@ -105,11 +107,11 @@ if ($is_admin && $_SERVER["REQUEST_METHOD"] == "POST") {
} else {
$meeting_date = $meeting_date_only . ' ' . $meeting_time_only;
if ($id) {
$stmt = mysqli_prepare($conn, "UPDATE meetings SET meeting_date = ?, color_id = ?, reason = ? WHERE id = ?");
mysqli_stmt_bind_param($stmt, "sisi", $meeting_date, $color_id, $reason, $id);
$stmt = mysqli_prepare($conn, "UPDATE meetings SET meeting_date = ?, color_id = ?, reason = ?, is_skipped = ? WHERE id = ?");
mysqli_stmt_bind_param($stmt, "sisis", $meeting_date, $color_id, $reason, $is_skipped, $id);
} else {
$stmt = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason) VALUES (?, ?, ?)");
mysqli_stmt_bind_param($stmt, "sis", $meeting_date, $color_id, $reason);
$stmt = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason, is_skipped) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, "sisi", $meeting_date, $color_id, $reason, $is_skipped);
}
if (mysqli_stmt_execute($stmt)) {
@@ -125,20 +127,21 @@ if ($is_admin && $_SERVER["REQUEST_METHOD"] == "POST") {
}
}
// --- 🔁 Automatische Planung: 4 Donnerstage, max. 1 pro Woche ---
if ($is_admin) {
$today = new DateTime('today');
$existing_weeks = [];
$result_existing = mysqli_query($conn, "SELECT meeting_date FROM meetings");
while ($row = mysqli_fetch_assoc($result_existing)) {
// --- 🔁 Automatische Planung: 4 Donnerstage, max. 1 pro Woche für ALLE Nutzer ---
$today = new DateTime('today');
// Nur nicht-übersprungene Termine zählen
$existing_weeks = [];
$result_existing = mysqli_query($conn, "SELECT meeting_date FROM meetings WHERE is_skipped = 0");
while ($row = mysqli_fetch_assoc($result_existing)) {
$dt = new DateTime($row['meeting_date']);
$year = $dt->format('o');
$week = $dt->format('W');
$existing_weeks["$year-$week"] = true;
}
}
$date = clone $today;
for ($i = 0; $i < 4; $i++) {
$date = clone $today;
for ($i = 0; $i < 4; $i++) {
$date->modify($i === 0 ? 'next thursday' : 'next thursday');
$year = $date->format('o');
$week = $date->format('W');
@@ -148,6 +151,7 @@ if ($is_admin) {
$new_date = $date->format('Y-m-d') . ' 12:00:00';
$color_id = get_weighted_random_color($conn);
if ($color_id) {
// Prüfen, ob überhaupt ein Termin (auch übersprungener) existiert → keine Duplikate
$check = mysqli_prepare($conn, "SELECT id FROM meetings WHERE meeting_date = ?");
mysqli_stmt_bind_param($check, "s", $new_date);
mysqli_stmt_execute($check);
@@ -156,7 +160,7 @@ if ($is_admin) {
if (!$exists) {
$default_reason = "Zufallsfarbe";
$ins = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason) VALUES (?, ?, ?)");
$ins = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason, is_skipped) VALUES (?, ?, ?, 0)");
mysqli_stmt_bind_param($ins, "sis", $new_date, $color_id, $default_reason);
mysqli_stmt_execute($ins);
mysqli_stmt_close($ins);
@@ -164,7 +168,6 @@ if ($is_admin) {
}
}
}
}
}
// --- Daten für Anzeige laden ---
@@ -176,9 +179,10 @@ if ($is_admin) {
}
}
// 🔥 Alle Termine laden (auch übersprungene), für alle Nutzer
$meetings = [];
$result_meetings = mysqli_query($conn, "
SELECT m.id, m.meeting_date, m.reason, c.name AS color_name, c.hex_code
SELECT m.id, m.meeting_date, m.reason, m.is_skipped, c.name AS color_name, c.hex_code
FROM meetings m
JOIN colors c ON m.color_id = c.id
WHERE m.is_completed = 0
@@ -227,7 +231,7 @@ require_once 'inc/header.php';
<label class="form-label">Farbe</label>
<select class="form-select" name="color_id" required>
<?php foreach ($all_colors as $color): ?>
<option value="<?= $color['id'] ?>" <?= (($edit_meeting['color_id'] ?? 0) == $color['id']) ? 'selected' : '' ?>>
<option value="<?= (int)$color['id'] ?>" <?= (($edit_meeting['color_id'] ?? 0) == $color['id']) ? 'selected' : '' ?>>
<?= htmlspecialchars($color['name']) ?>
</option>
<?php endforeach; ?>
@@ -238,6 +242,15 @@ require_once 'inc/header.php';
<input type="text" class="form-control" name="reason" value="<?= htmlspecialchars($edit_meeting['reason'] ?? ''); ?>">
<div class="form-text">Wenn leer, wird „Zufallsfarbe“ eingetragen.</div>
</div>
<div class="col-12">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="is_skipped" name="is_skipped" value="1"
<?= (!empty($edit_meeting['is_skipped'])) ? 'checked' : '' ?>>
<label class="form-check-label" for="is_skipped">
Termin bewusst aussetzen (wird in Grau angezeigt und nicht für Farbstatistik genutzt)
</label>
</div>
</div>
<div class="col-12 d-flex justify-content-start">
<button type="submit" class="btn btn-sm btn-outline-<?= $edit_mode ? 'success' : 'primary' ?> me-2">
<?= $edit_mode ? 'Speichern' : 'Hinzufügen' ?>
@@ -266,12 +279,22 @@ require_once 'inc/header.php';
<?php else: ?>
<div class="list-group list-group-flush">
<?php foreach ($meetings as $m): ?>
<div class="list-group-item">
<?php
$is_skipped = (bool)$m['is_skipped'];
$date_str = date('d.m.Y H:i', strtotime($m['meeting_date']));
?>
<div class="list-group-item <?= $is_skipped ? 'opacity-75' : '' ?>">
<div class="d-flex justify-content-between align-items-start">
<div>
<p class="fw-bold mb-1"><?= date('d.m.Y H:i', strtotime($m['meeting_date'])) ?></p>
<p class="fw-bold mb-1 <?= $is_skipped ? 'text-muted text-decoration-line-through' : '' ?>">
<?= htmlspecialchars($date_str) ?>
<?php if ($is_skipped): ?>
<span class="badge bg-light text-dark ms-2">übersprungen</span>
<?php endif; ?>
</p>
<div class="d-flex align-items-center mb-1">
<div class="me-2" style="background-color: <?= htmlspecialchars($m['hex_code']); ?>; width: 20px; height: 20px; border: 1px solid #ccc; border-radius: 2px;"></div> <span><?= htmlspecialchars($m['color_name']); ?></span>
<div class="me-2" style="background-color: <?= htmlspecialchars($m['hex_code']); ?>; width: 20px; height: 20px; border: 1px solid #ccc; border-radius: 2px;"></div>
<span><?= htmlspecialchars($m['color_name']); ?></span>
</div>
<p class="text-muted small mb-0">Grund: <?= htmlspecialchars($m['reason']); ?></p>
</div>
@@ -282,12 +305,12 @@ require_once 'inc/header.php';
</a>
<ul class="dropdown-menu dropdown-menu-end">
<li>
<a class="dropdown-item d-flex align-items-center" href="planning.php?action=edit&id=<?= $m['id'] ?>">
<a class="dropdown-item d-flex align-items-center" href="planning.php?action=edit&id=<?= (int)$m['id'] ?>">
<span class="material-icons me-2">mode_edit_outline</span> Bearbeiten
</a>
</li>
<li>
<a class="dropdown-item d-flex align-items-center text-danger" href="planning.php?action=delete&id=<?= $m['id'] ?>" onclick="return confirm('Wirklich löschen?')">
<a class="dropdown-item d-flex align-items-center text-danger" href="planning.php?action=delete&id=<?= (int)$m['id'] ?>" onclick="return confirm('Wirklich löschen?')">
<span class="material-icons me-2">delete_outline</span> Löschen
</a>
</li>