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, c.is_special,
COUNT(m.id) AS usage_count COUNT(m.id) AS usage_count
FROM colors c 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 GROUP BY c.id, c.name, c.hex_code, c.is_special
ORDER BY $order_by ORDER BY $order_by
"); ");

View File

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

View File

@@ -9,18 +9,18 @@ $message_type = '';
$edit_mode = false; $edit_mode = false;
$edit_meeting = null; $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) function get_weighted_random_color($conn)
{ {
// Zählt ALLE Termine (vergangen + geplant) für jede reguläre Farbe
$colors = []; $colors = [];
// 🔥 Wichtig: Nur nicht-übersprungene Termine zählen
$result = mysqli_query($conn, " $result = mysqli_query($conn, "
SELECT SELECT
c.id, c.id,
c.name, c.name,
COUNT(m.id) AS usage_count COUNT(m.id) AS usage_count
FROM colors c 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 WHERE c.is_special = 0
GROUP BY c.id, c.name GROUP BY c.id, c.name
"); ");
@@ -73,7 +73,8 @@ if ($is_admin && isset($_GET['action']) && $_GET['action'] == 'delete' && isset(
// --- Nur Admins: Bearbeiten --- // --- Nur Admins: Bearbeiten ---
if ($is_admin && isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) { if ($is_admin && isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
$id = (int)$_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_bind_param($stmt, "i", $id);
mysqli_stmt_execute($stmt); mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($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); $color_id = (int)($_POST['color_id'] ?? 0);
$reason = trim($_POST['reason'] ?? 'Zufallsfarbe'); $reason = trim($_POST['reason'] ?? 'Zufallsfarbe');
$id = !empty($_POST['id']) ? (int)$_POST['id'] : null; $id = !empty($_POST['id']) ? (int)$_POST['id'] : null;
$is_skipped = !empty($_POST['is_skipped']) ? 1 : 0;
if (empty($meeting_date_only) || !$color_id) { if (empty($meeting_date_only) || !$color_id) {
$message = "Datum und Farbe sind erforderlich."; $message = "Datum und Farbe sind erforderlich.";
@@ -105,11 +107,11 @@ if ($is_admin && $_SERVER["REQUEST_METHOD"] == "POST") {
} else { } else {
$meeting_date = $meeting_date_only . ' ' . $meeting_time_only; $meeting_date = $meeting_date_only . ' ' . $meeting_time_only;
if ($id) { if ($id) {
$stmt = mysqli_prepare($conn, "UPDATE meetings SET meeting_date = ?, color_id = ?, reason = ? WHERE id = ?"); $stmt = mysqli_prepare($conn, "UPDATE meetings SET meeting_date = ?, color_id = ?, reason = ?, is_skipped = ? WHERE id = ?");
mysqli_stmt_bind_param($stmt, "sisi", $meeting_date, $color_id, $reason, $id); mysqli_stmt_bind_param($stmt, "sisis", $meeting_date, $color_id, $reason, $is_skipped, $id);
} else { } else {
$stmt = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason) VALUES (?, ?, ?)"); $stmt = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason, is_skipped) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, "sis", $meeting_date, $color_id, $reason); mysqli_stmt_bind_param($stmt, "sisi", $meeting_date, $color_id, $reason, $is_skipped);
} }
if (mysqli_stmt_execute($stmt)) { if (mysqli_stmt_execute($stmt)) {
@@ -125,43 +127,44 @@ if ($is_admin && $_SERVER["REQUEST_METHOD"] == "POST") {
} }
} }
// --- 🔁 Automatische Planung: 4 Donnerstage, max. 1 pro Woche --- // --- 🔁 Automatische Planung: 4 Donnerstage, max. 1 pro Woche für ALLE Nutzer ---
if ($is_admin) { $today = new DateTime('today');
$today = new DateTime('today');
$existing_weeks = [];
$result_existing = mysqli_query($conn, "SELECT meeting_date FROM meetings");
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; // Nur nicht-übersprungene Termine zählen
for ($i = 0; $i < 4; $i++) { $existing_weeks = [];
$date->modify($i === 0 ? 'next thursday' : 'next thursday'); $result_existing = mysqli_query($conn, "SELECT meeting_date FROM meetings WHERE is_skipped = 0");
$year = $date->format('o'); while ($row = mysqli_fetch_assoc($result_existing)) {
$week = $date->format('W'); $dt = new DateTime($row['meeting_date']);
$week_key = "$year-$week"; $year = $dt->format('o');
$week = $dt->format('W');
$existing_weeks["$year-$week"] = true;
}
if (!isset($existing_weeks[$week_key])) { $date = clone $today;
$new_date = $date->format('Y-m-d') . ' 12:00:00'; for ($i = 0; $i < 4; $i++) {
$color_id = get_weighted_random_color($conn); $date->modify($i === 0 ? 'next thursday' : 'next thursday');
if ($color_id) { $year = $date->format('o');
$check = mysqli_prepare($conn, "SELECT id FROM meetings WHERE meeting_date = ?"); $week = $date->format('W');
mysqli_stmt_bind_param($check, "s", $new_date); $week_key = "$year-$week";
mysqli_stmt_execute($check);
$exists = mysqli_fetch_assoc(mysqli_stmt_get_result($check));
mysqli_stmt_close($check);
if (!$exists) { if (!isset($existing_weeks[$week_key])) {
$default_reason = "Zufallsfarbe"; $new_date = $date->format('Y-m-d') . ' 12:00:00';
$ins = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason) VALUES (?, ?, ?)"); $color_id = get_weighted_random_color($conn);
mysqli_stmt_bind_param($ins, "sis", $new_date, $color_id, $default_reason); if ($color_id) {
mysqli_stmt_execute($ins); // Prüfen, ob überhaupt ein Termin (auch übersprungener) existiert → keine Duplikate
mysqli_stmt_close($ins); $check = mysqli_prepare($conn, "SELECT id FROM meetings WHERE meeting_date = ?");
$existing_weeks[$week_key] = true; mysqli_stmt_bind_param($check, "s", $new_date);
} mysqli_stmt_execute($check);
$exists = mysqli_fetch_assoc(mysqli_stmt_get_result($check));
mysqli_stmt_close($check);
if (!$exists) {
$default_reason = "Zufallsfarbe";
$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);
$existing_weeks[$week_key] = true;
} }
} }
} }
@@ -176,9 +179,10 @@ if ($is_admin) {
} }
} }
// 🔥 Alle Termine laden (auch übersprungene), für alle Nutzer
$meetings = []; $meetings = [];
$result_meetings = mysqli_query($conn, " $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 FROM meetings m
JOIN colors c ON m.color_id = c.id JOIN colors c ON m.color_id = c.id
WHERE m.is_completed = 0 WHERE m.is_completed = 0
@@ -227,7 +231,7 @@ require_once 'inc/header.php';
<label class="form-label">Farbe</label> <label class="form-label">Farbe</label>
<select class="form-select" name="color_id" required> <select class="form-select" name="color_id" required>
<?php foreach ($all_colors as $color): ?> <?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']) ?> <?= htmlspecialchars($color['name']) ?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
@@ -238,6 +242,15 @@ require_once 'inc/header.php';
<input type="text" class="form-control" name="reason" value="<?= htmlspecialchars($edit_meeting['reason'] ?? ''); ?>"> <input type="text" class="form-control" name="reason" value="<?= htmlspecialchars($edit_meeting['reason'] ?? ''); ?>">
<div class="form-text">Wenn leer, wird „Zufallsfarbe“ eingetragen.</div> <div class="form-text">Wenn leer, wird „Zufallsfarbe“ eingetragen.</div>
</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"> <div class="col-12 d-flex justify-content-start">
<button type="submit" class="btn btn-sm btn-outline-<?= $edit_mode ? 'success' : 'primary' ?> me-2"> <button type="submit" class="btn btn-sm btn-outline-<?= $edit_mode ? 'success' : 'primary' ?> me-2">
<?= $edit_mode ? 'Speichern' : 'Hinzufügen' ?> <?= $edit_mode ? 'Speichern' : 'Hinzufügen' ?>
@@ -266,12 +279,22 @@ require_once 'inc/header.php';
<?php else: ?> <?php else: ?>
<div class="list-group list-group-flush"> <div class="list-group list-group-flush">
<?php foreach ($meetings as $m): ?> <?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 class="d-flex justify-content-between align-items-start">
<div> <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="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> </div>
<p class="text-muted small mb-0">Grund: <?= htmlspecialchars($m['reason']); ?></p> <p class="text-muted small mb-0">Grund: <?= htmlspecialchars($m['reason']); ?></p>
</div> </div>
@@ -282,12 +305,12 @@ require_once 'inc/header.php';
</a> </a>
<ul class="dropdown-menu dropdown-menu-end"> <ul class="dropdown-menu dropdown-menu-end">
<li> <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 <span class="material-icons me-2">mode_edit_outline</span> Bearbeiten
</a> </a>
</li> </li>
<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 <span class="material-icons me-2">delete_outline</span> Löschen
</a> </a>
</li> </li>