33dc5406b2
- api/logout.php: destroys session + clears cookie, redirects to / - api/guest-session.php: sets guest flag, lets users explore without account - layout.php: removes hard PHP redirect; authenticated users see email + "Logg ut" in topbar; guests see guest banner (sticky, dismissible) and auth gate modal (dismissible via localStorage) instead of redirect - layout_footer.php: injects auth gate modal + JS for banner/modal dismiss - layout_dashboard.php: adds username + "Logg ut" to dash-topbar - index.php: adds "Utforsk uten konto" link under primary login CTA - tools.css: .guest-banner, .auth-gate-*, .topbar-user, .dash-topbar__user Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
116 lines
4.9 KiB
PHP
116 lines
4.9 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>
|
|
|
|
<div class="dash-shell">
|
|
<header class="dash-topbar" role="banner">
|
|
<a class="dash-brand" href="/dashboard/">
|
|
<span class="dash-brand__mark">⚖</span>
|
|
<span class="dash-brand__text">
|
|
<strong>Min korpus</strong>
|
|
<small>Do Better Norge</small>
|
|
</span>
|
|
</a>
|
|
<nav class="dash-topbar__tools" aria-label="Tools">
|
|
<a href="/dashboard.php" class="dash-topbar__link">← Tilbake til verktøy</a>
|
|
</nav>
|
|
<div class="dash-topbar__user">
|
|
<?php if ($dashUserDisplay !== ''): ?>
|
|
<span class="dash-topbar__username" title="<?= htmlspecialchars($dashAuthUser['email'] ?? '') ?>"><?= htmlspecialchars($dashUserDisplay) ?></span>
|
|
<?php endif; ?>
|
|
<a href="/api/logout.php" class="dash-topbar__logout">Logg ut</a>
|
|
</div>
|
|
</header>
|
|
|
|
<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">
|