FinancePlanner/nav.php
2026-05-29 12:00:49 +01:00

85 lines
4.3 KiB
PHP

<?php
// ─────────────────────────────────────────────
// nav.php · Shared navigation partial
// ─────────────────────────────────────────────
require_once __DIR__ . '/auth.php';
function renderHead(string $title): void {
$site = getSetting('site_name', 'Finance Planner');
echo <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{$title} · {$site}</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
HTML;
}
function renderTopBar(string $title, bool $addBtn = false, string $addId = ''): void {
$user = currentUser();
$name = htmlspecialchars($user['display_name'] ?? '');
$btn = $addBtn ? "<button class='topbar-action' id='{$addId}' title='Add'>&#43;</button>" : '';
$initial = $name ? strtoupper(substr(strip_tags($name), 0, 1)) : '';
$avatar = $initial
? "<a href='settings.php' class='topbar-avatar' title='Settings'>{$initial}</a>"
: '';
echo <<<HTML
<header class="topbar">
{$avatar}
<h1>{$title}</h1>
{$btn}
</header>
HTML;
}
function renderNav(string $active): void {
$pages = [
'trends' => ['index.php', 'Trends', trendIcon()],
'transactions' => ['transactions.php', 'Recurring', txIcon()],
'oneoff' => ['oneoff.php', 'One-off', oneoffIcon()],
'debts' => ['debts.php', 'Debts', debtIcon()],
'balances' => ['balances.php', 'Balances', balIcon()],
'accounts' => ['accounts.php', 'Accounts', acctIcon()],
'settings' => ['settings.php', 'Settings', settingsIcon()],
];
if (isAdmin()) {
$pages['admin'] = ['admin.php', 'Admin', adminIcon()];
}
echo '<nav class="nav">';
foreach ($pages as $key => [$href, $label, $icon]) {
$cls = $key === $active ? ' class="active"' : '';
echo "<a href='{$href}'{$cls}>{$icon}<span>{$label}</span></a>";
}
echo '</nav>';
}
// ── Icons ─────────────────────────────────────
function trendIcon(): string {
return '<svg viewBox="0 0 24 24"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/></svg>';
}
function txIcon(): string {
return '<svg viewBox="0 0 24 24"><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="21" y2="18"/><line x1="3" y1="6" x2="3.01" y2="6"/><line x1="3" y1="12" x2="3.01" y2="12"/><line x1="3" y1="18" x2="3.01" y2="18"/></svg>';
}
function balIcon(): string {
return '<svg viewBox="0 0 24 24"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg>';
}
function acctIcon(): string {
return '<svg viewBox="0 0 24 24"><rect x="2" y="5" width="20" height="14" rx="2"/><line x1="2" y1="10" x2="22" y2="10"/></svg>';
}
function debtIcon(): string {
return '<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>';
}
function oneoffIcon(): string {
return '<svg viewBox="0 0 24 24"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>';
}
function settingsIcon(): string {
return '<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>';
}
function adminIcon(): string {
return '<svg viewBox="0 0 24 24"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>';
}