Files
geograsim/App/pages/heli-game.php
T
Adminator 33fb423967 Atlas: Live-View-Feature + Submit-Bug-Fixes + Admin-Styleguide
- Neuer API-Endpoint /api/live (heartbeat / spectator) + DB-Tabelle
  live_sessions + class_modules.paused-Spalte
- Plattform-Live-Client (assets/js/live-client.js): Heartbeat,
  Pause-Overlay, Spectator-Mode bei ?view=teacher
- ggs_inject_live() in _scripts.php als Helper, in alle 11 Sim-Wrapper
  integriert
- Lehrer-Cockpit: tabellarische Klassen-Live-Ansicht pro Sim,
  Pause-Toggle, blinkender Tab-Indikator wenn aktive Sessions
- Submit-Bug erschlagen: progress.php hat jetzt submit_assessment-
  und reflection-Action; saves.php akzeptiert beide Key-Konventionen;
  alle Direkt-Pfad-API-Files mit require_once-Bootstrap
- Avatar-Default: zufaelliger DALL-E-Avatar fuer neue Schueler:innen
- Admin-Styleguide-Seite mit Bildstil, Farb-Tokens, Layout, iPad-Pattern
- Klima 2D + 3D: GGS_LIVE_STATE-Hook, Klima 2D zusaetzlich skipResume
  fuer Klassenaufgaben-Reset
- Test-Lehrer Jakob + 3 Schueler:innen lokal + auf Live angelegt
- Rundbriefe an alle Sim-Instanzen + Submit-Briefe an sonnensystem,
  busfahrt, energiemanager + Glossar-Anfrage zu Grundriess
- Status-Uebergabe in _inbox/zentrale/_status.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 01:20:53 +02:00

150 lines
6.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;
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/';
$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" .
"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;