Files
daveadmin 90117fa9de feat(nav): unified navbar, account page, corpus summary widget, and i18n fixes
- 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>
2026-05-23 19:11:39 +02:00

46 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
/**
* GET /api/corpus-summary.php
* Returns: { doc_count: int, last_updated: string|null }
*
* Auth: SSO session only. Ensures dashboard tenant is provisioned.
*/
require_once __DIR__ . '/../includes/bootstrap.php';
header('Content-Type: application/json');
header('Cache-Control: no-store');
if (!dbnToolsIsAuthenticated() || !dbnToolsIsFreeTier()) {
http_response_code(401);
echo json_encode(['error' => 'auth_required']);
exit;
}
try {
$tenant = dbnToolsEnsureDashboardTenant();
} catch (Throwable $e) {
http_response_code(503);
echo json_encode(['error' => 'tenant_unavailable']);
exit;
}
try {
$db = dbnToolsDb();
$stmt = $db->prepare(
"SELECT COUNT(*) AS doc_count, MAX(created_at) AS last_updated
FROM client_documents
WHERE client_id = ? AND status = 'ready'"
);
$stmt->execute([(int)$tenant['client_id']]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
echo json_encode([
'doc_count' => (int)($row['doc_count'] ?? 0),
'last_updated' => $row['last_updated'] ?? null,
]);
} catch (Throwable $e) {
http_response_code(500);
echo json_encode(['error' => 'db_error']);
}