diff --git a/api/brainstorm.php b/api/brainstorm.php index 94f2d88..ca5b3d0 100644 --- a/api/brainstorm.php +++ b/api/brainstorm.php @@ -368,6 +368,53 @@ try { exit; } + // 5. Brainstormsessie verwijderen (inclusief bijbehorende kaarten) + if ($action === 'delete_session') { + $data = json_decode(file_get_contents('php://input'), true) ?: $_POST; + $sessionId = (int)($data['session_id'] ?? 0); + + if (!$sessionId) { + echo json_encode(['success' => false, 'error' => 'Geen geldig sessie ID opgegeven.']); + exit; + } + + $stmtCheck = $db->prepare("SELECT id, title, created_by_id FROM brainstorm_sessions WHERE id = ?"); + $stmtCheck->execute([$sessionId]); + $session = $stmtCheck->fetch(); + + if (!$session) { + echo json_encode(['success' => false, 'error' => 'Brainstormsessie niet gevonden.']); + exit; + } + + $isCreator = ((int)$session['created_by_id'] === (int)$user['id']); + $isAdmin = ($user['role'] === 'ADMIN'); + + if (!$isCreator && !$isAdmin) { + http_response_code(403); + echo json_encode(['success' => false, 'error' => 'Alleen de maker van deze sessie of een beheerder kan deze verwijderen.']); + exit; + } + + $db->beginTransaction(); + try { + // Verwijder kaarten behorend bij deze sessie + $stmtDelCards = $db->prepare("DELETE FROM brainstorm_cards WHERE session_id = ?"); + $stmtDelCards->execute([$sessionId]); + + // Verwijder de sessie zelf + $stmtDelSession = $db->prepare("DELETE FROM brainstorm_sessions WHERE id = ?"); + $stmtDelSession->execute([$sessionId]); + + $db->commit(); + echo json_encode(['success' => true, 'message' => 'Brainstormsessie en alle bijbehorende kaarten zijn definitief verwijderd.']); + exit; + } catch (Throwable $t) { + if ($db->inTransaction()) $db->rollBack(); + throw $t; + } + } + echo json_encode(['error' => 'Onbekende actie']); } catch (Exception $e) { if ($db->inTransaction()) $db->rollBack(); diff --git a/brainstorm.php b/brainstorm.php index 1a3d694..8414560 100644 --- a/brainstorm.php +++ b/brainstorm.php @@ -95,9 +95,11 @@ require_once __DIR__ . '/includes/header.php'; - - -
+ +
+
@@ -117,16 +119,28 @@ require_once __DIR__ . '/includes/header.php';

-
+
Door -
- Open canvas - +
- +
@@ -192,11 +206,108 @@ require_once __DIR__ . '/includes/header.php';
+ + + diff --git a/brainstorm_canvas.php b/brainstorm_canvas.php index 5f82039..9ea78b6 100644 --- a/brainstorm_canvas.php +++ b/brainstorm_canvas.php @@ -189,6 +189,12 @@ $categories = [ Zet om naar Roadmap + + + + @@ -783,6 +789,37 @@ $categories = [ + + @@ -1745,12 +1782,60 @@ async function submitBreakdownExport() { if (window.lucide) lucide.createIcons(); } } +function promptDeleteCurrentCanvasSession() { + const modal = document.getElementById('deleteCanvasSessionModal'); + if (modal) { + modal.classList.remove('hidden'); + modal.classList.add('flex'); + } + if (window.lucide) lucide.createIcons(); +} + +function closeDeleteCanvasSessionModal() { + const modal = document.getElementById('deleteCanvasSessionModal'); + if (modal) { + modal.classList.add('hidden'); + modal.classList.remove('flex'); + } +} + +async function executeDeleteCanvasSession() { + const btn = document.getElementById('btnConfirmDeleteCanvasSession'); + const origHtml = btn.innerHTML; + btn.disabled = true; + btn.innerHTML = 'Verwijderen...'; + if (window.lucide) lucide.createIcons(); + + try { + const res = await fetch('/api/brainstorm.php?action=delete_session', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ session_id: }) + }); + const data = await res.json(); + + if (data.success) { + window.location.href = '/brainstorm.php'; + } else { + alert('Fout bij verwijderen: ' + (data.error || 'Onbekende fout')); + btn.disabled = false; + btn.innerHTML = origHtml; + if (window.lucide) lucide.createIcons(); + } + } catch (err) { + alert('Netwerkfout bij verwijderen: ' + err.message); + btn.disabled = false; + btn.innerHTML = origHtml; + if (window.lucide) lucide.createIcons(); + } +} document.addEventListener('keydown', (e) => { if (e.key === 'Escape') { closeAddCardModal(); closeConvertModal(); closeAiBreakdownModal(); + closeDeleteCanvasSessionModal(); } }); diff --git a/planner.php b/planner.php index 695e052..82d6f1c 100644 --- a/planner.php +++ b/planner.php @@ -1444,8 +1444,12 @@ for ($h = $startHour; $h <= $endHour; $h++) {