Add premium My Case MVP

This commit is contained in:
2026-05-23 10:17:34 +02:00
parent e0aeefc73e
commit 83fc71414f
33 changed files with 1275 additions and 148 deletions
+88 -3
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/FreeTier.php';
require_once __DIR__ . '/includes/CaseStore.php';
require_once __DIR__ . '/includes/CaseResults.php';
if (!dbnToolsIsAuthenticated()) {
header('Location: /?return=' . urlencode('/min-sak.php'));
@@ -21,7 +22,7 @@ $detail = FreeTier::balanceDetail($userId);
$tier = (string)$detail['tier'];
// Free tier: show upgrade gate
if (!in_array($tier, ['light', 'pro', 'pro_plus'], true)) {
if (!FreeTier::isPaidTier($tier)) {
require_once __DIR__ . '/includes/footer.php';
$upgradeUrl = '/pricing.php';
?><!doctype html>
@@ -38,7 +39,7 @@ if (!in_array($tier, ['light', 'pro', 'pro_plus'], true)) {
<li>🧠 Alle verktøy kan referere til din egen sak</li>
<li>🇪🇺 Alt lagres i EU (Tyskland/Finland/Norge)</li>
</ul>
<p style="margin:2rem 0 0;"><a href="<?= htmlspecialchars($upgradeUrl) ?>" style="background:#00205B;color:#fff;padding:1rem 2rem;border-radius:8px;font-weight:700;text-decoration:none;display:inline-block;">Se planer fra 9/mo</a></p>
<p style="margin:2rem 0 0;"><a href="<?= htmlspecialchars($upgradeUrl) ?>" style="background:#00205B;color:#fff;padding:1rem 2rem;border-radius:8px;font-weight:700;text-decoration:none;display:inline-block;">Se planer fra NOK 129/mo</a></p>
</main></body></html><?php
exit;
}
@@ -112,7 +113,12 @@ $pct = $quota > 0 ? min(100, round(($used / $quota) * 100)) : 0;
<div class="ms-card">
<h2>Plan</h2>
<div class="big" style="font-size:1.3rem;">
<?= htmlspecialchars(['light'=>'Light','pro'=>'Pro','pro_plus'=>'Pro+ Familie'][$tier] ?? $tier) ?>
<?= htmlspecialchars(['plus'=>'Plus','pro'=>'Pro Familie'][$tier] ?? ucfirst($tier)) ?>
<?php if (!empty($detail['trial_active'])): ?>
<span style="display:inline-block;background:#fef3c7;color:#92400e;font-size:0.7rem;padding:2px 8px;border-radius:999px;margin-left:0.5rem;vertical-align:middle;">
Prøveperiode · <?= (int)$detail['trial_days_remaining'] ?> dager igjen
</span>
<?php endif; ?>
</div>
<p style="margin:0;color:#6b7280;font-size:0.85rem;">
<a href="/pricing.php">Oppgrader</a> · <a href="/billing.php">Administrer</a>
@@ -155,6 +161,51 @@ $pct = $quota > 0 ? min(100, round(($used / $quota) * 100)) : 0;
</div>
<?php endforeach; endif; ?>
</section>
<?php $results = CaseResults::listForUser($userId, 50); ?>
<h2 style="font-family:'Crimson Pro',serif;margin:2.5rem 0 0.5rem;font-size:1.6rem;color:#00205B;">Lagrede analyser</h2>
<p class="lede" style="margin:0 0 1rem;">Alle resultater fra Korrespondanse, Advokat, BVJ, Dyp analyse, Motstrid og Tidslinje samles her — klar til å gjenåpnes, kjøres på nytt eller eksporteres.</p>
<section class="ms-results" aria-label="Lagrede analyser">
<?php if (empty($results)): ?>
<p class="ms-empty">Ingen lagrede analyser ennå. Kjør et verktøy for å lagre din første.</p>
<?php else: foreach ($results as $r): ?>
<div class="ms-result" data-result-id="<?= (int)$r['id'] ?>"
style="display:flex;align-items:center;gap:1rem;padding:0.95rem 1.25rem;border-bottom:1px solid #f3f4f6;background:#fff;">
<div style="font-size:1.4rem;line-height:1;"><?= htmlspecialchars(CaseResults::toolIcon((string)$r['tool'])) ?></div>
<div style="flex:1;min-width:0;">
<div style="font-weight:600;color:#1f2937;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">
<a href="/case-result.php?id=<?= (int)$r['id'] ?>" style="color:inherit;text-decoration:none;">
<?= htmlspecialchars((string)($r['title'] ?? CaseResults::toolLabel((string)$r['tool']))) ?>
</a>
<?php if (!empty($r['pinned'])): ?>
<span title="Festet" style="color:#c9a84c;margin-left:0.4rem;">★</span>
<?php endif; ?>
</div>
<div style="font-size:0.85rem;color:#6b7280;">
<?= htmlspecialchars(CaseResults::toolLabel((string)$r['tool'])) ?>
· <?= htmlspecialchars(date('j. M Y H:i', strtotime((string)$r['created_at']))) ?>
<?php if (!empty($r['used_case_context'])): ?>
· <span style="background:#dbeafe;color:#1e3a8a;padding:1px 8px;border-radius:999px;font-size:0.75rem;font-weight:600;">Bruk min sak</span>
<?php endif; ?>
</div>
</div>
<div class="ms-result-actions" style="display:flex;gap:0.4rem;">
<button type="button" class="ms-pin" data-id="<?= (int)$r['id'] ?>"
style="background:#f3f4f6;border:none;padding:6px 10px;border-radius:6px;cursor:pointer;font-size:0.85rem;">
<?= !empty($r['pinned']) ? 'Løsne' : 'Fest' ?>
</button>
<a href="/case-result.php?id=<?= (int)$r['id'] ?>"
style="background:#00205B;color:#fff;padding:6px 12px;border-radius:6px;text-decoration:none;font-size:0.85rem;font-weight:600;">
Åpne
</a>
<button type="button" class="ms-result-delete" data-id="<?= (int)$r['id'] ?>"
style="background:#f3f4f6;border:none;padding:6px 10px;border-radius:6px;cursor:pointer;font-size:0.85rem;">
Slett
</button>
</div>
</div>
<?php endforeach; endif; ?>
</section>
</main>
<script>
@@ -222,6 +273,40 @@ $pct = $quota > 0 ? min(100, round(($used / $quota) * 100)) : 0;
} catch (e) { alert('Nettverksfeil: ' + e.message); }
});
});
// Saved analyses: pin / delete
document.querySelectorAll('.ms-pin').forEach(btn => {
btn.addEventListener('click', async () => {
const id = btn.getAttribute('data-id');
try {
const res = await fetch('/api/case/result-action.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'pin', id: parseInt(id, 10) }),
});
const json = await res.json();
if (json.ok) window.location.reload();
else alert(json.error?.message || 'Festing feilet.');
} catch (e) { alert('Nettverksfeil: ' + e.message); }
});
});
document.querySelectorAll('.ms-result-delete').forEach(btn => {
btn.addEventListener('click', async () => {
if (!confirm('Slette denne analysen for godt?')) return;
const id = btn.getAttribute('data-id');
try {
const res = await fetch('/api/case/result-action.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'delete', id: parseInt(id, 10) }),
});
const json = await res.json();
if (json.ok) window.location.reload();
else alert(json.error?.message || 'Sletting feilet.');
} catch (e) { alert('Nettverksfeil: ' + e.message); }
});
});
})();
</script>
</body>