Atlas+Instanzen: Phase B Integration — Wrapper-Mode-Check + Assessment
Logistik + Heli Wrappers von den Instanzen umgebaut: - Mode-Check (free/teacher_started/locked) direkt aus DB - Forced-Level-Start bei teacher_started - Easy-Flag aus students.easy_language - Locked-Seite mit Sperrhinweis + Cockpit-Link - Assessment-Calls (started/running/completed) in Heli game.html Atlas-Arbeit: - teacher.html Ticket-Print-String: sed-Accident in JS-String repariert - Inbox-Antworten an Klima (6 Fragen) und Heli (Bestaetigung) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+93
-10
@@ -1,22 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* Heli-Spiel — saubere PHP-Seite
|
||||
* Waypoints kommen ausschließlich aus der DB
|
||||
* 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 . '/sim';
|
||||
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, sonst leer
|
||||
// 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 → Script-freundlich weitermachen */ }
|
||||
} catch (Exception $e) { /* Tabelle fehlt -> weitermachen */ }
|
||||
$factsJson = json_encode($factsByKey, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$wpJs = "{\n";
|
||||
@@ -27,7 +97,7 @@ foreach ($rows as $w) {
|
||||
}
|
||||
$wpJs .= "}";
|
||||
|
||||
// POIs für die Karte (nur Basen, Städte, Gipfel)
|
||||
// POIs fuer die Karte (Basen, Staedte, Gipfel)
|
||||
$poisJs = "[\n";
|
||||
foreach ($rows as $w) {
|
||||
if (in_array($w['wp_type'], ['base','city','peak'])) {
|
||||
@@ -38,19 +108,32 @@ foreach ($rows as $w) {
|
||||
}
|
||||
$poisJs .= "]";
|
||||
|
||||
// game.html laden
|
||||
// ---- game.html laden ----
|
||||
$html = file_get_contents(__DIR__ . '/../sims/heli/game.html');
|
||||
|
||||
// Placeholder ersetzen — HELI_BASE aus BASE_PATH ableiten (funktioniert lokal + produktiv)
|
||||
// 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/';
|
||||
$html = str_replace('/*__DB_WAYPOINTS__*/',
|
||||
"window.HELI_BASE = '$base';\nvar WP = $wpJs;\nvar wpLoaded = true;\nvar DB_POIS = $poisJs;\nvar HELI_FACTS = $factsJson;", $html);
|
||||
$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);
|
||||
|
||||
// Leaflet lokal + Tile-Proxy (DSGVO-sicher, kein Drittanbieter-Kontakt aus Browser)
|
||||
// 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';
|
||||
|
||||
Reference in New Issue
Block a user