Files
imf-sms-dashboard/web/index.html
T
2026-06-06 00:03:51 +01:00

345 lines
15 KiB
HTML

<!doctype html>
<html lang="en" data-bs-theme="dark">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Home — IMFestival SMS Dashboard</title>
<link href="assets/vendor/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" rel="stylesheet"
crossorigin="anonymous">
<link href="assets/css/dashboard.css" rel="stylesheet">
</head>
<body>
<!-- ─── Mobile top bar ─── -->
<div class="topbar">
<button class="hamburger" data-bs-toggle="offcanvas" data-bs-target="#mobileSidebar" aria-label="Open menu">
<i class="fa-solid fa-bars"></i>
</button>
<span style="font-weight:600;font-size:0.95rem;">SMS Dashboard</span>
</div>
<!-- ─── Mobile offcanvas sidebar ─── -->
<div class="offcanvas offcanvas-start" tabindex="-1" id="mobileSidebar">
<div class="offcanvas-header">
<div class="brand"
style="border:none;margin:0;padding:0;flex-direction:column;align-items:flex-start;gap:0.5rem;">
<span>IMFestival SMS Dashboard</span>
</div>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body p-3">
<nav class="d-flex flex-column gap-1">
<a href="index.html" class="nav-link-custom active">
<i class="fa-solid fa-house fa-fw"></i>
Home
</a>
<a href="attendees.html" class="nav-link-custom">
<i class="fa-solid fa-users fa-fw"></i>
Attendees
</a>
<a href="templates.html" class="nav-link-custom">
<i class="fa-solid fa-comment-sms fa-fw"></i>
SMS Templates
</a>
<a href="schedule.html" class="nav-link-custom">
<i class="fa-solid fa-calendar-days fa-fw"></i>
Schedule
</a>
<a href="delivery-log.html" class="nav-link-custom">
<i class="fa-solid fa-list-check fa-fw"></i>
Delivery Log
</a>
</nav>
</div>
</div>
<!-- ─── Desktop sidebar ─── -->
<div class="sidebar">
<div class="brand">
<span style="margin: 0 auto;">IMFestival SMS Dashboard</span>
</div>
<nav class="d-flex flex-column gap-1 mt-2">
<a href="index.html" class="nav-link-custom active">
<i class="fa-solid fa-house fa-fw"></i>
Home
</a>
<a href="attendees.html" class="nav-link-custom">
<i class="fa-solid fa-users fa-fw"></i>
Attendees
</a>
<a href="templates.html" class="nav-link-custom">
<i class="fa-solid fa-comment-sms fa-fw"></i>
SMS Templates
</a>
<a href="schedule.html" class="nav-link-custom">
<i class="fa-solid fa-calendar-days fa-fw"></i>
Schedule
</a>
<a href="delivery-log.html" class="nav-link-custom">
<i class="fa-solid fa-list-check fa-fw"></i>
Delivery Log
</a>
</nav>
<div class="mt-auto pt-3" style="border-top:1px solid var(--border);">
<div class="nav-link-custom" style="cursor:default;">
<i class="fa-solid fa-circle-user fa-fw"></i>
<span style="font-size:0.82rem;">Admin</span>
</div>
</div>
</div>
<!-- ─── Main content ─── -->
<div class="main">
<div class="main-inner">
<div id="sandboxBanner" class="alert alert-warning"
style="display:none;font-size:0.85rem;font-weight:600;text-align:center;">
<i class="fa-solid fa-flask me-1"></i> Sandbox mode is active — texts are tagged as a test and excluded from
cost calculations.
</div>
<div class="page-header">
<h1>Overview</h1>
<p>Welcome back. Here's what's happening today.</p>
</div>
<!-- Stats -->
<div class="row g-3 mb-4">
<div class="col-12 col-sm-3">
<div class="stat-card border-0">
<div class="stat-label">Attendees</div>
<div class="stat-value" id="stat-attendees"></div>
</div>
</div>
<div class="col-12 col-sm-3">
<div class="stat-card border-0">
<div class="stat-label">Total Sent</div>
<div class="stat-value" id="stat-sent"></div>
</div>
</div>
<div class="col-12 col-sm-3">
<div class="stat-card border-0">
<div class="stat-label">Success Rate</div>
<div class="stat-value" id="stat-rate"></div>
</div>
</div>
<div class="col-12 col-sm-3">
<div class="stat-card border-0">
<div class="stat-label">Estimated Cost</div>
<div class="stat-value" id="stat-cost"></div>
</div>
</div>
</div>
<!-- Quick links -->
<div class="row g-3">
<!-- Send SMS Now — primary action card, full width -->
<div class="col-12">
<a href="send-now.html" class="card p-4 text-decoration-none d-flex flex-row align-items-center gap-3"
style="border-color:var(--accent);background:linear-gradient(135deg,#1a2540 0%,var(--bg-card) 100%);">
<i class="fa-solid fa-paper-plane fa-lg" style="color:var(--accent);"></i>
<div>
<div style="font-weight:600;color:var(--text-primary);">Send SMS Now</div>
<div style="font-size:0.82rem;color:var(--text-muted);">Compose and send a one-off message instantly</div>
</div>
<i class="fa-solid fa-chevron-right ms-auto" style="color:var(--text-muted);font-size:0.8rem;"></i>
</a>
</div>
<div class="col-12 col-sm-6">
<a href="attendees.html"
class="card p-4 border-0 text-decoration-none d-flex flex-row align-items-center gap-3">
<i class="fa-solid fa-users fa-lg" style="color:var(--accent);"></i>
<div>
<div style="font-weight:600;color:var(--text-primary);">Attendees</div>
<div style="font-size:0.82rem;color:var(--text-muted);">Upload and manage participant CSV</div>
</div>
<i class="fa-solid fa-chevron-right ms-auto" style="color:var(--text-muted);font-size:0.8rem;"></i>
</a>
</div>
<div class="col-12 col-sm-6">
<a href="templates.html"
class="card p-4 border-0 text-decoration-none d-flex flex-row align-items-center gap-3">
<i class="fa-solid fa-comment-sms fa-lg" style="color:var(--accent);"></i>
<div>
<div style="font-weight:600;color:var(--text-primary);">SMS Templates</div>
<div style="font-size:0.82rem;color:var(--text-muted);">Create and preview message templates</div>
</div>
<i class="fa-solid fa-chevron-right ms-auto" style="color:var(--text-muted);font-size:0.8rem;"></i>
</a>
</div>
<div class="col-12 col-sm-6">
<a href="schedule.html"
class="card p-4 border-0 text-decoration-none d-flex flex-row align-items-center gap-3">
<i class="fa-solid fa-calendar-days fa-lg" style="color:var(--accent);"></i>
<div>
<div style="font-weight:600;color:var(--text-primary);">Schedule</div>
<div style="font-size:0.82rem;color:var(--text-muted);">Set send rules and timing</div>
</div>
<i class="fa-solid fa-chevron-right ms-auto" style="color:var(--text-muted);font-size:0.8rem;"></i>
</a>
</div>
<div class="col-12 col-sm-6">
<a href="delivery-log.html"
class="card p-4 border-0 text-decoration-none d-flex flex-row align-items-center gap-3">
<i class="fa-solid fa-list-check fa-lg" style="color:var(--accent);"></i>
<div>
<div style="font-weight:600;color:var(--text-primary);">Delivery Log</div>
<div style="font-size:0.82rem;color:var(--text-muted);">Track sent, delivered and failed messages</div>
</div>
<i class="fa-solid fa-chevron-right ms-auto" style="color:var(--text-muted);font-size:0.8rem;"></i>
</a>
</div>
<!-- Start Admin Settings -->
<hr class="mt-4 mb-3">
<div class="page-header mt-0 mb-0">
<p><em>You're seeing these options because you're an admin. Proceed with caution!</em></p>
</div>
<div class="col-12 col-sm-6">
<a href="admin.html" class="card p-4 border-0 text-decoration-none d-flex flex-row align-items-center gap-3">
<i class="fa-solid fa-user-shield fa-lg" style="color:var(--accent);"></i>
<div>
<div style="font-weight:600;color:var(--text-primary);">Admin</div>
<div style="font-size:0.82rem;color:var(--text-muted);">Sandbox mode and data management controls</div>
</div>
<i class="fa-solid fa-chevron-right ms-auto" style="color:var(--text-muted);font-size:0.8rem;"></i>
</a>
</div>
<div class="col-12 col-sm-6">
<button type="button" onclick="openApiKeyModal()" data-bs-toggle="modal" data-bs-target="#apiKeyModal"
class="card p-4 text-decoration-none d-flex flex-row align-items-center gap-3 w-100 border-0 text-start"
style="cursor:pointer;">
<i class="fa-solid fa-cog fa-lg" style="color:var(--accent);"></i>
<div>
<div style="font-weight:600;color:var(--text-primary);">Clickatell Settings</div>
<div style="font-size:0.82rem;color:var(--text-muted);">Change Clickatell API key and cost per SMS</div>
</div>
<i class="fa-solid fa-chevron-right ms-auto" style="color:var(--text-muted);font-size:0.8rem;"></i>
</button>
</div>
</div>
</div>
</div>
<!-- ─── Clickatell API Key modal ─── -->
<div class="modal fade" id="apiKeyModal" tabindex="-1" aria-labelledby="apiKeyModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="apiKeyModalLabel">
<i class="fa-solid fa-gear fa-fw me-2"></i>Clickatell Settings
</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p id="apiKeyStatus" class="text-muted mb-3" style="font-size:0.85rem;">Checking…</p>
<div class="mb-3">
<label for="apiKeyInput" class="form-label">API Key</label>
<input type="password" class="form-control" id="apiKeyInput" placeholder="Enter new API key"
autocomplete="off">
</div>
<div class="mb-1">
<label for="costPerSmsInput" class="form-label">Cost per SMS (£)</label>
<input type="number" class="form-control" id="costPerSmsInput" placeholder="e.g. 0.04849" step="0.00001"
min="0">
</div>
<div id="apiKeyError" class="text-danger mt-2" style="font-size:0.82rem;"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="apiKeySaveBtn" onclick="saveApiKey()">
<i class="fa-solid fa-floppy-disk fa-fw"></i> Save
</button>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
crossorigin="anonymous"></script>
<script>
function esc(str) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
async function openApiKeyModal() {
document.getElementById('apiKeyInput').value = '';
document.getElementById('apiKeyError').textContent = '';
const statusEl = document.getElementById('apiKeyStatus');
statusEl.textContent = 'Checking…';
try {
const [keyData, costData] = await Promise.all([
fetch('/api/settings.php?key=clickatell_api_key').then(r => r.json()),
fetch('/api/settings.php?key=clickatell_cost_per_sms').then(r => r.json()),
]);
statusEl.innerHTML = keyData.set
? `API key set: <code>${esc(keyData.hint)}</code> — enter a new key to replace it.`
: '<span class="text-warning">No API key configured.</span> Enter one below to enable SMS sending.';
document.getElementById('costPerSmsInput').value = costData.value ?? '0.04849';
} catch {
statusEl.textContent = 'Could not load current settings.';
}
}
async function saveApiKey() {
const key = document.getElementById('apiKeyInput').value.trim();
const cost = document.getElementById('costPerSmsInput').value.trim();
const errEl = document.getElementById('apiKeyError');
const btn = document.getElementById('apiKeySaveBtn');
errEl.textContent = '';
if (!key && !cost) { errEl.textContent = 'Please enter at least one value.'; return; }
const costNum = parseFloat(cost);
if (cost && (isNaN(costNum) || costNum < 0)) { errEl.textContent = 'Cost must be a positive number.'; return; }
btn.disabled = true;
try {
const saves = [];
if (key) saves.push(fetch('/api/settings.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ key: 'clickatell_api_key', value: key }) }));
if (cost) saves.push(fetch('/api/settings.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ key: 'clickatell_cost_per_sms', value: cost }) }));
const results = await Promise.all(saves);
for (const res of results) { if (!res.ok) throw new Error((await res.json()).error ?? 'Save failed'); }
bootstrap.Modal.getInstance(document.getElementById('apiKeyModal')).hide();
loadStats();
} catch (e) {
errEl.textContent = e.message;
} finally {
btn.disabled = false;
}
}
async function loadStats() {
try {
const [att, log] = await Promise.all([
fetch('/api/attendees.php').then(r => r.json()),
fetch('/api/delivery-log.php').then(r => r.json()),
]);
document.getElementById('stat-attendees').textContent = att.total ?? '—';
document.getElementById('stat-sent').textContent = log.stats?.total_sent ?? '—';
const rate = log.stats?.success_rate;
document.getElementById('stat-rate').textContent = rate != null ? rate + '%' : '—';
const sent = log.stats?.total_sent;
const costPerSms = parseFloat((await fetch('/api/settings.php?key=clickatell_cost_per_sms').then(r => r.json())).value ?? '0.04849');
document.getElementById('stat-cost').textContent = sent != null
? '£' + (sent * costPerSms).toFixed(2)
: '—';
} catch { /* DB unavailable — stats stay as dashes */ }
}
loadStats();
</script>
<script>
(async function () {
try {
const d = await fetch('/api/admin.php').then(r => r.json());
document.getElementById('sandboxBanner').style.display = d.sandbox_mode ? '' : 'none';
} catch { }
}());
</script>
</body>
</html>