Fix: Template improvements
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 38s
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 38s
- api_packing_list_handler.php: Use robust LEFT JOINs to fetch backpack/compartment names, fixing '0' display issue for templates. - packing_lists.php: Add 'Edit Details' button for templates. - edit_packing_list_details.php: Allow sharing templates with household (checkbox) and adjust title for templates.
This commit is contained in:
@@ -224,7 +224,33 @@ function user_can_edit_list($conn, $packing_list_id, $user_id) {
|
||||
}
|
||||
|
||||
function get_all_items($conn, $packing_list_id) {
|
||||
$stmt = $conn->prepare("SELECT pli.id, pli.article_id, pli.quantity, pli.parent_packing_list_item_id, pli.carrier_user_id, pli.backpack_id, pli.backpack_compartment_id, COALESCE(a.name, pli.name) as name, a.weight_grams, a.product_designation, a.consumable, m.name as manufacturer_name FROM packing_list_items pli LEFT JOIN articles a ON pli.article_id = a.id LEFT JOIN manufacturers m ON a.manufacturer_id = m.id WHERE pli.packing_list_id = ? ORDER BY pli.order_index ASC, pli.id ASC");
|
||||
$sql = "SELECT
|
||||
pli.id,
|
||||
pli.article_id,
|
||||
pli.quantity,
|
||||
pli.parent_packing_list_item_id,
|
||||
pli.carrier_user_id,
|
||||
pli.backpack_id,
|
||||
pli.backpack_compartment_id,
|
||||
COALESCE(
|
||||
a.name,
|
||||
bc.name,
|
||||
CASE WHEN b.name IS NOT NULL THEN CONCAT('Rucksack: ', b.name) ELSE NULL END,
|
||||
pli.name
|
||||
) as name,
|
||||
a.weight_grams,
|
||||
a.product_designation,
|
||||
a.consumable,
|
||||
m.name as manufacturer_name
|
||||
FROM packing_list_items pli
|
||||
LEFT JOIN articles a ON pli.article_id = a.id
|
||||
LEFT JOIN manufacturers m ON a.manufacturer_id = m.id
|
||||
LEFT JOIN backpacks b ON pli.backpack_id = b.id
|
||||
LEFT JOIN backpack_compartments bc ON pli.backpack_compartment_id = bc.id
|
||||
WHERE pli.packing_list_id = ?
|
||||
ORDER BY pli.order_index ASC, pli.id ASC";
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param("i", $packing_list_id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
@@ -85,11 +85,19 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && $can_edit) {
|
||||
// Update Basic Details
|
||||
$name = trim($_POST['name']);
|
||||
$description = trim($_POST['description']);
|
||||
$stmt_update = $conn->prepare("UPDATE packing_lists SET name = ?, description = ? WHERE id = ?");
|
||||
$stmt_update->bind_param("ssi", $name, $description, $packing_list_id);
|
||||
|
||||
// Household sharing logic
|
||||
$new_household_id = NULL;
|
||||
if (isset($_POST['is_household_list']) && $_POST['is_household_list'] == '1' && $current_user_household_id) {
|
||||
$new_household_id = $current_user_household_id;
|
||||
}
|
||||
|
||||
$stmt_update = $conn->prepare("UPDATE packing_lists SET name = ?, description = ?, household_id = ? WHERE id = ?");
|
||||
$stmt_update->bind_param("ssii", $name, $description, $new_household_id, $packing_list_id);
|
||||
$stmt_update->execute();
|
||||
$packing_list['name'] = $name;
|
||||
$packing_list['description'] = $description;
|
||||
$packing_list['household_id'] = $new_household_id;
|
||||
|
||||
// Handle Participation & Backpacks
|
||||
// Get all potential users to check if they were unchecked
|
||||
@@ -179,12 +187,13 @@ function cleanup_old_backpack_containers($conn, $list_id, $user_id) {
|
||||
}
|
||||
|
||||
$back_link = 'packing_lists.php' . (!empty($packing_list['is_template']) ? '?view=templates' : '');
|
||||
$page_headline = !empty($packing_list['is_template']) ? 'Vorlage bearbeiten' : 'Details bearbeiten';
|
||||
|
||||
?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<h2 class="h4 mb-0">Details: <?php echo htmlspecialchars($packing_list['name'] ?? ''); ?></h2>
|
||||
<h2 class="h4 mb-0"><?php echo $page_headline; ?>: <?php echo htmlspecialchars($packing_list['name'] ?? ''); ?></h2>
|
||||
<a href="<?php echo $back_link; ?>" class="btn btn-sm btn-outline-light"><i class="fas fa-arrow-left me-2"></i>Zurück</a>
|
||||
</div>
|
||||
<div class="card-body p-4">
|
||||
@@ -203,10 +212,17 @@ $back_link = 'packing_lists.php' . (!empty($packing_list['is_template']) ? '?vie
|
||||
<label class="form-label">Beschreibung</label>
|
||||
<textarea class="form-control" name="description" rows="3"><?php echo htmlspecialchars($packing_list['description'] ?: ''); ?></textarea>
|
||||
</div>
|
||||
|
||||
<?php if ($current_user_household_id): ?>
|
||||
<div class="form-check form-switch mb-3">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="is_household_list" name="is_household_list" value="1" <?php echo !empty($packing_list['household_id']) ? 'checked' : ''; ?>>
|
||||
<label class="form-check-label" for="is_household_list">Für den gesamten Haushalt freigeben</label>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<h5 class="mb-3">Teilnehmer & Rucksäcke</h5>
|
||||
<h5 class="mb-3">Teilnehmer & Rucksäcke <?php if(!empty($packing_list['is_template'])): ?><small class="text-muted">(Standard)</small><?php endif; ?></h5>
|
||||
<div class="card bg-light border-0">
|
||||
<div class="card-body">
|
||||
<p class="small text-muted">Wähle hier, wer mitkommt und welchen Rucksack er trägt.</p>
|
||||
|
||||
@@ -142,16 +142,11 @@ $conn->close();
|
||||
// VORLAGEN ACTIONS
|
||||
?>
|
||||
<form action="add_packing_list.php" method="POST" class="d-inline">
|
||||
<!-- Hack: Wir nutzen das Formular von add_packing_list, aber wir müssen es eigentlich via GET -> UI aufrufen oder POST direkt?
|
||||
add_packing_list erwartet POST mit 'name' etc.
|
||||
Besser: Link zu add_packing_list.php mit Preset. Aber das haben wir nicht gebaut.
|
||||
Daher: Nur Edit/Delete hier. Das "Nutzen" passiert im "Erstellen" Dialog.
|
||||
-->
|
||||
</form>
|
||||
|
||||
<!-- Bearbeiten (Inhalt ändern) -->
|
||||
<?php if ($is_owner || $can_edit_household_list): ?>
|
||||
<a href="manage_packing_list_items.php?id=<?php echo $list['id']; ?>" class="btn btn-sm btn-outline-primary" title="Vorlage bearbeiten"><i class="fas fa-pencil-alt"></i></a>
|
||||
<a href="edit_packing_list_details.php?id=<?php echo $list['id']; ?>" class="btn btn-sm btn-outline-primary" title="Details bearbeiten"><i class="fas fa-pencil-alt"></i></a>
|
||||
<a href="manage_packing_list_items.php?id=<?php echo $list['id']; ?>" class="btn btn-sm btn-outline-secondary" title="Inhalt bearbeiten"><i class="fas fa-boxes"></i></a>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
|
||||
Reference in New Issue
Block a user