From 787a6d8a1ca10b0c2f861a89b6634c6332c6e4a1 Mon Sep 17 00:00:00 2001 From: Gemini Date: Thu, 14 May 2026 20:40:13 +0000 Subject: [PATCH] Fix: Kategorie-Farben werden nun korrekt gespeichert --- src/categories.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/categories.php b/src/categories.php index 04e9d0b..7fb8a29 100644 --- a/src/categories.php +++ b/src/categories.php @@ -44,9 +44,12 @@ $types = str_repeat('i', count($household_member_ids)); if ($_SERVER["REQUEST_METHOD"] == "POST") { if (isset($_POST['add_category'])) { $category_name = trim($_POST['category_name']); + $category_color = trim($_POST['category_color'] ?? '#e2e8f0'); + if (!preg_match('/^#[a-f0-9]{6}$/i', $category_color)) $category_color = '#e2e8f0'; + if (!empty($category_name)) { - $stmt = $conn->prepare("INSERT INTO categories (name, user_id) VALUES (?, ?)"); - $stmt->bind_param("si", $category_name, $current_user_id); + $stmt = $conn->prepare("INSERT INTO categories (name, user_id, color) VALUES (?, ?, ?)"); + $stmt->bind_param("sis", $category_name, $current_user_id, $category_color); if ($stmt->execute()) { if ($household_id) { $log_message = htmlspecialchars($_SESSION['username']) . " hat die Kategorie '" . htmlspecialchars($category_name) . "' hinzugefügt."; @@ -68,10 +71,12 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { elseif (isset($_POST['edit_category'])) { $category_id = intval($_POST['category_id']); $category_name = trim($_POST['category_name']); + $category_color = trim($_POST['category_color'] ?? '#e2e8f0'); + if (!preg_match('/^#[a-f0-9]{6}$/i', $category_color)) $category_color = '#e2e8f0'; if (!empty($category_name) && $category_id > 0) { - $stmt = $conn->prepare("UPDATE categories SET name = ? WHERE id = ? AND user_id = ?"); - $stmt->bind_param("sii", $category_name, $category_id, $current_user_id); + $stmt = $conn->prepare("UPDATE categories SET name = ?, color = ? WHERE id = ? AND user_id = ?"); + $stmt->bind_param("ssii", $category_name, $category_color, $category_id, $current_user_id); if ($stmt->execute()) { if ($household_id) { $log_message = htmlspecialchars($_SESSION['username']) . " hat die Kategorie '" . htmlspecialchars($category_name) . "' bearbeitet.";