Files
deskhub/DeskHub-Webseite/kb.php
T
2026-10-26 21:19:21 +00:00

100 lines
3.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once __DIR__ . '/includes/bootstrap.php';
if (get_setting('kb_enabled', '1') !== '1') {
flash('error', 'Die Wissensdatenbank ist derzeit nicht verfügbar.');
redirect('/home.php');
}
$pdo = get_db();
$q = trim($_GET['q'] ?? '');
if ($q !== '') {
$loadSearch = static function () use ($pdo, $q): array {
$stmt = $pdo->prepare(
"SELECT a.*, c.name AS category_name FROM kb_articles a
JOIN kb_categories c ON c.id = a.category_id
WHERE a.is_published = 1 AND (a.title LIKE ? OR a.body LIKE ?)
ORDER BY a.views DESC"
);
$like = '%' . $q . '%';
$stmt->execute([$like, $like]);
return $stmt->fetchAll();
};
$articles = function_exists('dhcm_cache_remember')
? dhcm_cache_remember('kb.search.' . $q, $loadSearch)
: $loadSearch();
$categories = [];
} else {
$loadIndex = static function () use ($pdo): array {
$categories = $pdo->query('SELECT * FROM kb_categories ORDER BY sort_order, name')->fetchAll();
$articlesByCategory = [];
foreach ($pdo->query('SELECT * FROM kb_articles WHERE is_published = 1 ORDER BY title')->fetchAll() as $article) {
$articlesByCategory[(int) $article['category_id']][] = $article;
}
return ['categories' => $categories, 'articles' => $articlesByCategory];
};
$kbIndex = function_exists('dhcm_cache_remember')
? dhcm_cache_remember('kb.index', $loadIndex)
: $loadIndex();
$categories = $kbIndex['categories'] ?? [];
$articlesByCategory = $kbIndex['articles'] ?? [];
$articles = null;
}
$pageTitle = 'Wissensdatenbank';
$activePage = 'kb';
$showHeroBanner = true;
$showHeroImage = true;
$heroEyebrow = 'Wissensdatenbank';
$heroTitle = 'Wonach suchen Sie?';
$heroSubtitle = 'Antworten auf häufige Fragen – oft schneller als der Weg über ein Ticket.';
$heroSearchPlaceholder = 'Suchbegriff eingeben …';
$heroSearchValue = $q;
require __DIR__ . '/includes/header_customer.php';
?>
<?php if ($articles !== null): ?>
<h3><?= count($articles) ?> Ergebnis(se) für „<?= e($q) ?>“</h3>
<?php if (!$articles): ?>
<div class="card empty-state">Keine Artikel gefunden. <a href="/ticket_new.php">Erstellen Sie ein Ticket</a>, falls Sie weitere Hilfe benötigen.</div>
<?php endif; ?>
<?php foreach ($articles as $a): ?>
<div class="card kb-result-card">
<a href="/kb_article.php?slug=<?= urlencode($a['slug']) ?>"><h3 style="margin:0"><?= e($a['title']) ?></h3></a>
<span class="muted"><?= e($a['category_name']) ?></span>
</div>
<?php endforeach; ?>
<?php else: ?>
<?php $anyArticles = false; ?>
<div class="kb-category-grid">
<?php foreach ($categories as $i => $cat): ?>
<?php
$arts = $articlesByCategory[(int) $cat['id']] ?? [];
if (!$arts) continue;
$anyArticles = true;
?>
<div class="card kb-category-card">
<div class="kb-category-head">
<div class="icon-badge"><svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="4" width="16" height="16" rx="3"/><path d="M8 9h8M8 13h5"/></svg></div>
<div>
<h3 style="margin:0"><?= e($cat['name']) ?></h3>
<span class="muted" style="font-size:.78rem"><?= count($arts) ?> Artikel</span>
</div>
</div>
<?php foreach ($arts as $a): ?>
<a class="kb-article-link" href="/kb_article.php?slug=<?= urlencode($a['slug']) ?>">
<span><?= e($a['title']) ?></span>
<span class="arrow">→</span>
</a>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
</div>
<?php if (!$anyArticles): ?>
<div class="card empty-state">Es wurden noch keine Artikel veröffentlicht. <a href="/ticket_new.php">Erstellen Sie ein Ticket</a>, falls Sie Hilfe benötigen.</div>
<?php endif; ?>
<?php endif; ?>
<?php require __DIR__ . '/includes/footer_customer.php'; ?>