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>
171 lines
7.0 KiB
PHP
171 lines
7.0 KiB
PHP
<?php
|
|
/**
|
|
* Heli-Spiel — Wrapper
|
|
* Laedt sims/heli/game.html und injiziert Base-Path + DB-Seed + Session-Mode.
|
|
*
|
|
* Integrations-Vertrag §6.1: mode + forcedLevel + easy werden aus der
|
|
* Schueler-Session abgeleitet und ans Frontend uebergeben.
|
|
*/
|
|
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'; // Default: Autodidakt / Demo ohne Persistenz
|
|
$forcedLevel = null;
|
|
$easy = false;
|
|
|
|
// Review-Tool: Direkt-Start einer bestimmten Mission via /heli-game?mission=mX
|
|
// Wird von /heli-missionen verlinkt — nur fuer interne Review, kein User-Feature.
|
|
$forcedMission = null;
|
|
$rawMission = $_GET['mission'] ?? '';
|
|
if (preg_match('/^m[1-9][0-9]?$/', $rawMission)) {
|
|
$forcedMission = $rawMission;
|
|
}
|
|
|
|
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'];
|
|
// Klassen-Default
|
|
$cm = $db->prepare('SELECT mode, current_level FROM class_modules WHERE class_id = ? AND module_id = ?');
|
|
$cm->execute([$classId, 'heli']);
|
|
$cmRow = $cm->fetch(PDO::FETCH_ASSOC);
|
|
if ($cmRow) {
|
|
$mode = $cmRow['mode'];
|
|
if ($mode === 'teacher_started') $forcedLevel = (int)($cmRow['current_level'] ?? 1);
|
|
} else {
|
|
$mode = 'locked'; // kein Klassen-Eintrag = explizit gesperrt
|
|
}
|
|
// Override auf Schueler-Ebene
|
|
$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'], 'heli']);
|
|
$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']);
|
|
}
|
|
// Session ohne class_id = Autodidakt -> bleibt 'free'
|
|
}
|
|
|
|
// 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 · Heli-Navigation</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>🔒 Heli-Navigation ist gesperrt.</h1>
|
|
<p>Deine Lehrkraft 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;
|
|
}
|
|
|
|
// ---- Waypoints aus DB laden ----
|
|
$rows = $db->query("SELECT wp_key, name, lat, lon, wp_type, info FROM geo_waypoints")->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// Facts pro Waypoint (geo + kids) — falls Tabelle existiert
|
|
$factsByKey = [];
|
|
try {
|
|
$factRows = $db->query("SELECT wp_key, kind, text_de FROM geo_waypoint_facts ORDER BY wp_key, kind, display_order")->fetchAll(PDO::FETCH_ASSOC);
|
|
foreach ($factRows as $f) {
|
|
$factsByKey[$f['wp_key']][$f['kind']][] = $f['text_de'];
|
|
}
|
|
} catch (Exception $e) { /* Tabelle fehlt -> weitermachen */ }
|
|
$factsJson = json_encode($factsByKey, JSON_UNESCAPED_UNICODE);
|
|
|
|
$wpJs = "{\n";
|
|
foreach ($rows as $w) {
|
|
$key = $w['wp_key'];
|
|
$name = addslashes($w['name']);
|
|
$wpJs .= " '$key':{lat:{$w['lat']},lon:{$w['lon']},name:'$name'},\n";
|
|
}
|
|
$wpJs .= "}";
|
|
|
|
// POIs fuer die Karte (Basen, Staedte, Gipfel)
|
|
$poisJs = "[\n";
|
|
foreach ($rows as $w) {
|
|
if (in_array($w['wp_type'], ['base','city','peak'])) {
|
|
$name = addslashes($w['name']);
|
|
$info = addslashes($w['info'] ?? '');
|
|
$poisJs .= " {key:'{$w['wp_key']}',name:'$name',lat:{$w['lat']},lon:{$w['lon']},type:'{$w['wp_type']}',info:'$info'},\n";
|
|
}
|
|
}
|
|
$poisJs .= "]";
|
|
|
|
// ---- game.html laden ----
|
|
$html = file_get_contents(__DIR__ . '/../sims/heli/game.html');
|
|
|
|
// Session-Werte fuer JS
|
|
$modeJs = json_encode($mode);
|
|
$forcedLevelJs = json_encode($forcedLevel);
|
|
$easyJs = $easy ? 'true' : 'false';
|
|
$sessionIdJs = json_encode($sessionId);
|
|
|
|
$base = BASE_PATH . '/sims/heli/';
|
|
|
|
// === Heli-Stationen + Pool-Kennzeichen aus zentraler JSON ===
|
|
// (rechtssichere Anzeige ohne Markennamen, siehe docs/konzept-heli-kennzeichen.md)
|
|
$stationsPath = __DIR__ . '/../sims/heli/data/heli-stations.json';
|
|
$stationsJson = file_exists($stationsPath) ? file_get_contents($stationsPath) : '{}';
|
|
|
|
// === Mission-Briefings (Phase 1.5) aus zentraler JSON ===
|
|
$briefingsPath = __DIR__ . '/../sims/heli/data/briefings.json';
|
|
$briefingsJson = file_exists($briefingsPath) ? file_get_contents($briefingsPath) : '{}';
|
|
|
|
$injection =
|
|
"window.HELI_BASE = '$base';\n" .
|
|
"window.HELI_SESSION_MODE = {$modeJs};\n" .
|
|
"window.HELI_FORCED_LEVEL = {$forcedLevelJs};\n" .
|
|
"window.HELI_SESSION_ID = {$sessionIdJs};\n" .
|
|
"window.STUDENT_EASY = {$easyJs};\n" .
|
|
"window.HELI_API_BASE = '" . BASE_PATH . "/api';\n" .
|
|
"window.HELI_STATIONS = $stationsJson;\n" .
|
|
"window.HELI_BRIEFINGS = $briefingsJson;\n" .
|
|
"window.HELI_FORCED_MISSION = " . json_encode($forcedMission) . ";\n" .
|
|
"var WP = $wpJs;\nvar wpLoaded = true;\nvar DB_POIS = $poisJs;\nvar HELI_FACTS = $factsJson;";
|
|
|
|
$html = str_replace('/*__DB_WAYPOINTS__*/', $injection, $html);
|
|
|
|
// Head-Asset-Pfade auf BASE_PATH umbiegen (relative ../../ greift unter /heli-game-Route falsch)
|
|
$html = str_replace('href="../../favicon-96x96.png"', 'href="' . BASE_PATH . '/favicon-96x96.png"', $html);
|
|
$html = str_replace('href="../../assets/fonts/inter.css"', 'href="' . BASE_PATH . '/assets/fonts/inter.css"', $html);
|
|
$html = str_replace('href="../../assets/css/design-system.css"', 'href="' . BASE_PATH . '/assets/css/design-system.css"', $html);
|
|
|
|
// Leaflet lokal + Tile-Proxy (DSGVO-sicher)
|
|
$leafletCss = BASE_PATH . '/assets/vendor/leaflet/leaflet.css';
|
|
$leafletJs = BASE_PATH . '/assets/vendor/leaflet/leaflet.js';
|
|
$tileProxy = BASE_PATH . '/php/tile-proxy.php';
|
|
$html = strtr($html, [
|
|
'https://unpkg.com/leaflet@1.9.4/dist/leaflet.css' => $leafletCss,
|
|
'https://unpkg.com/leaflet@1.9.4/dist/leaflet.js' => $leafletJs,
|
|
"'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'" => "'{$tileProxy}?z={z}&x={x}&y={y}&p=osm'",
|
|
]);
|
|
$html = str_replace('href="/schueler"', 'href="' . cockpit_href() . '"', $html);
|
|
|
|
if (function_exists('ggs_inject_live')) $html = ggs_inject_live($html, 'heli');
|
|
echo $html;
|