$categoryId, "label" => $label, ]; saveCategories($categories); logAccess("Admin added category", [ "category_id" => $categoryId, "label" => $label, ]); $message = "Kategorie wurde erfolgreich angelegt."; $messageType = "success"; } } if (isset($_POST["update_category"])) { $categoryId = normalizeCategoryId($_POST["category_id"] ?? ""); $label = normalizeCategoryLabel($_POST["label"] ?? ""); $found = false; if (!isValidCategoryLabel($label)) { $message = "Bitte geben Sie einen Kategorienamen mit maximal 80 Zeichen ein."; $messageType = "error"; } else { foreach ($categories as &$category) { if ($category["id"] === $categoryId) { $category["label"] = $label; $found = true; break; } } unset($category); if (!$found) { $message = "Kategorie nicht gefunden."; $messageType = "error"; } else { saveCategories($categories); logAccess("Admin updated category", [ "category_id" => $categoryId, "label" => $label, ]); $message = "Kategorie wurde erfolgreich aktualisiert."; $messageType = "success"; } } } if (isset($_POST["delete_category"])) { $categoryId = normalizeCategoryId($_POST["category_id"] ?? ""); $label = ""; $found = false; if (isCategoryInUse($categoryId)) { $message = "Diese Kategorie wird noch von Produkten verwendet und kann nicht gelöscht werden."; $messageType = "error"; } else { $categories = array_values( array_filter($categories, function ($category) use ( $categoryId, &$found, &$label, ) { if ($category["id"] === $categoryId) { $found = true; $label = $category["label"]; return false; } return true; }), ); if (!$found) { $message = "Kategorie nicht gefunden."; $messageType = "error"; } else { saveCategories($categories); logAccess("Admin deleted category", [ "category_id" => $categoryId, "label" => $label, ]); $message = "Kategorie wurde gelöscht."; $messageType = "success"; } } } $categories = getCategories(); $products = getProducts(); } } $editCategoryId = normalizeCategoryId($_GET["edit"] ?? ""); $editingCategory = null; if ($editCategoryId !== "") { $editingCategory = getCategoryById($editCategoryId); if ($editingCategory === null && $message === "") { $message = "Ausgewählte Kategorie wurde nicht gefunden."; $messageType = "error"; } } $bodyClass = "admin-page"; include __DIR__ . "/../includes/header.php"; ?>
| Name | ID | Produkte | Aktionen |
|---|---|---|---|
|
" class="btn btn-small btn-secondary">Bearbeiten |