Feature: Kategorienverwaltung hinzugefügt und Artikel-Kachel Höhe angepasst
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 40s
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 40s
This commit is contained in:
@@ -229,7 +229,7 @@ $conn->close();
|
||||
border: 1px solid #eee; border-radius: 8px; padding: 6px;
|
||||
text-align: center; background: #fff; display: flex; flex-direction: column;
|
||||
transition: transform 0.1s, box-shadow 0.1s;
|
||||
height: 250px;
|
||||
height: 220px;
|
||||
position: relative;
|
||||
}
|
||||
.lager-card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.05); }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// categories.php - Kategorienverwaltung
|
||||
// FINALE VERSION mit Haushaltslogik
|
||||
|
||||
$page_title = "Kategorien im Haushalt";
|
||||
$page_title = "Kategorien verwalten";
|
||||
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
@@ -53,34 +53,85 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
log_household_action($conn, $household_id, $current_user_id, $log_message);
|
||||
}
|
||||
$message = '<div class="alert alert-success" role="alert">Kategorie erfolgreich hinzugefügt!</div>';
|
||||
} else { /* ... */ }
|
||||
} else {
|
||||
if ($conn->errno == 1062) {
|
||||
$message = '<div class="alert alert-danger" role="alert">Fehler: Eine Kategorie mit diesem Namen existiert bereits für dein Konto.</div>';
|
||||
} else {
|
||||
$message = '<div class="alert alert-danger" role="alert">Fehler beim Hinzufügen der Kategorie: ' . $stmt->error . '</div>';
|
||||
}
|
||||
}
|
||||
$stmt->close();
|
||||
} else { /* ... */ }
|
||||
} else {
|
||||
$message = '<div class="alert alert-danger" role="alert">Der Kategoriename darf nicht leer sein.</div>';
|
||||
}
|
||||
}
|
||||
elseif (isset($_POST['edit_category'])) {
|
||||
// ...
|
||||
$category_id = intval($_POST['category_id']);
|
||||
$category_name = trim($_POST['category_name']);
|
||||
|
||||
if (!empty($category_name) && $category_id > 0) {
|
||||
$stmt = $conn->prepare("UPDATE categories SET name = ? WHERE id = ? AND user_id = ?");
|
||||
$stmt->bind_param("sii", $category_name, $category_id, $current_user_id);
|
||||
if ($stmt->execute()) {
|
||||
if ($household_id) {
|
||||
$log_message = htmlspecialchars($_SESSION['username']) . " hat die Kategorie '" . htmlspecialchars($category_name) . "' bearbeitet.";
|
||||
log_household_action($conn, $household_id, $current_user_id, $log_message);
|
||||
}
|
||||
$message = '<div class="alert alert-success" role="alert">Kategorie erfolgreich aktualisiert!</div>';
|
||||
} else {
|
||||
$message = '<div class="alert alert-danger" role="alert">Fehler beim Aktualisieren der Kategorie: ' . $stmt->error . '</div>';
|
||||
}
|
||||
$stmt->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id'])) {
|
||||
// ...
|
||||
$category_id = intval($_GET['id']);
|
||||
|
||||
// Prüfen ob die Kategorie dem User gehört
|
||||
$stmt_check = $conn->prepare("SELECT name FROM categories WHERE id = ? AND user_id = ?");
|
||||
$stmt_check->bind_param("ii", $category_id, $current_user_id);
|
||||
$stmt_check->execute();
|
||||
$res_check = $stmt_check->get_result();
|
||||
|
||||
if ($res_check->num_rows > 0) {
|
||||
$cat_name = $res_check->fetch_assoc()['name'];
|
||||
// Optional: Vor dem Löschen prüfen, ob Artikel verknüpft sind, und auf NULL setzen (in DB per ON DELETE SET NULL gemacht)
|
||||
|
||||
$stmt_delete = $conn->prepare("DELETE FROM categories WHERE id = ?");
|
||||
$stmt_delete->bind_param("i", $category_id);
|
||||
if ($stmt_delete->execute()) {
|
||||
if ($household_id) {
|
||||
$log_message = htmlspecialchars($_SESSION['username']) . " hat die Kategorie '" . htmlspecialchars($cat_name) . "' gelöscht.";
|
||||
log_household_action($conn, $household_id, $current_user_id, $log_message);
|
||||
}
|
||||
$message = '<div class="alert alert-success" role="alert">Kategorie erfolgreich gelöscht!</div>';
|
||||
} else {
|
||||
$message = '<div class="alert alert-danger" role="alert">Fehler beim Löschen der Kategorie.</div>';
|
||||
}
|
||||
$stmt_delete->close();
|
||||
} else {
|
||||
$message = '<div class="alert alert-danger" role="alert">Sie sind nicht berechtigt, diese Kategorie zu löschen.</div>';
|
||||
}
|
||||
$stmt_check->close();
|
||||
}
|
||||
|
||||
$stmt_load = $conn->prepare("SELECT c.id, c.name, c.user_id, u.username as creator_name FROM categories c JOIN users u ON c.user_id = u.id WHERE c.user_id IN ($placeholders) ORDER BY c.name ASC");
|
||||
$stmt_load->bind_param($types, ...$household_member_ids);
|
||||
$stmt_load->execute();
|
||||
$categories_list = $stmt_load->get_result()->fetch_all(MYSQLI_ASSOC);
|
||||
$stmt_load->close();
|
||||
$categories_query = $conn->prepare("SELECT c.id, c.name, c.user_id, u.username as creator_name FROM categories c JOIN users u ON c.user_id = u.id WHERE c.user_id IN ($placeholders) ORDER BY c.name ASC");
|
||||
$categories_query->bind_param($types, ...$household_member_ids);
|
||||
$categories_query->execute();
|
||||
$categories_list = $categories_query->get_result()->fetch_all(MYSQLI_ASSOC);
|
||||
$categories_query->close();
|
||||
$conn->close();
|
||||
?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<h2 class="h4 mb-0">Kategorien im Haushalt</h2>
|
||||
<div class="card-header">
|
||||
<h2 class="h4 mb-0"><i class="fas fa-tags me-2"></i>Kategorien im Haushalt</h2>
|
||||
</div>
|
||||
<div class="card-body p-4">
|
||||
<?php if(!empty($message)) echo $message; ?>
|
||||
|
||||
<div class="card bg-light mb-5">
|
||||
<div class="card bg-light mb-5 border-0 shadow-sm">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title mb-3">Neue Kategorie hinzufügen</h5>
|
||||
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" class="row g-3 align-items-end">
|
||||
@@ -97,14 +148,14 @@ $conn->close();
|
||||
|
||||
<h5 class="mb-3">Bestehende Kategorien</h5>
|
||||
<?php if (empty($categories_list)): ?>
|
||||
<div class="alert alert-info text-center">Keine Kategorien im Haushalt gefunden.</div>
|
||||
<div class="alert alert-info text-center">Keine Kategorien gefunden.</div>
|
||||
<?php else: ?>
|
||||
<div class="list-group">
|
||||
<div class="list-group shadow-sm">
|
||||
<?php foreach ($categories_list as $category): ?>
|
||||
<div class="list-group-item d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<i class="fas fa-tag text-muted me-2"></i>
|
||||
<span><?php echo htmlspecialchars($category['name']); ?></span>
|
||||
<span class="fw-bold"><?php echo htmlspecialchars($category['name']); ?></span>
|
||||
<?php if ($category['user_id'] != $current_user_id): ?>
|
||||
<small class="text-muted ms-2">(von <?php echo htmlspecialchars($category['creator_name']); ?>)</small>
|
||||
<?php endif; ?>
|
||||
@@ -153,19 +204,19 @@ $conn->close();
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
var editCategoryModal = document.getElementById('editCategoryModal');
|
||||
if (editCategoryModal) {
|
||||
editCategoryModal.addEventListener('show.bs.modal', function (event) {
|
||||
var editModal = document.getElementById('editCategoryModal');
|
||||
if (editModal) {
|
||||
editModal.addEventListener('show.bs.modal', function (event) {
|
||||
var button = event.relatedTarget;
|
||||
var categoryId = button.getAttribute('data-id');
|
||||
var categoryName = button.getAttribute('data-name');
|
||||
var modalIdInput = editCategoryModal.querySelector('#edit_category_id');
|
||||
var modalNameInput = editCategoryModal.querySelector('#edit_category_name');
|
||||
if (modalIdInput) modalIdInput.value = categoryId;
|
||||
if (modalNameInput) modalNameInput.value = categoryName;
|
||||
var id = button.getAttribute('data-id');
|
||||
var name = button.getAttribute('data-name');
|
||||
var modalIdInput = editModal.querySelector('#edit_category_id');
|
||||
var modalNameInput = editModal.querySelector('#edit_category_name');
|
||||
if (modalIdInput) modalIdInput.value = id;
|
||||
if (modalNameInput) modalNameInput.value = name;
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php require_once 'footer.php'; ?>
|
||||
<?php require_once 'footer.php'; ?>
|
||||
@@ -72,6 +72,7 @@ if (isset($_SESSION['user_id'])) {
|
||||
<li class="nav-item"><a class="nav-link" href="packing_lists.php"><i class="fas fa-clipboard-list fa-fw"></i>Packlisten</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="storage_locations.php"><i class="fas fa-archive fa-fw"></i>Lagerorte</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="todo_lists.php"><i class="fas fa-list-check fa-fw"></i>ToDo-Listen</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="categories.php"><i class="fas fa-tags fa-fw"></i>Kategorien</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="manufacturers.php"><i class="fas fa-industry fa-fw"></i>Hersteller</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="household.php"><i class="fas fa-users-cog fa-fw"></i>Haushalt</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="user_profile.php"><i class="fas fa-user-cog fa-fw"></i>Profil</a></li>
|
||||
|
||||
Reference in New Issue
Block a user