Feature: Rucksäcke immer mit dem Haushalt teilen und Bearbeitungsrechte erweitern
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 11s

This commit is contained in:
AI Agent
2026-07-09 19:58:18 +00:00
parent aa8c4987a8
commit 086fca68a6
3 changed files with 22 additions and 27 deletions

View File

@@ -244,4 +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.
* In der Rucksack-Bearbeitung (`edit_backpack.php`) kann nun der Besitzer des Rucksacks (analog zu Artikeln) innerhalb des Haushalts geändert werden. Die Option "Mit Haushalt teilen" wurde entfernt, da Rucksäcke nun immer geteilt werden und von allen Mitgliedern bearbeitet werden können.

View File

@@ -17,12 +17,23 @@ require_once 'header.php';
$user_id = $_SESSION['user_id'];
$message = '';
// Fetch Household
$household_id = null;
$stmt_hh = $conn->prepare("SELECT household_id FROM users WHERE id = ?");
$stmt_hh->bind_param("i", $user_id);
$stmt_hh->execute();
$res_hh = $stmt_hh->get_result();
if ($row = $res_hh->fetch_assoc()) {
$household_id = $row['household_id'];
}
// Delete Action
if (isset($_POST['delete_backpack_id'])) {
$delete_id = intval($_POST['delete_backpack_id']);
// Check ownership
$stmt = $conn->prepare("SELECT id FROM backpacks WHERE id = ? AND user_id = ?");
$stmt->bind_param("ii", $delete_id, $user_id);
// Check ownership or household
$stmt = $conn->prepare("SELECT id FROM backpacks WHERE id = ? AND (user_id = ? OR household_id = ?)");
$hh_id_param = $household_id ?: 0;
$stmt->bind_param("iii", $delete_id, $user_id, $hh_id_param);
$stmt->execute();
if ($stmt->get_result()->num_rows > 0) {
$stmt_del = $conn->prepare("DELETE FROM backpacks WHERE id = ?");
@@ -48,16 +59,6 @@ if ($check_col_c && $check_col_c->num_rows == 0) {
$conn->query("ALTER TABLE backpack_compartments ADD CONSTRAINT fk_bc_article FOREIGN KEY (linked_article_id) REFERENCES articles(id) ON DELETE SET NULL");
}
// Fetch Backpacks (Personal + Household)
$household_id = null;
$stmt_hh = $conn->prepare("SELECT household_id FROM users WHERE id = ?");
$stmt_hh->bind_param("i", $user_id);
$stmt_hh->execute();
$res_hh = $stmt_hh->get_result();
if ($row = $res_hh->fetch_assoc()) {
$household_id = $row['household_id'];
}
$backpacks = [];
$sql = "SELECT b.*, u.username as owner_name,
@@ -155,7 +156,7 @@ while ($row = $result->fetch_assoc()) {
</div>
<div class="d-flex gap-1">
<?php if ($bp['user_id'] == $user_id): ?>
<?php if ($bp['user_id'] == $user_id || ($household_id && $bp['household_id'] == $household_id)): ?>
<a href="edit_backpack.php?id=<?php echo $bp['id']; ?>" class="btn btn-sm btn-outline-primary"><i class="fas fa-edit"></i></a>
<form method="post" onsubmit="return confirm('Rucksack wirklich löschen?');" class="d-inline">
<input type="hidden" name="delete_backpack_id" value="<?php echo $bp['id']; ?>">

View File

@@ -85,8 +85,9 @@ function save_image_from_base64($base64_string, $upload_dir) {
// Load existing data
if ($backpack_id > 0) {
$stmt = $conn->prepare("SELECT * FROM backpacks WHERE id = ? AND user_id = ?");
$stmt->bind_param("ii", $backpack_id, $user_id);
$stmt = $conn->prepare("SELECT * FROM backpacks WHERE id = ? AND (user_id = ? OR household_id = ?)");
$hh_id_param = $household_id ?: 0;
$stmt->bind_param("iii", $backpack_id, $user_id, $hh_id_param);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
@@ -195,7 +196,6 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$model = trim($_POST['model']);
$weight = intval($_POST['weight_grams']);
$volume = intval($_POST['volume_liters']);
$share_household = isset($_POST['share_household']) ? 1 : 0;
$product_url_input = trim($_POST['product_url'] ?? '');
$category_id = !empty($_POST['category_id']) ? intval($_POST['category_id']) : NULL;
@@ -220,12 +220,12 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($ok) $image_url_for_db = $res;
}
$final_household_id = ($share_household && $household_id) ? $household_id : NULL;
$final_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 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 = $conn->prepare("UPDATE backpacks SET user_id=?, name=?, manufacturer=?, model=?, weight_grams=?, volume_liters=?, household_id=?, image_url=?, product_url=?, category_id=? WHERE id=?");
$stmt->bind_param("isssiisssii", $new_owner_id, $name, $manufacturer, $model, $weight, $volume, $final_household_id, $image_url_for_db, $product_url_input, $category_id, $backpack_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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
@@ -372,12 +372,6 @@ 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-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>