90117fa9de
- New includes/nav.php: sticky site-wide nav with Tools dropdown, Dashboard link, compact language switcher, user identity → /account.php, Log out - New account.php: credits & plan, profile, team, usage sections - New api/corpus-summary.php: JSON endpoint for corpus doc count + last updated - Replaces topbar in layout.php, layout_dashboard.php, and dashboard.php - Fixes hardcoded Norwegian strings in dashboard.php credit cards via dbnToolsT() - Adds 35 new i18n keys across all 4 languages (en/no/uk/pl) in i18n.php - CSS: .dbn-nav navbar + .account-* account page styles in tools.css Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
99 lines
4.0 KiB
PHP
99 lines
4.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
/**
|
|
* Dashboard chrome (minimal). Used by /dashboard/* pages.
|
|
*
|
|
* Page contract:
|
|
* $dashboardPage string — slug for active-state ('index'|'documents'|'document'|'upload'|'chat'|'settings')
|
|
* $dashboardTitle string — H1 for the content area
|
|
* $dashboardLead string? — optional sub-title sentence
|
|
* $extraScripts string[]?— optional extra script srcs (defer-loaded)
|
|
*
|
|
* Lazy-provisions the tenant on first hit; exposes ids to JS as window.DBN_DASHBOARD.
|
|
*/
|
|
|
|
require_once __DIR__ . '/bootstrap.php';
|
|
|
|
if (!dbnToolsIsAuthenticated()) {
|
|
$return = urlencode($_SERVER['REQUEST_URI'] ?? '/dashboard/');
|
|
header('Location: /?return=' . $return);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$dashboardTenant = dbnToolsEnsureDashboardTenant();
|
|
} catch (DbnToolsHttpException $e) {
|
|
http_response_code($e->status);
|
|
echo '<!doctype html><meta charset="utf-8"><title>Dashboard unavailable</title>'
|
|
. '<p style="font-family:sans-serif;max-width:540px;margin:4rem auto;">'
|
|
. htmlspecialchars($e->getMessage())
|
|
. ' <a href="/dashboard/">Try again</a></p>';
|
|
exit;
|
|
}
|
|
|
|
$uiLang = dbnToolsCurrentLanguage();
|
|
$dashboardPage = $dashboardPage ?? 'index';
|
|
$dashboardTitle = $dashboardTitle ?? 'Dashboard';
|
|
$dashboardLead = $dashboardLead ?? '';
|
|
$langPath = strtok((string)($_SERVER['REQUEST_URI'] ?? '/dashboard/'), '?') ?: '/dashboard/';
|
|
|
|
$dashAuthUser = dbnToolsAuthenticatedUser();
|
|
$dashUserDisplay = '';
|
|
if ($dashAuthUser !== null) {
|
|
$email = (string)($dashAuthUser['email'] ?? '');
|
|
$dashUserDisplay = strstr($email, '@', true) ?: $email;
|
|
}
|
|
|
|
$dashboardNav = [
|
|
'index' => ['url' => '/dashboard/', 'label' => 'Oversikt', 'sub' => 'Overview'],
|
|
'documents' => ['url' => '/dashboard/documents.php', 'label' => 'Dokumenter', 'sub' => 'Documents'],
|
|
'upload' => ['url' => '/dashboard/upload.php', 'label' => 'Last opp', 'sub' => 'Upload'],
|
|
'chat' => ['url' => '/dashboard/chat.php', 'label' => 'Spør', 'sub' => 'Ask'],
|
|
'settings' => ['url' => '/dashboard/settings.php', 'label' => 'Innstillinger', 'sub' => 'Settings'],
|
|
];
|
|
?>
|
|
<!doctype html>
|
|
<html lang="<?= htmlspecialchars($uiLang) ?>">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title><?= htmlspecialchars($dashboardTitle) ?> · Min korpus · Do Better Norge</title>
|
|
<link rel="stylesheet" href="/assets/css/tools.css">
|
|
<link rel="stylesheet" href="/assets/css/dashboard.css">
|
|
</head>
|
|
<body data-authenticated="true" data-dashboard-page="<?= htmlspecialchars($dashboardPage) ?>">
|
|
<script>
|
|
window.DBN_TOOLS_AUTHENTICATED = true;
|
|
window.DBN_TOOLS_LANG = <?= json_encode($uiLang, JSON_UNESCAPED_UNICODE) ?>;
|
|
window.DBN_DASHBOARD = {
|
|
clientId: <?= (int)$dashboardTenant['client_id'] ?>,
|
|
clientUserId: <?= (int)$dashboardTenant['client_user_id'] ?>,
|
|
corpusId: <?= (int)$dashboardTenant['corpus_id'] ?>,
|
|
apiBase: '/api/dashboard'
|
|
};
|
|
</script>
|
|
|
|
<?php include __DIR__ . '/nav.php'; ?>
|
|
<div class="dash-shell">
|
|
|
|
<div class="dash-layout">
|
|
<nav class="dash-sidebar" aria-label="Dashboard sections">
|
|
<?php foreach ($dashboardNav as $slug => $item): ?>
|
|
<a href="<?= htmlspecialchars($item['url']) ?>"
|
|
class="dash-sidebar__item<?= $slug === $dashboardPage ? ' is-active' : '' ?>"
|
|
<?= $slug === $dashboardPage ? 'aria-current="page"' : '' ?>>
|
|
<strong><?= htmlspecialchars($item['label']) ?></strong>
|
|
<small><?= htmlspecialchars($item['sub']) ?></small>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</nav>
|
|
|
|
<main class="dash-main" id="dashMain">
|
|
<header class="dash-main__head">
|
|
<h1><?= htmlspecialchars($dashboardTitle) ?></h1>
|
|
<?php if ($dashboardLead !== ''): ?>
|
|
<p class="dash-main__lead"><?= htmlspecialchars($dashboardLead) ?></p>
|
|
<?php endif; ?>
|
|
</header>
|
|
<div class="dash-main__body">
|