v1.3.2 - Farbvorgabe angepasst
This commit is contained in:
@@ -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
|
||||||
");
|
");
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
63
planning.php
63
planning.php
@@ -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,11 +127,12 @@ 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');
|
||||||
|
|
||||||
|
// Nur nicht-übersprungene Termine zählen
|
||||||
$existing_weeks = [];
|
$existing_weeks = [];
|
||||||
$result_existing = mysqli_query($conn, "SELECT meeting_date FROM meetings");
|
$result_existing = mysqli_query($conn, "SELECT meeting_date FROM meetings WHERE is_skipped = 0");
|
||||||
while ($row = mysqli_fetch_assoc($result_existing)) {
|
while ($row = mysqli_fetch_assoc($result_existing)) {
|
||||||
$dt = new DateTime($row['meeting_date']);
|
$dt = new DateTime($row['meeting_date']);
|
||||||
$year = $dt->format('o');
|
$year = $dt->format('o');
|
||||||
@@ -148,6 +151,7 @@ if ($is_admin) {
|
|||||||
$new_date = $date->format('Y-m-d') . ' 12:00:00';
|
$new_date = $date->format('Y-m-d') . ' 12:00:00';
|
||||||
$color_id = get_weighted_random_color($conn);
|
$color_id = get_weighted_random_color($conn);
|
||||||
if ($color_id) {
|
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 = ?");
|
$check = mysqli_prepare($conn, "SELECT id FROM meetings WHERE meeting_date = ?");
|
||||||
mysqli_stmt_bind_param($check, "s", $new_date);
|
mysqli_stmt_bind_param($check, "s", $new_date);
|
||||||
mysqli_stmt_execute($check);
|
mysqli_stmt_execute($check);
|
||||||
@@ -156,7 +160,7 @@ if ($is_admin) {
|
|||||||
|
|
||||||
if (!$exists) {
|
if (!$exists) {
|
||||||
$default_reason = "Zufallsfarbe";
|
$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_bind_param($ins, "sis", $new_date, $color_id, $default_reason);
|
||||||
mysqli_stmt_execute($ins);
|
mysqli_stmt_execute($ins);
|
||||||
mysqli_stmt_close($ins);
|
mysqli_stmt_close($ins);
|
||||||
@@ -165,7 +169,6 @@ if ($is_admin) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// --- Daten für Anzeige laden ---
|
// --- Daten für Anzeige laden ---
|
||||||
$all_colors = [];
|
$all_colors = [];
|
||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user