prepare('INSERT INTO kb_categories (name, slug, sort_order) VALUES (?,?,0)')->execute([$name, $slug]); if (function_exists('dhcm_cache_clear')) dhcm_cache_clear(); audit_log($admin['id'], "KB-Kategorie erstellt: {$name}"); flash('success', 'Kategorie erstellt.'); redirect('/staff/kb_manage.php'); } } if ($action === 'delete_category') { $id = (int) $_POST['id']; $stmt = $pdo->prepare('SELECT COUNT(*) FROM kb_articles WHERE category_id = ?'); $stmt->execute([$id]); if ((int) $stmt->fetchColumn() > 0) { flash('error', 'Diese Kategorie enthält noch Artikel und kann nicht gelöscht werden.'); } else { $nameStmt = $pdo->prepare('SELECT name FROM kb_categories WHERE id = ?'); $nameStmt->execute([$id]); $catName = $nameStmt->fetchColumn(); $pdo->prepare('DELETE FROM kb_categories WHERE id = ?')->execute([$id]); if (function_exists('dhcm_cache_clear')) dhcm_cache_clear(); audit_log($admin['id'], "KB-Kategorie gelöscht: {$catName}"); flash('success', 'Kategorie gelöscht.'); } redirect('/staff/kb_manage.php'); } if ($action === 'save_article') { $id = $_POST['id'] ?? ''; $title = trim($_POST['title'] ?? ''); $categoryId = (int) ($_POST['category_id'] ?? 0); $body = sanitize_staff_html($_POST['body'] ?? ''); $isPublished = !empty($_POST['is_published']) ? 1 : 0; if ($title === '') $errors[] = 'Bitte einen Titel angeben.'; if (trim(strip_tags($body)) === '') $errors[] = 'Bitte einen Inhalt angeben.'; if (!$errors) { if ($id === '') { $slug = slugify($title); $base = $slug; $i = 2; $check = $pdo->prepare('SELECT COUNT(*) FROM kb_articles WHERE slug = ?'); while (true) { $check->execute([$slug]); if ((int) $check->fetchColumn() === 0) break; $slug = $base . '-' . $i++; } $pdo->prepare('INSERT INTO kb_articles (category_id, title, slug, body, is_published, created_at, updated_at) VALUES (?,?,?,?,?,?,?)') ->execute([$categoryId, $title, $slug, $body, $isPublished, db_now(), db_now()]); audit_log($admin['id'], "KB-Artikel erstellt: {$title}"); flash('success', 'Artikel erstellt.'); } else { $pdo->prepare('UPDATE kb_articles SET category_id=?, title=?, body=?, is_published=?, updated_at=? WHERE id=?') ->execute([$categoryId, $title, $body, $isPublished, db_now(), (int) $id]); audit_log($admin['id'], "KB-Artikel aktualisiert: {$title}"); flash('success', 'Artikel aktualisiert.'); } if (function_exists('dhcm_cache_clear')) dhcm_cache_clear(); redirect('/staff/kb_manage.php'); } } if ($action === 'delete_article') { $id = (int) $_POST['id']; $titleStmt = $pdo->prepare('SELECT title FROM kb_articles WHERE id = ?'); $titleStmt->execute([$id]); $artTitle = $titleStmt->fetchColumn(); $pdo->prepare('DELETE FROM kb_articles WHERE id = ?')->execute([$id]); if (function_exists('dhcm_cache_clear')) dhcm_cache_clear(); audit_log($admin['id'], "KB-Artikel gelöscht: {$artTitle}"); flash('success', 'Artikel gelöscht.'); redirect('/staff/kb_manage.php'); } } $categories = $pdo->query('SELECT * FROM kb_categories ORDER BY sort_order, name')->fetchAll(); $articles = $pdo->query( 'SELECT a.*, c.name AS category_name FROM kb_articles a JOIN kb_categories c ON c.id=a.category_id ORDER BY a.title' )->fetchAll(); $editId = $_GET['edit'] ?? null; $editArticle = null; if ($editId) { $stmt = $pdo->prepare('SELECT * FROM kb_articles WHERE id = ?'); $stmt->execute([$editId]); $editArticle = $stmt->fetch(); } $showForm = isset($_GET['new']) || $editArticle; $pageTitle = 'Wissensdatenbank'; $activePage = 'kb'; require __DIR__ . '/_header.php'; ?>
| Titel | Kategorie | Status | Aufrufe | |
|---|---|---|---|---|
| = e($a['title']) ?> | = e($a['category_name']) ?> | = $a['is_published'] ? 'Live' : 'Entwurf' ?> | = (int) $a['views'] ?> | Bearbeiten · |