diff --git a/colors.php b/colors.php index 8ae859d..59f5389 100755 --- a/colors.php +++ b/colors.php @@ -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 "); diff --git a/index.php b/index.php index 83afe68..602c7c7 100755 --- a/index.php +++ b/index.php @@ -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); diff --git a/planning.php b/planning.php index f8bf98f..da30538 100755 --- a/planning.php +++ b/planning.php @@ -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,43 +127,44 @@ 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)) { - $dt = new DateTime($row['meeting_date']); - $year = $dt->format('o'); - $week = $dt->format('W'); - $existing_weeks["$year-$week"] = true; - } +// --- 🔁 Automatische Planung: 4 Donnerstage, max. 1 pro Woche – für ALLE Nutzer --- +$today = new DateTime('today'); - $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'); - $week_key = "$year-$week"; +// 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; +} - if (!isset($existing_weeks[$week_key])) { - $new_date = $date->format('Y-m-d') . ' 12:00:00'; - $color_id = get_weighted_random_color($conn); - if ($color_id) { - $check = mysqli_prepare($conn, "SELECT id FROM meetings WHERE meeting_date = ?"); - 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); +$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'); + $week_key = "$year-$week"; - if (!$exists) { - $default_reason = "Zufallsfarbe"; - $ins = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason) VALUES (?, ?, ?)"); - 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; - } + if (!isset($existing_weeks[$week_key])) { + $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); + $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 = []; $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';
Wenn leer, wird „Zufallsfarbe“ eingetragen.
+
+
+ > + +
+