1e51ef7def
- 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>
154 lines
5.9 KiB
PHP
154 lines
5.9 KiB
PHP
<?php
|
|
/**
|
|
* Kofferdetektiv 3D — Plattform-Wrapper
|
|
* Lädt sims/kofferdetektiv/game-3d.html und injiziert Plattform-Kontext.
|
|
*
|
|
* Stufenmapping (current_level → Sim-Stufe):
|
|
* 1 → Länderklasse A (5 Hinweise + 3 + 2)
|
|
* 2 → Länderklasse B (3 Hinweise + 4 + 3)
|
|
* 3 → Länderklasse C (1 Hinweis + 5 + 4)
|
|
*
|
|
* Stand 2026-06-14: Modul-Status 'geplant' beim Anlegen. Wird auf 'beta' gezogen
|
|
* nach erster Test-Welle. 2D-Version (kofferdetektiv-2d.php) folgt später.
|
|
*/
|
|
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;
|
|
$studentName = 'Gast';
|
|
$classId = null;
|
|
|
|
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'];
|
|
$studentName = $sess['display_name'] ?: 'Schüler:in';
|
|
$cm = $db->prepare('SELECT mode, current_level FROM class_modules WHERE class_id = ? AND module_id = ?');
|
|
$cm->execute([$classId, 'kofferdetektiv']);
|
|
$cmRow = $cm->fetch(PDO::FETCH_ASSOC);
|
|
if ($cmRow) {
|
|
$mode = $cmRow['mode'];
|
|
if ($mode === 'teacher_started') $forcedLevel = (int)($cmRow['current_level'] ?? 1);
|
|
} 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'], 'kofferdetektiv']);
|
|
$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']);
|
|
}
|
|
}
|
|
|
|
// 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 · Kofferdetektiv</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>🔒 Kofferdetektiv 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/kofferdetektiv/game-3d.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 · Kofferdetektiv</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>🕵️ Kofferdetektiv wird gerade vorbereitet.</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);
|
|
|
|
$base = BASE_PATH . '/sims/kofferdetektiv/';
|
|
$ggs = [
|
|
'sessionId' => $sessionId ?: '',
|
|
'studentId' => null,
|
|
'studentName' => $studentName,
|
|
'classId' => $classId,
|
|
'simId' => 'kofferdetektiv',
|
|
'simName' => 'Kofferdetektiv',
|
|
'mode' => $mode,
|
|
'forcedLevel' => $forcedLevel,
|
|
'easy' => $easy,
|
|
'baseUrl' => defined('BASE_URL') ? BASE_URL : '',
|
|
'basePath' => BASE_PATH,
|
|
'apiUrl' => BASE_PATH . '/php/api',
|
|
];
|
|
$injection = '<script>'
|
|
. 'window.KD_BASE = ' . json_encode($base) . ';'
|
|
. 'window.__GGS__ = ' . json_encode($ggs, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . ';'
|
|
. '</script>';
|
|
|
|
// Relative Pfade absolut machen — NUR src/href-Attribute, NICHT JS-Strings
|
|
// (fetch-Aufrufe präfixen selbst mit window.KD_BASE).
|
|
$html = preg_replace(
|
|
"/(href|src)=([\"'])(assets\/|data\.js|engine\.js|welt\.html)/",
|
|
"$1=$2{$base}$3",
|
|
$html
|
|
);
|
|
$html = str_replace('</head>', $injection . "\n</head>", $html);
|
|
|
|
// Cockpit-Link absolut machen
|
|
$html = str_replace('href="/schueler"', 'href="' . cockpit_href() . '"', $html);
|
|
|
|
// Plattform-Clients anhängen
|
|
$liveScript = '<script src="' . BASE_PATH . '/assets/js/live-client.js" defer></script>';
|
|
$glossarScript = '<script src="' . BASE_PATH . '/assets/js/glossar-tooltip.js" defer></script>'
|
|
. '<script>window.addEventListener("DOMContentLoaded",function(){'
|
|
. 'if(window.GlossarTooltip)GlossarTooltip.init({apiBase:' . json_encode(BASE_PATH . '/php/api') . ',moduleId:"kofferdetektiv"});'
|
|
. '});</script>';
|
|
$html = str_replace('</body>', $liveScript . "\n" . $glossarScript . "\n</body>", $html);
|
|
|
|
if (function_exists('ggs_inject_live')) $html = ggs_inject_live($html, 'kofferdetektiv');
|
|
|
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
|
header('Content-Type: text/html; charset=UTF-8');
|
|
echo $html;
|