diff --git a/src/add_packing_list.php b/src/add_packing_list.php index 2844411..773827e 100644 --- a/src/add_packing_list.php +++ b/src/add_packing_list.php @@ -59,20 +59,35 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($stmt->execute()) { $new_list_id = $conn->insert_id; - // Handle Backpacks - if (isset($_POST['backpacks'])) { - foreach ($_POST['backpacks'] as $uid => $bid) { + // Handle Backpacks and Participation + if (isset($_POST['participate']) && is_array($_POST['participate'])) { + foreach ($_POST['participate'] as $uid => $val) { $uid = intval($uid); - $bid = intval($bid); - if ($bid > 0) { + // Only add if checked (value is usually '1') + if ($val) { + $bid = isset($_POST['backpacks'][$uid]) ? intval($_POST['backpacks'][$uid]) : 0; + + // Insert Carrier (even if no backpack is assigned, they are a carrier on the list) + // But DB schema: packing_list_carriers links user to list. Backpack is optional. + // If we want them on the list, we insert. + + // Check if $bid is valid (>0) + $bid_to_insert = ($bid > 0) ? $bid : NULL; + $stmt_in = $conn->prepare("INSERT INTO packing_list_carriers (packing_list_id, user_id, backpack_id) VALUES (?, ?, ?)"); - $stmt_in->bind_param("iii", $new_list_id, $uid, $bid); + $stmt_in->bind_param("iii", $new_list_id, $uid, $bid_to_insert); $stmt_in->execute(); $stmt_in->close(); - sync_backpack_items($conn, $new_list_id, $uid, $bid); + if ($bid > 0) { + sync_backpack_items($conn, $new_list_id, $uid, $bid); + } } } + } else { + // If no array (e.g. single user form without checkboxes?), usually we force current user? + // Or assume no one selected. Let's ensure Current User is added if not explicitly unchecked? + // Actually, the UI below will default to checked for everyone. } if ($household_id_for_user) { @@ -104,7 +119,7 @@ require_once 'header.php';
-
+
@@ -122,71 +137,55 @@ require_once 'header.php';
-
-
Rucksack-Zuweisung
+
+
Teilnehmer & Rucksäcke
-

Wähle gleich hier, wer welchen Rucksack trägt.

+

Wähle aus, wer mitkommt und wer welchen Rucksack trägt.

- $current_bp_id, + 'backpacks' => $user_backpacks + ]; ?> -
- - +
+
+ + +
+
+ +
+
+ +
+
+
+
+ +
+ +
+ + Abbrechen +
+ +
- -
- - - - -
- -
- - Abbrechen -
- - - - - - + + + + + diff --git a/src/backpack_utils.php b/src/backpack_utils.php index 90aa3fc..18b35ae 100644 --- a/src/backpack_utils.php +++ b/src/backpack_utils.php @@ -70,4 +70,171 @@ function get_available_backpacks_for_user($conn, $target_user_id, $household_id) } return $bps; } + +/** + * Renders the HTML for the Backpack Selection Card (Small widget per user) + */ +function render_backpack_card_selector($user, $current_bp_id, $user_backpacks) { + // Find current details + $current_bp_details = null; + foreach ($user_backpacks as $bp) { + if ($bp['id'] == $current_bp_id) { + $current_bp_details = $bp; + break; + } + } + + ob_start(); + ?> + + +
+ +
+ + + + + + +
+
+
+ + Kein Rucksack zugewiesen + +
+ +
+ + + + + + + + \ No newline at end of file diff --git a/src/edit_packing_list_details.php b/src/edit_packing_list_details.php index cc31c62..485572f 100644 --- a/src/edit_packing_list_details.php +++ b/src/edit_packing_list_details.php @@ -189,7 +189,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && $can_edit) { // Calculate used backpacks $all_assigned_backpack_ids = array_values($current_assignments); - // Prepare data for JS + // Prepare data for JS (still needed for the render helper) $user_backpacks_json = []; foreach ($available_users as $user): @@ -202,42 +202,13 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && $can_edit) { 'backpacks' => $user_backpacks ]; - // Find current backpack details for display - $current_bp_details = null; - foreach ($user_backpacks as $bp) { - if ($bp['id'] == $my_current_bp_id) { - $current_bp_details = $bp; - break; - } - } + // Use helper to render the widget + echo '
'; + echo ''; + echo render_backpack_card_selector($user, $my_current_bp_id, $user_backpacks); + echo '
'; + endforeach; ?> -
- - - -
- -
- - - - - - - -
-
-
- - Kein Rucksack zugewiesen - -
- -
-
- @@ -254,115 +225,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && $can_edit) { - - - - - - + + \ No newline at end of file diff --git a/src/packing_list_detail.php b/src/packing_list_detail.php index 36cf6f7..1b44930 100644 --- a/src/packing_list_detail.php +++ b/src/packing_list_detail.php @@ -161,6 +161,9 @@ function render_item_row($item, $level, $items_by_parent) { $weight_display = $item['weight_grams'] > 0 ? number_format($item['weight_grams'], 0, ',', '.') . ' g' : '-'; $total_weight_display = $item['weight_grams'] > 0 ? number_format($item['weight_grams'] * $item['quantity'], 0, ',', '.') . ' g' : '-'; + // Ensure children rows are initially shown or hidden based on some logic? Default shown. + // But the toggle button should reflect state. Default expanded -> chevron-down. + echo ''; // Name Column with Indentation @@ -169,9 +172,10 @@ function render_item_row($item, $level, $items_by_parent) { // Tree Toggle or Spacer if ($has_children) { - echo ''; + // Explicitly style the button + echo ''; } else { - echo ''; + echo ''; } echo $icon;