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';
- - - - - + + + + + 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(); + ?> + + +