UPLOAD_TYPES_OFFICE, 'dir' => dirname(__DIR__) . '/fortbildung-materials/', 'naming' => 'hash', 'max_bytes' => 20 * 1024 * 1024, 'messages' => [ 'missing' => 'nofile', 'upload' => 'nofile', 'ext' => 'badext', 'mime' => 'badmime', 'size' => 'toobig', 'move' => 'upload', ], ]); if (!$up['ok']) { header('Location: ../pages/admin.php?tab=fortbildung&err=' . $up['error']); exit; } $safe_name = $up['filename']; $original_name = $up['original_name']; $sort_order = (int)db()->query('SELECT COALESCE(MAX(sort_order), 0) + 10 FROM fortbildung_materials')->fetchColumn(); $now = date('c'); $stmt = db()->prepare( 'INSERT INTO fortbildung_materials (title, description, filename, original_name, sort_order, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?)' ); $stmt->execute([$title, $description, $safe_name, $original_name, $sort_order, $now, $now]); header('Location: ../pages/admin.php?tab=fortbildung&ok=added'); exit; } /* ── Delete ───────────────────────────────────────────────────────────── */ if ($action === 'delete') { $id = (int)($_POST['material_id'] ?? 0); if ($id <= 0) { header('Location: ../pages/admin.php?tab=fortbildung&err=invalid'); exit; } $stmt = db()->prepare('SELECT filename FROM fortbildung_materials WHERE id = ?'); $stmt->execute([$id]); $row = $stmt->fetch(); if ($row) { db()->prepare('DELETE FROM fortbildung_materials WHERE id = ?')->execute([$id]); @unlink(dirname(__DIR__) . '/fortbildung-materials/' . $row['filename']); } header('Location: ../pages/admin.php?tab=fortbildung&ok=deleted'); exit; } header('Location: ../pages/admin.php?tab=fortbildung'); exit;