BROOKO icon
BROOKO UK NETWORK
Where code meets creativity & adventure
File viewer

dashboard.php

Type
php
Size
6.27 KB
Modified
15 May
dashboard.php 6.27 KB
<?php
require_once __DIR__ . '/../bootstrap.php';
require_once __DIR__ . '/../lib/feature_modules.php';

requireAuth();

if (!isAdminRole() && !hasPermission('management.access')) {
    http_response_code(403);
    die('Access denied. Management privileges required.');
}

$pageTitle = 'Management Dashboard';

$vehiclesCount = 0;
try { $vehiclesCount = (int)$pdo->query("SELECT COUNT(*) FROM vans WHERE is_active = 1")->fetchColumn(); } catch (Throwable $e) {}

$upcomingEvents = 0;
try {
    $upcomingEvents = (int)$pdo->query("SELECT COUNT(*) FROM calendar_events WHERE start_at >= NOW()")->fetchColumn();
} catch (Throwable $e) {
    try { $upcomingEvents = (int)$pdo->query("SELECT COUNT(*) FROM calendar_events WHERE event_date >= CURDATE()")->fetchColumn(); } catch (Throwable $e2) {}
}

$clockOpen = 0;
try { $clockOpen = (int)$pdo->query("SELECT COUNT(*) FROM time_clock_entries WHERE clock_out_at IS NULL OR status = 'clocked_in'")->fetchColumn(); } catch (Throwable $e) {}

$featureMetrics = function_exists('wp_feature_dashboard_metrics') ? wp_feature_dashboard_metrics() : [
    'rota_today' => 0,
    'holiday_pending' => 0,
    'incidents_open' => 0,
    'contacts_total' => 0,
    'alerts_unread' => 0,
];

$featureHubCards = [
    ['icon' => '🗓️', 'title' => 'Rota', 'count' => $featureMetrics['rota_today'] ?? 0, 'label' => 'today', 'link' => app_url('management/rota'), 'perm' => ['rota.view','rota.edit']],
    ['icon' => '🕒', 'title' => 'Clock Records', 'count' => $clockOpen, 'label' => 'currently clocked in', 'link' => app_url('management/clock'), 'perm' => ['clock.view_team']],
    ['icon' => '🏖️', 'title' => 'Holiday Requests', 'count' => $featureMetrics['holiday_pending'] ?? 0, 'label' => 'pending', 'link' => app_url('management/holidays'), 'perm' => ['holidays.view','holidays.request','holidays.manage']],
    ['icon' => '🚨', 'title' => 'Incidents', 'count' => $featureMetrics['incidents_open'] ?? 0, 'label' => 'open', 'link' => app_url('management/incidents'), 'perm' => ['incidents.view','incidents.create','incidents.manage']],
    ['icon' => '📇', 'title' => 'Contacts', 'count' => $featureMetrics['contacts_total'] ?? 0, 'label' => 'saved', 'link' => app_url('management/contacts'), 'perm' => ['contacts.view','contacts.manage']],
    ['icon' => '📣', 'title' => 'Alerts', 'count' => $featureMetrics['alerts_unread'] ?? 0, 'label' => 'unread', 'link' => app_url('management/alerts'), 'perm' => ['alerts.view','alerts.send']],
    ['icon' => '🚐', 'title' => 'Vehicles', 'count' => $vehiclesCount, 'label' => 'active', 'link' => app_url('management/vehicles'), 'perm' => ['vehicles.view','vehicles.edit']],
];

$extraHead = '<style>
.feature-hub-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:16px;}
.feature-hub-card{display:flex;flex-direction:column;gap:14px;height:100%;padding:18px;border:1px solid var(--border);border-radius:16px;background:rgba(255,255,255,0.02);}
.feature-hub-head{display:flex;justify-content:space-between;align-items:flex-start;gap:12px;}
.feature-hub-icon{width:48px;height:48px;border-radius:14px;display:flex;align-items:center;justify-content:center;background:rgba(255,140,26,.12);font-size:1.4rem;}
.feature-hub-title{margin:0 0 6px 0;font-size:1rem;font-weight:800;}
.feature-hub-meta{color:var(--text-muted);font-size:.92rem;}
.feature-hub-count{font-size:1.55rem;font-weight:900;line-height:1;color:var(--text-main);}
@media (max-width:1100px){.feature-hub-grid{grid-template-columns:repeat(2,minmax(0,1fr));}}
@media (max-width:640px){.feature-hub-grid{grid-template-columns:1fr;}}
</style>';

include __DIR__ . '/../partials/header.php';
?>

<div class="content-header">
    <h1 class="content-title">📊 Management Dashboard</h1>
    <p class="content-subtitle">Day-to-day operations. Staff accounts, permissions, TruTrak setup and system tools are kept under Administration.</p>
</div>

<div class="grid-3">
    <div class="card">
        <div class="d-flex justify-between align-center">
            <div>
                <p class="text-muted" style="margin:0;font-size:.9rem;">Active Vehicles</p>
                <h2 style="margin:8px 0 0 0;font-size:2.2rem;font-weight:900;"><?= (int)$vehiclesCount ?></h2>
            </div>
            <div style="font-size:2.5rem;opacity:.6;">🚐</div>
        </div>
    </div>
    <div class="card">
        <div class="d-flex justify-between align-center">
            <div>
                <p class="text-muted" style="margin:0;font-size:.9rem;">Clocked In</p>
                <h2 style="margin:8px 0 0 0;font-size:2.2rem;font-weight:900;"><?= (int)$clockOpen ?></h2>
            </div>
            <div style="font-size:2.5rem;opacity:.6;">🕒</div>
        </div>
    </div>
    <div class="card">
        <div class="d-flex justify-between align-center">
            <div>
                <p class="text-muted" style="margin:0;font-size:.9rem;">Upcoming Events</p>
                <h2 style="margin:8px 0 0 0;font-size:2.2rem;font-weight:900;"><?= (int)$upcomingEvents ?></h2>
            </div>
            <div style="font-size:2.5rem;opacity:.6;">📅</div>
        </div>
    </div>
</div>

<div class="card" style="margin-top:16px;">
    <div class="card-header">
        <div>
            <h3 class="card-title">Operations</h3>
            <p class="text-muted" style="margin:6px 0 0 0;">Clean operational tabs only. Open Clock Records to see who is clocked in and all shift checks/photos.</p>
        </div>
    </div>
    <div class="feature-hub-grid">
        <?php foreach ($featureHubCards as $card): ?>
            <?php if (!isAdminRole() && !hasAnyPermission($card['perm'])) continue; ?>
            <div class="feature-hub-card">
                <div class="feature-hub-head">
                    <div>
                        <h4 class="feature-hub-title"><?= e($card['title']) ?></h4>
                        <div class="feature-hub-count"><?= (int)$card['count'] ?></div>
                        <div class="feature-hub-meta"><?= e((string)$card['label']) ?></div>
                    </div>
                    <div class="feature-hub-icon"><?= $card['icon'] ?></div>
                </div>
                <div style="margin-top:auto;"><a href="<?= e($card['link']) ?>" class="btn btn-secondary">Open</a></div>
            </div>
        <?php endforeach; ?>
    </div>
</div>

<?php include __DIR__ . '/../partials/footer.php'; ?>