From 80ede8e3a697bfaed9e8ac40387176d1daf78c8f Mon Sep 17 00:00:00 2001 From: Gemini Agent Date: Sun, 7 Dec 2025 07:57:05 +0000 Subject: [PATCH] Fix: Zusatztaschen-Gewicht und Bilder in Packlisten - backpack_utils.php: Setze article_id beim Sync von Zusatztaschen korrekt. - packing_list_detail.php: Zeige Artikelbild statt Ordner-Icon bei Zusatztaschen. --- src/backpack_utils.php | 15 ++++++++------- src/packing_list_detail.php | 8 +++++++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/backpack_utils.php b/src/backpack_utils.php index 77843ea..3f3e312 100644 --- a/src/backpack_utils.php +++ b/src/backpack_utils.php @@ -6,9 +6,6 @@ function sync_backpack_items($conn, $list_id, $user_id, $backpack_id) { $bp = $conn->query("SELECT name FROM backpacks WHERE id = $backpack_id")->fetch_assoc(); // 2. Check/Create Root Item - // Use NULL safe comparison or check for NULL explicitly - // We need to allow for existing items that might be named differently if user renamed them? - // No, we stick to structure. $root_id = 0; $stmt = $conn->prepare("SELECT id FROM packing_list_items WHERE packing_list_id = ? AND carrier_user_id = ? AND backpack_id = ?"); $stmt->bind_param("iii", $list_id, $user_id, $backpack_id); @@ -28,7 +25,8 @@ function sync_backpack_items($conn, $list_id, $user_id, $backpack_id) { } // 3. Sync Compartments - $comps = $conn->query("SELECT id, name FROM backpack_compartments WHERE backpack_id = $backpack_id ORDER BY sort_order ASC"); + // FIX: Fetch linked_article_id as well + $comps = $conn->query("SELECT id, name, linked_article_id FROM backpack_compartments WHERE backpack_id = $backpack_id ORDER BY sort_order ASC"); while ($comp = $comps->fetch_assoc()) { // Check if item exists for this compartment AND this user $stmt_c = $conn->prepare("SELECT id FROM packing_list_items WHERE packing_list_id = ? AND backpack_compartment_id = ? AND carrier_user_id = ?"); @@ -36,9 +34,12 @@ function sync_backpack_items($conn, $list_id, $user_id, $backpack_id) { $stmt_c->execute(); if ($stmt_c->get_result()->num_rows == 0) { // Create Compartment Item - $c_name = $comp['name']; - $stmt_ins_c = $conn->prepare("INSERT INTO packing_list_items (packing_list_id, carrier_user_id, name, backpack_compartment_id, parent_packing_list_item_id, quantity, article_id, order_index) VALUES (?, ?, ?, ?, ?, 1, NULL, 0)"); - $stmt_ins_c->bind_param("iisii", $list_id, $user_id, $c_name, $comp['id'], $root_id); + $c_name = $comp['name']; + $c_article_id = !empty($comp['linked_article_id']) ? $comp['linked_article_id'] : NULL; + + // FIX: Insert linked article_id if present + $stmt_ins_c = $conn->prepare("INSERT INTO packing_list_items (packing_list_id, carrier_user_id, name, backpack_compartment_id, parent_packing_list_item_id, quantity, article_id, order_index) VALUES (?, ?, ?, ?, ?, 1, ?, 0)"); + $stmt_ins_c->bind_param("iisiii", $list_id, $user_id, $c_name, $comp['id'], $root_id, $c_article_id); $stmt_ins_c->execute(); } } diff --git a/src/packing_list_detail.php b/src/packing_list_detail.php index 75a8696..f41796c 100644 --- a/src/packing_list_detail.php +++ b/src/packing_list_detail.php @@ -182,7 +182,13 @@ function render_item_row($item, $level, $items_by_parent) { } elseif ($is_compartment) { $bg_class = "table-light"; $text_class = "fw-bold fst-italic text-muted"; - $icon = ''; + // Check if linked article (image present) + if (!empty($item['image_url'])) { + $img_src = htmlspecialchars($item['image_url']); + $icon = ''; + } else { + $icon = ''; + } } else { $img_src = !empty($item['image_url']) ? htmlspecialchars($item['image_url']) : 'assets/images/keinbild.png'; $icon = '';