Files
geograsim/App/php/api/levels.php
T
Adminator 9a61f55cb1 Atlas: Infrastruktur + Team-Konventionen + Sprachregel Lernarbeit
- Design-System (assets/css/design-system.css) mit 21 Komponenten,
  iPad-Responsive-Breakpoints, Touch-Ziele 36px, Music-Player,
  Glossar-Tooltips
- Templates (sims/template.html + student/teacher-Dashboard)
- Docs: module-interface.md (inkl. 4a Sprachregel, 4b Leichte Sprache,
  4c iPad), content-architecture.md, crash-recovery.md, music-registry.md
- Admin-Infrastruktur: admin-modules.html + api/admin-modules.php
  (Titel, Emoji, Bild, Status, Dauer, Alter pro Modul)
- Inbox-System: _inbox/README.md + _status.md fuer Atlas + Briefings
  an Klima, Glossar, Lehrplan, Fluss
- Zentrale SFX-Pipeline (scripts/generate-sounds.py)
- DALL-E-Bilder: 8 Badges + 5 Glossar-Repraesentationsbilder (Querformat)
- Logo + Inter-Font lokal
- PHP-APIs: admin, glossar, levels, licenses, progress, waypoints,
  assignments, profile, tickets
- Spielsprache entfernt (admin-modules, admin-levels, schueler)
- Landing-Page-Bearbeitungen (Boote sichtbarer, Button-Hintergrund)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 11:51:14 +02:00

72 lines
2.4 KiB
PHP

<?php
/**
* API: Level-Konfiguration (Admin)
* GET /api/levels?game_id=heli_start → Alle Levels eines Spiels
* POST /api/levels {action} → Level erstellen/bearbeiten/löschen
*/
$method = $_SERVER['REQUEST_METHOD'];
$db = Database::get();
if ($method === 'GET') {
$gameId = $_GET['game_id'] ?? '';
if (!$gameId) Response::error('game_id erforderlich');
$levels = $db->fetchAll(
'SELECT id, game_id, level_name, scenario, params, sort_order FROM game_levels WHERE game_id = ? ORDER BY sort_order, id',
[$gameId]
);
// Parse JSON params
foreach ($levels as &$l) {
$l['params'] = json_decode($l['params'], true);
}
Response::ok($levels);
}
if ($method === 'POST') {
// Admin check
Session::start();
$adminId = $_SESSION['admin_id'] ?? null;
$teacherId = Session::teacherId();
if (!$adminId && !$teacherId) Response::error('Nicht autorisiert', 401);
$body = json_decode(file_get_contents('php://input'), true);
$action = $body['action'] ?? '';
if ($action === 'save') {
$gameId = $body['gameId'] ?? '';
$levelName = mb_substr(trim($body['levelName'] ?? ''), 0, 64);
$scenario = $body['scenario'] ?? '';
$params = json_encode($body['params'] ?? []);
$sortOrder = (int)($body['sortOrder'] ?? 0);
$levelId = (int)($body['levelId'] ?? 0);
if (!$gameId || !$levelName || !$scenario) Response::error('gameId, levelName und scenario erforderlich');
if ($levelId) {
$db->execute(
'UPDATE game_levels SET level_name = ?, scenario = ?, params = ?, sort_order = ?, updated_at = NOW() WHERE id = ?',
[$levelName, $scenario, $params, $sortOrder, $levelId]
);
} else {
$db->execute(
'INSERT INTO game_levels (game_id, level_name, scenario, params, sort_order) VALUES (?, ?, ?, ?, ?)',
[$gameId, $levelName, $scenario, $params, $sortOrder]
);
$levelId = (int)$db->lastInsertId();
}
Response::ok(['id' => $levelId]);
}
if ($action === 'delete') {
$levelId = (int)($body['levelId'] ?? 0);
if (!$levelId) Response::error('levelId erforderlich');
$db->execute('DELETE FROM game_levels WHERE id = ?', [$levelId]);
Response::ok();
}
Response::error('Unbekannte Aktion');
}
Response::error('Methode nicht erlaubt', 405);