Webbserver - Love Blomberg

Show sourcecode

The following files exists in this folder. Click to view.

public_html/smartkortet/includes/

auth.php
data.php
functions.php
layout.php

layout.php

87 lines UTF-8 Windows (CRLF)
<?php

declare(strict_types=1);

require_once 
__DIR__ '/functions.php';

function 
appTabs(): array
{
    return [
        
'hem' => ['label' => 'Hem''icon' => 'home'],
        
'historik' => ['label' => 'Historik''icon' => 'history'],
        
'statistik' => ['label' => 'Statistik''icon' => 'chart'],
        
'restauranger' => ['label' => 'Restauranger''icon' => 'shop'],
        
'installningar' => ['label' => 'Inställningar''icon' => 'settings'],
    ];
}

function 
tabIcon(string $icon): string
{
    
$icons = [
        
'home' => '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M240-200h120v-240h240v240h120v-360L480-740 240-560v360Zm-80 80v-480l320-240 320 240v480H520v-240h-80v240H160Zm320-350Z"/></svg>',
        
'history' => '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M480-120q-138 0-240.5-91.5T122-440h82q14 104 92.5 172T480-200q117 0 198.5-81.5T760-480q0-117-81.5-198.5T480-760q-69 0-129 32t-101 88h110v80H120v-240h80v94q51-64 124.5-99T480-840q75 0 140.5 28.5t114 77q48.5 48.5 77 114T840-480q0 75-28.5 140.5t-77 114q-48.5 48.5-114 77T480-120Zm112-192L440-464v-216h80v184l128 128-56 56Z"/></svg>',
        
'chart' => '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M80-120v-80h800v80H80Zm40-120v-280h120v280H120Zm200 0v-480h120v480H320Zm200 0v-360h120v360H520Zm200 0v-600h120v600H720Z"/></svg>',
        
'shop' => '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px"><path d="M280-80v-366q-51-14-85.5-56T160-600v-280h80v280h40v-280h80v280h40v-280h80v280q0 56-34.5 98T360-446v366h-80Zm400 0v-320H560v-280q0-83 58.5-141.5T760-880v800h-80Z"/></svg>',
        
'settings' => '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="m370-80-16-128q-13-5-24.5-12T307-235l-119 50L78-375l103-78q-1-7-1-13.5v-27q0-6.5 1-13.5L78-585l110-190 119 50q11-8 23-15t24-12l16-128h220l16 128q13 5 24.5 12t22.5 15l119-50 110 190-103 78q1 7 1 13.5v27q0 6.5-2 13.5l103 78-110 190-118-50q-11 8-23 15t-24 12L590-80H370Zm70-80h79l14-106q31-8 57.5-23.5T639-327l99 41 39-68-86-65q5-14 7-29.5t2-31.5q0-16-2-31.5t-7-29.5l86-65-39-68-99 42q-22-23-48.5-38.5T533-694l-13-106h-79l-14 106q-31 8-57.5 23.5T321-633l-99-41-39 68 86 64q-5 15-7 30t-2 32q0 16 2 31t7 30l-86 65 39 68 99-42q22 23 48.5 38.5T427-266l13 106Zm42-180q58 0 99-41t41-99q0-58-41-99t-99-41q-59 0-99.5 41T342-480q0 58 40.5 99t99.5 41Zm-2-140Z"/></svg>',
    ];

    return 
$icons[$icon] ?? $icons['home'];
}

function 
renderHeader(string $titlestring $activeTab, array $userstring $theme 'dark'): void
{
    
$tabs appTabs();
    
$csrf csrfToken();
    
$theme $theme === 'light' 'light' 'dark';
    
?>
    <!doctype html>
    <html lang="sv">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
        <meta name="apple-mobile-web-app-title" content="Smartkortet">
        <meta name="theme-color" content="#0b1220">
        <title><?= e($title?> | Smartkortet</title>
        <link rel="preconnect" href="https://fonts.googleapis.com">
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap" rel="stylesheet">
        <link rel="stylesheet" href="<?= e(url('assets/css/style.css')) ?>">
        <link rel="apple-touch-icon" sizes="512x512" href="https://i.imgur.com/KYUBlIE.png">
        <link rel="apple-touch-icon" sizes="180x180" href="https://smartkortet.app/assets/icon-180.png">
        <link rel="icon" href="<?= e(url('assets/icon.svg')) ?>" type="image/svg+xml">
        <link rel="shortcut icon" href="<?= e(url('assets/icon.svg')) ?>" type="image/svg+xml">
        
        <script>
            window.APP_CSRF = <?= json_encode($csrfJSON_UNESCAPED_UNICODE?>;
        </script>
    </head>
    <body data-theme="<?= e($theme?>">
        <main class="app-shell">
            <nav class="tabs card">
                <?php foreach ($tabs as $slug => $tab): ?>
                    <a class="tab-link <?= $slug === $activeTab 'active' '' ?>" href="<?= e(url('index.php')) ?>?tab=<?= e($slug?>">
                        <span class="tab-icon" aria-hidden="true"><?= tabIcon($tab['icon']) ?></span>
                        <span class="tab-label"><?= e($tab['label']) ?></span>
                    </a>
                <?php endforeach; ?>
            </nav>
            <section class="content-grid">
    <?php
}

function 
renderFooter(bool $includeCharts false): void
{
    
?>
            </section>
        </main>
        <?php if ($includeCharts): ?>
            <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
        <?php endif; ?>
        <script src="<?= e(url('assets/js/app.js')) ?>"></script>
    </body>
    </html>
    <?php
}