From 086fca68a60115c7ebcb5101defb4bb5febb5369 Mon Sep 17 00:00:00 2001 From: AI Agent Date: Thu, 9 Jul 2026 19:58:18 +0000 Subject: [PATCH] =?UTF-8?q?Feature:=20Rucks=C3=A4cke=20immer=20mit=20dem?= =?UTF-8?q?=20Haushalt=20teilen=20und=20Bearbeitungsrechte=20erweitern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/backpacks.php | 29 +++++++++++++++-------------- src/edit_backpack.php | 18 ++++++------------ 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 8da2926..119bc66 100644 --- a/README.md +++ b/README.md @@ -244,4 +244,4 @@ Das Projekt basiert auf bewährten Web-Standards: * Bugfix ("Headers already sent"): Fehler beim Speichern im Artikel-Editor (`edit_article.php`) behoben, indem Output-Buffering hinzugefügt wurde. * **Features:** * Die Gewichts-Anzeige in der Rucksackübersicht (`backpacks.php`) wurde angepasst und zeigt nun das "Basisgewicht + Zusatzgewicht" in Klammern an anstatt nur dem Zusatzgewicht. - * In der Rucksack-Bearbeitung (`edit_backpack.php`) kann nun der Besitzer des Rucksacks (analog zu Artikeln) innerhalb des Haushalts geändert werden. + * In der Rucksack-Bearbeitung (`edit_backpack.php`) kann nun der Besitzer des Rucksacks (analog zu Artikeln) innerhalb des Haushalts geändert werden. Die Option "Mit Haushalt teilen" wurde entfernt, da Rucksäcke nun immer geteilt werden und von allen Mitgliedern bearbeitet werden können. diff --git a/src/backpacks.php b/src/backpacks.php index 83e4f5a..fddffbb 100644 --- a/src/backpacks.php +++ b/src/backpacks.php @@ -17,12 +17,23 @@ require_once 'header.php'; $user_id = $_SESSION['user_id']; $message = ''; +// Fetch Household +$household_id = null; +$stmt_hh = $conn->prepare("SELECT household_id FROM users WHERE id = ?"); +$stmt_hh->bind_param("i", $user_id); +$stmt_hh->execute(); +$res_hh = $stmt_hh->get_result(); +if ($row = $res_hh->fetch_assoc()) { + $household_id = $row['household_id']; +} + // Delete Action if (isset($_POST['delete_backpack_id'])) { $delete_id = intval($_POST['delete_backpack_id']); - // Check ownership - $stmt = $conn->prepare("SELECT id FROM backpacks WHERE id = ? AND user_id = ?"); - $stmt->bind_param("ii", $delete_id, $user_id); + // Check ownership or household + $stmt = $conn->prepare("SELECT id FROM backpacks WHERE id = ? AND (user_id = ? OR household_id = ?)"); + $hh_id_param = $household_id ?: 0; + $stmt->bind_param("iii", $delete_id, $user_id, $hh_id_param); $stmt->execute(); if ($stmt->get_result()->num_rows > 0) { $stmt_del = $conn->prepare("DELETE FROM backpacks WHERE id = ?"); @@ -48,16 +59,6 @@ if ($check_col_c && $check_col_c->num_rows == 0) { $conn->query("ALTER TABLE backpack_compartments ADD CONSTRAINT fk_bc_article FOREIGN KEY (linked_article_id) REFERENCES articles(id) ON DELETE SET NULL"); } -// Fetch Backpacks (Personal + Household) -$household_id = null; -$stmt_hh = $conn->prepare("SELECT household_id FROM users WHERE id = ?"); -$stmt_hh->bind_param("i", $user_id); -$stmt_hh->execute(); -$res_hh = $stmt_hh->get_result(); -if ($row = $res_hh->fetch_assoc()) { - $household_id = $row['household_id']; -} - $backpacks = []; $sql = "SELECT b.*, u.username as owner_name, @@ -155,7 +156,7 @@ while ($row = $result->fetch_assoc()) {
- +
diff --git a/src/edit_backpack.php b/src/edit_backpack.php index 123e84b..a092782 100644 --- a/src/edit_backpack.php +++ b/src/edit_backpack.php @@ -85,8 +85,9 @@ function save_image_from_base64($base64_string, $upload_dir) { // Load existing data if ($backpack_id > 0) { - $stmt = $conn->prepare("SELECT * FROM backpacks WHERE id = ? AND user_id = ?"); - $stmt->bind_param("ii", $backpack_id, $user_id); + $stmt = $conn->prepare("SELECT * FROM backpacks WHERE id = ? AND (user_id = ? OR household_id = ?)"); + $hh_id_param = $household_id ?: 0; + $stmt->bind_param("iii", $backpack_id, $user_id, $hh_id_param); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { @@ -195,7 +196,6 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { $model = trim($_POST['model']); $weight = intval($_POST['weight_grams']); $volume = intval($_POST['volume_liters']); - $share_household = isset($_POST['share_household']) ? 1 : 0; $product_url_input = trim($_POST['product_url'] ?? ''); $category_id = !empty($_POST['category_id']) ? intval($_POST['category_id']) : NULL; @@ -220,12 +220,12 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($ok) $image_url_for_db = $res; } - $final_household_id = ($share_household && $household_id) ? $household_id : NULL; + $final_household_id = $household_id ?: NULL; $new_owner_id = !empty($_POST['owner_id']) ? intval($_POST['owner_id']) : $user_id; if ($backpack_id > 0) { - $stmt = $conn->prepare("UPDATE backpacks SET user_id=?, name=?, manufacturer=?, model=?, weight_grams=?, volume_liters=?, household_id=?, image_url=?, product_url=?, category_id=? WHERE id=? AND user_id=?"); - $stmt->bind_param("isssiisssiii", $new_owner_id, $name, $manufacturer, $model, $weight, $volume, $final_household_id, $image_url_for_db, $product_url_input, $category_id, $backpack_id, $user_id); + $stmt = $conn->prepare("UPDATE backpacks SET user_id=?, name=?, manufacturer=?, model=?, weight_grams=?, volume_liters=?, household_id=?, image_url=?, product_url=?, category_id=? WHERE id=?"); + $stmt->bind_param("isssiisssii", $new_owner_id, $name, $manufacturer, $model, $weight, $volume, $final_household_id, $image_url_for_db, $product_url_input, $category_id, $backpack_id); $stmt->execute(); } else { $stmt = $conn->prepare("INSERT INTO backpacks (user_id, household_id, name, manufacturer, model, weight_grams, volume_liters, image_url, product_url, category_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); @@ -372,12 +372,6 @@ require_once 'header.php';
-
-
- > - -
-