Feature: Rucksackbesitzer kann geändert werden
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 8s
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 8s
This commit is contained in:
@@ -244,3 +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.
|
||||
|
||||
@@ -110,12 +110,25 @@ if ($backpack_id > 0) {
|
||||
|
||||
// Load Manufacturers & Categories
|
||||
$hh_ids = [$user_id];
|
||||
$all_household_members = [];
|
||||
if ($household_id) {
|
||||
$stmt_hhm = $conn->prepare("SELECT id FROM users WHERE household_id = ?");
|
||||
$stmt_hhm = $conn->prepare("SELECT id, COALESCE(NULLIF(display_name, ''), username) AS username FROM users WHERE household_id = ? ORDER BY username ASC");
|
||||
$stmt_hhm->bind_param("i", $household_id);
|
||||
$stmt_hhm->execute();
|
||||
$res_hhm = $stmt_hhm->get_result();
|
||||
while($r = $res_hhm->fetch_assoc()) $hh_ids[] = $r['id'];
|
||||
while($r = $res_hhm->fetch_assoc()) {
|
||||
if (!in_array($r['id'], $hh_ids)) $hh_ids[] = $r['id'];
|
||||
$all_household_members[] = $r;
|
||||
}
|
||||
}
|
||||
// Ensure current user is in $all_household_members if not already
|
||||
$found = false;
|
||||
foreach ($all_household_members as $m) { if ($m['id'] == $user_id) $found = true; }
|
||||
if (!$found) {
|
||||
$stmt_u = $conn->prepare("SELECT id, COALESCE(NULLIF(display_name, ''), username) AS username FROM users WHERE id = ?");
|
||||
$stmt_u->bind_param("i", $user_id);
|
||||
$stmt_u->execute();
|
||||
if ($row = $stmt_u->get_result()->fetch_assoc()) $all_household_members[] = $row;
|
||||
}
|
||||
$placeholders = implode(',', array_fill(0, count($hh_ids), '?'));
|
||||
$types_hh = str_repeat('i', count($hh_ids));
|
||||
@@ -208,14 +221,15 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
}
|
||||
|
||||
$final_household_id = ($share_household && $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 name=?, manufacturer=?, model=?, weight_grams=?, volume_liters=?, household_id=?, image_url=?, product_url=?, category_id=? WHERE id=? AND user_id=?");
|
||||
$stmt->bind_param("sssiisssiii", $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=? 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->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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
$stmt->bind_param("iisssiissi", $user_id, $final_household_id, $name, $manufacturer, $model, $weight, $volume, $image_url_for_db, $product_url_input, $category_id);
|
||||
$stmt->bind_param("iisssiissi", $new_owner_id, $final_household_id, $name, $manufacturer, $model, $weight, $volume, $image_url_for_db, $product_url_input, $category_id);
|
||||
$stmt->execute();
|
||||
$backpack_id = $stmt->insert_id;
|
||||
}
|
||||
@@ -358,12 +372,25 @@ require_once 'header.php';
|
||||
<input type="url" name="product_url" class="form-control" value="<?php echo htmlspecialchars($product_url); ?>" placeholder="https://...">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div class="form-check form-switch">
|
||||
<div class="col-md-6">
|
||||
<div class="form-check form-switch mt-4">
|
||||
<input class="form-check-input" type="checkbox" id="share_household" name="share_household" <?php echo (!empty($backpack['household_id']) || $backpack_id == 0) ? 'checked' : ''; ?>>
|
||||
<label class="form-check-label" for="share_household">Mit Haushalt teilen</label>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($household_id): ?>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label" for="owner_id">Besitzer</label>
|
||||
<select class="form-select" id="owner_id" name="owner_id">
|
||||
<?php
|
||||
foreach ($all_household_members as $member):
|
||||
$selected = (isset($backpack['user_id']) && $backpack['user_id'] == $member['id']) || (!isset($backpack['user_id']) && $user_id == $member['id']) ? 'selected' : '';
|
||||
?>
|
||||
<option value="<?php echo $member['id']; ?>" <?php echo $selected; ?>><?php echo htmlspecialchars($member['username']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
|
||||
Reference in New Issue
Block a user