Files
geograsim/App/pages/wal.php
T
Adminator 1e51ef7def Nachtrag: alle bisher untracked Ordner + hängende Änderungen mit-committen
- Konzept/, didaktik_geografie/, didaktik_simulation/, v2-modules/, v2-platform/
- 12 code-workspace-Files
- STATUS-*.md
- viele M/D/R-Änderungen an bereits getrackten Files
- .gitignore verstärkt: **/.humaninput/, **/secret_keys.txt

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-07-08 02:27:02 +02:00

146 lines
5.4 KiB
PHP

<?php
/**
* Wal — Wrapper
* Laedt sims/wal/game.html und injiziert Base-Path + Session-Mode + Welt-Variante.
*
* Sim: „Die große Wanderung" — Buckelwal Alaska → Hawaii mit drei Welt-Varianten
* (1850 Walfangzeit · 1990 nach Moratorium · 2026 heute). Externe KI (Fable 5)
* baut die Sim — siehe .dontDeploy/briefing-wal-fable5.md.
*
* Welt-Variante (Stufenmapping über current_level wenn mode='teacher_started'):
* 1 → 1850 2 → 1990 3 → 2026
* Sonst (mode='free') wählt die Schüler:in im Sim-Intro selbst.
*
* Stand 2026-06-14: Modul-Status 'entwurf' — externe KI baut die Sim, Atlas
* verkabelt LIVE_PRIMARY_FIELDS + Benchmark-Formel sobald State-Schema steht.
*/
require_once __DIR__ . '/../php/config/app.php';
require_once __DIR__ . '/../php/config/db.php';
$db = getDB();
// ---- Mode-Check (Integrations-Vertrag §6.1) ----
$sessionId = $_COOKIE['ggs_session'] ?? null;
$mode = 'free';
$forcedLevel = null;
$easy = false;
if ($sessionId) {
$stmt = $db->prepare('SELECT class_id, display_name FROM student_sessions WHERE id = ?');
$stmt->execute([$sessionId]);
$sess = $stmt->fetch(PDO::FETCH_ASSOC);
if ($sess && !empty($sess['class_id'])) {
$classId = (int)$sess['class_id'];
$cm = $db->prepare('SELECT mode, current_level FROM class_modules WHERE class_id = ? AND module_id = ?');
$cm->execute([$classId, 'wal']);
$cmRow = $cm->fetch(PDO::FETCH_ASSOC);
if ($cmRow) {
$mode = $cmRow['mode'];
if ($mode === 'teacher_started') $forcedLevel = (int)($cmRow['current_level'] ?? 3);
} else {
$mode = 'locked';
}
// Schüler-Override
$so = $db->prepare(
'SELECT sm.mode FROM student_modules sm
JOIN students s ON s.id = sm.student_id
WHERE s.class_id = ? AND s.display_name = ? AND sm.module_id = ?'
);
$so->execute([$classId, $sess['display_name'], 'wal']);
$soRow = $so->fetch(PDO::FETCH_ASSOC);
if ($soRow) $mode = $soRow['mode'];
// Easy-Flag
$eq = $db->prepare('SELECT easy_language FROM students WHERE class_id = ? AND display_name = ?');
$eq->execute([$classId, $sess['display_name']]);
$eqRow = $eq->fetch(PDO::FETCH_ASSOC);
if ($eqRow) $easy = !empty($eqRow['easy_language']);
}
}
// Welt-Variante aus forcedLevel ableiten. null = Sim fragt im Intro.
$forcedEra = null;
if ($forcedLevel !== null) {
$forcedEra = ($forcedLevel === 1) ? 1850
: (($forcedLevel === 2) ? 1990 : 2026);
}
// Locked-Seite
if ($mode === 'locked') {
http_response_code(403);
header('Content-Type: text/html; charset=utf-8');
$cssHref = BASE_PATH . '/assets/css/design-system.css';
$cockpit = BASE_PATH . '/schueler';
echo <<<HTML
<!DOCTYPE html><html lang="de"><head>
<meta charset="utf-8"><title>Gesperrt · Wal</title>
<link rel="stylesheet" href="{$cssHref}">
<style>body{font-family:system-ui,sans-serif;padding:40px;max-width:640px;margin:auto;color:#333}
h1{color:#1f4b37}.lock-card{background:#f5f3ea;border:1px solid #e2ddd1;padding:24px;border-radius:8px}</style>
</head><body>
<div class="lock-card">
<h1>🔒 Wal ist gesperrt.</h1>
<p>Deine Lehrperson hat dieses Modul für eure Klasse noch nicht freigegeben.</p>
<p>Im <a href="{$cockpit}">Cockpit</a> findest du die derzeit freigegebenen Module.</p>
</div>
</body></html>
HTML;
exit;
}
// ---- Sim-Datei laden ----
$gamePath = __DIR__ . '/../sims/wal/game.html';
if (!is_file($gamePath)) {
http_response_code(503);
header('Content-Type: text/html; charset=utf-8');
$cssHref = BASE_PATH . '/assets/css/design-system.css';
$cockpit = BASE_PATH . '/schueler';
echo <<<HTML
<!DOCTYPE html><html lang="de"><head>
<meta charset="utf-8"><title>In Vorbereitung · Wal</title>
<link rel="stylesheet" href="{$cssHref}">
<style>body{font-family:system-ui,sans-serif;padding:40px;max-width:640px;margin:auto;color:#333}
h1{color:#1f4b37}.wip-card{background:#f5f3ea;border:1px solid #e2ddd1;padding:24px;border-radius:8px}</style>
</head><body>
<div class="wip-card">
<h1>🐋 Die große Wanderung wird gerade gebaut.</h1>
<p>Diese Simulation ist in Vorbereitung. Schau im <a href="{$cockpit}">Cockpit</a>
in die anderen Module.</p>
</div>
</body></html>
HTML;
exit;
}
$html = file_get_contents($gamePath);
$modeJs = json_encode($mode);
$forcedLevelJs = json_encode($forcedLevel);
$forcedEraJs = json_encode($forcedEra);
$easyJs = $easy ? 'true' : 'false';
$sessionIdJs = json_encode($sessionId);
$baseSim = BASE_PATH . '/sims/wal/';
$injection =
"window.WAL_BASE = '$baseSim';\n" .
"window.WAL_SESSION_MODE = {$modeJs};\n" .
"window.WAL_FORCED_LEVEL = {$forcedLevelJs};\n" .
"window.WAL_FORCED_ERA = {$forcedEraJs};\n" . // 1850 | 1990 | 2026 | null
"window.WAL_SESSION_ID = {$sessionIdJs};\n" .
"window.STUDENT_EASY = {$easyJs};\n" .
"window.WAL_API_BASE = '" . BASE_PATH . "/php/api';";
if (strpos($html, '/*__WAL_INJECTION__*/') !== false) {
$html = str_replace('/*__WAL_INJECTION__*/', $injection, $html);
} else {
$html = str_replace('</head>', "<script>$injection</script>\n</head>", $html);
}
// Asset-Pfade umbiegen
$html = preg_replace("/(['\"])assets\//", "$1{$baseSim}assets/", $html);
// Cockpit-Link absolut machen
$html = str_replace('href="/schueler"', 'href="' . cockpit_href() . '"', $html);
if (function_exists('ggs_inject_live')) $html = ggs_inject_live($html, 'wal');
echo $html;