Files
2026-05-17 05:22:06 +03:00

134 lines
6.1 KiB
PHP
Raw Permalink 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
/**
* AegisOne Engineering — Просмотр документации
*
* Доступ: owner (все документы), engineer (только разрешённые владельцем)
*
* GET-параметры:
* ?view=slug — просмотр конкретного документа
*/
require_once __DIR__ . '/../../inc/auth.php';
require_once __DIR__ . '/../../inc/functions.php';
require_once __DIR__ . '/../../inc/docs_functions.php';
$session = auth_require('owner', 'engineer');
$userRole = $session['user_role'];
$userName = $session['user_name'];
$viewSlug = trim($_GET['view'] ?? '');
$docs = get_allowed_docs($userRole);
// Если запрошен просмотр конкретного документа
if ($viewSlug !== '') {
// Проверяем, что документ есть в разрешённых
$allowedSlugs = array();
foreach ($docs as $d) { $allowedSlugs[] = $d['slug']; }
if (!in_array($viewSlug, $allowedSlugs, true)) {
http_response_code(403);
echo '<div class="error-page"><h1>403</h1><p>Документ недоступен для вашей роли.</p><a href="?">← К списку документов</a></div>';
exit;
}
$content = get_doc_content($viewSlug);
if ($content === null) {
echo '<div class="error-page"><h1>404</h1><p>Документ не найден.</p><a href="?">← К списку документов</a></div>';
exit;
}
$title = '';
foreach ($docs as $d) {
if ($d['slug'] === $viewSlug) {
$title = $d['title'];
break;
}
}
require __DIR__ . '/../../inc/header.php';
?>
<div class="doc-viewer">
<div class="doc-viewer__toolbar">
<a href="?" class="btn btn-sm btn-secondary">← Все документы</a>
<span class="doc-viewer__title"><?= htmlspecialchars($title) ?></span>
</div>
<div class="doc-viewer__content markdown-body">
<?= render_markdown_simple($content) ?>
</div>
</div>
<?php
require __DIR__ . '/../../inc/footer.php';
exit;
}
// Список документов
$pageTitle = 'Документация';
require __DIR__ . '/../../inc/header.php';
?>
<div class="docs-list">
<div class="page-header">
<h1>Документация</h1>
<?php if ($userRole === 'owner'): ?>
<p class="page-subtitle">Управляйте доступом инженеров к документам в разделе <a href="/service/pages/owner/docs_section.php">Управление документами</a>.</p>
<?php endif; ?>
</div>
<?php if (empty($docs)): ?>
<div class="empty-state">
<h2>Документов пока нет</h2>
<p>Администратор ещё не добавил документы, или ни один документ не разрешён для вашей роли.</p>
</div>
<?php else: ?>
<div class="docs-grid">
<?php foreach ($docs as $doc): ?>
<a href="?view=<?= urlencode($doc['slug']) ?>" class="doc-card">
<div class="doc-card__icon">
<svg viewBox="0 0 64 64" width="48" height="48"><rect x="16" y="8" width="32" height="48" rx="4" fill="none" stroke="var(--accent)" stroke-width="3"/><line x1="22" y1="20" x2="42" y2="20" stroke="var(--accent)" stroke-width="3"/><line x1="22" y1="30" x2="42" y2="30" stroke="var(--accent)" stroke-width="3"/><line x1="22" y1="40" x2="34" y2="40" stroke="var(--accent)" stroke-width="3"/></svg>
</div>
<div class="doc-card__body">
<h3><?= htmlspecialchars($doc['title']) ?></h3>
<span class="doc-card__meta">Markdown документ</span>
</div>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<style>
.docs-list { padding: 24px; }
.page-header { margin-bottom: 32px; }
.page-header h1 { font-size: 24px; color: var(--text-primary); margin-bottom: 8px; }
.page-subtitle { font-size: 13px; color: var(--text-muted); }
.page-subtitle a { color: var(--accent); }
.docs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.doc-card {
display: flex; align-items: center; gap: 16px; padding: 20px;
background: var(--bg-card); border: 1px solid var(--border);
border-radius: 10px; text-decoration: none; transition: border-color 0.2s, box-shadow 0.2s;
}
.doc-card:hover { border-color: var(--accent); box-shadow: 0 2px 12px rgba(0,173,239,0.1); }
.doc-card__icon { flex-shrink: 0; }
.doc-card__body h3 { font-size: 15px; font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.doc-card__meta { font-size: 12px; color: var(--text-muted); }
.doc-viewer { padding: 24px; max-width: 960px; }
.doc-viewer__toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.doc-viewer__title { font-size: 13px; color: var(--text-muted); }
.doc-viewer__content { line-height: 1.8; font-size: 14px; color: var(--text-primary); }
.markdown-body h1 { font-size: 26px; margin: 32px 0 16px; color: var(--text-primary); }
.markdown-body h2 { font-size: 20px; margin: 24px 0 12px; padding-bottom: 8px; border-bottom: 2px solid var(--accent); color: var(--text-primary); }
.markdown-body h3 { font-size: 16px; margin: 20px 0 10px; color: var(--text-primary); }
.markdown-body p { margin-bottom: 12px; }
.markdown-body ul { margin: 8px 0 16px 24px; }
.markdown-body li { margin-bottom: 4px; }
.markdown-body strong { color: var(--accent); }
.markdown-body table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.markdown-body td, .markdown-body th { border: 1px solid var(--border); padding: 8px 12px; text-align: left; font-size: 13px; color: var(--text-primary); }
.markdown-body th { background: var(--bg-card); font-weight: 600; }
.markdown-body a { color: var(--accent); }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state h2 { font-size: 20px; margin-bottom: 8px; }
</style>
<?php require __DIR__ . '/../../inc/footer.php'; ?>