0) { $stmt = $pdo->prepare("UPDATE blog_posts SET title=?, slug=?, content=?, excerpt=?, category=?, status=? WHERE id=?"); $stmt->execute([$title, $slug, $content, $excerpt, $category, $status, $id]); $message = 'Пост обновлён.'; } else { $stmt = $pdo->prepare("INSERT INTO blog_posts (title, slug, content, excerpt, category, author_id, status, published_at) VALUES (?,?,?,?,?,?,?,?)"); $published = $status === 'published' ? date('Y-m-d H:i:s') : null; $stmt->execute([$title, $slug, $content, $excerpt, $category, $session['user_id'], $status, $published]); $message = 'Пост создан.'; } auth_log($session['user_id'], 'blog_save', "Title: $title"); } catch (\PDOException $e) { $message = 'Ошибка: ' . ($e->getCode() === '23000' ? 'Такой slug уже существует.' : $e->getMessage()); } } } if (isset($_GET['delete'])) { $id = (int)$_GET['delete']; if (auth_csrf_verify($_GET['csrf'] ?? '')) { $pdo->prepare("DELETE FROM blog_posts WHERE id=?")->execute([$id]); $message = 'Пост удалён.'; } } if (isset($_GET['publish'])) { $id = (int)$_GET['publish']; if (auth_csrf_verify($_GET['csrf'] ?? '')) { $pdo->prepare("UPDATE blog_posts SET status='published', published_at=NOW() WHERE id=?")->execute([$id]); $message = 'Пост опубликован.'; } } $editPost = null; if (isset($_GET['edit'])) { $stmt = $pdo->prepare("SELECT * FROM blog_posts WHERE id=?"); $stmt->execute([(int)$_GET['edit']]); $editPost = $stmt->fetch(); } $posts = $pdo->query("SELECT bp.*, u.full_name as author_name FROM blog_posts bp LEFT JOIN users u ON u.id=bp.author_id ORDER BY bp.created_at DESC")->fetchAll(); $csrf = auth_csrf_token(); $categories = [ 'audit' => 'Аудит', 'sla' => 'SLA', 'incident' => 'Инциденты', 'supervision' => 'Технадзор', 'documentation' => 'Документация', 'risk' => 'Риск-инжиниринг', 'cases' => 'Кейсы', ]; require __DIR__ . '/../../inc/header.php'; ?>
| Заголовок | Категория | Автор | Статус | Дата | Действия |
|---|---|---|---|---|---|
| Нет статей | |||||
| = htmlspecialchars($p['title']) ?> | = $categories[$p['category']] ?? $p['category'] ?> | = htmlspecialchars($p['author_name'] ?: '—') ?> | = $p['status'] ?> | = $p['published_at'] ? date('d.m.Y', strtotime($p['published_at'])) : date('d.m.Y', strtotime($p['created_at'])) ?> | 👁️ ✏️ 📢 🗑️ |