33fb423967
- 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>
161 lines
7.2 KiB
PHP
161 lines
7.2 KiB
PHP
<?php
|
|
/**
|
|
* Logistik Europa — Wrapper
|
|
* Lädt sims/logistik/game.html und injiziert Base-Path + Seed-Daten.
|
|
* URL: http://localhost/geograsim/App/logistik
|
|
*/
|
|
require_once __DIR__ . '/../php/config/app.php';
|
|
require_once __DIR__ . '/../php/config/db.php';
|
|
|
|
$db = getDB();
|
|
|
|
// Module-Info aus DB
|
|
$mi = $db->query("SELECT title FROM module_info WHERE module_id='logistik'")->fetch(PDO::FETCH_ASSOC);
|
|
$simName = $mi['title'] ?? 'Logistik Europa';
|
|
|
|
// ---- Mode-Check (Integrations-Vertrag §6.1) ----
|
|
// Liefert: $mode ('free' | 'teacher_started' | 'locked'), $forcedLevel, $easy
|
|
$sessionId = $_COOKIE['ggs_session'] ?? null;
|
|
$mode = 'free'; // Default: Autodidakt / oeffentliche Demo
|
|
$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, 'logistik']);
|
|
$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
|
|
}
|
|
// Individueller 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'], 'logistik']);
|
|
$soRow = $so->fetch(PDO::FETCH_ASSOC);
|
|
if ($soRow) $mode = $soRow['mode'];
|
|
// Easy-Flag aus students
|
|
$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 bei 'free'
|
|
}
|
|
|
|
// Locked-Seite: kurze Sperrmeldung statt game.html
|
|
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 · Logistik Europa</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>🔒 Logistik Europa ist gesperrt.</h1>
|
|
<p>Deine Lehrkraft hat dieses Modul für eure Klasse noch nicht freigegeben.</p>
|
|
<p>Falls du keinen Klassen-Beitritt brauchst, kannst du im <a href="{$cockpit}">Cockpit</a>
|
|
zurück und ein anderes frei verfügbares Modul starten.</p>
|
|
</div>
|
|
</body></html>
|
|
HTML;
|
|
exit;
|
|
}
|
|
|
|
// Seed-Dateien aus App/assets/data/ einlesen (werden von Logistik-Instanz gefüllt)
|
|
$readSeed = function (string $file): string {
|
|
$path = __DIR__ . '/../assets/data/' . $file;
|
|
if (!is_file($path)) return '[]';
|
|
$raw = file_get_contents($path);
|
|
return $raw !== false && trim($raw) !== '' ? $raw : '[]';
|
|
};
|
|
|
|
$locations = $readSeed('lg-locations.json');
|
|
$vehicleTypes = $readSeed('lg-vehicle-types.json');
|
|
$cargoTypes = $readSeed('lg-cargo-types.json');
|
|
$railnet = $readSeed('lg-railnet.json');
|
|
$roadnet = $readSeed('lg-roadnet.json');
|
|
$routesOsm = $readSeed('lg-routes-osm.json');
|
|
$contractTemplates = $readSeed('lg-contract-templates.json');
|
|
|
|
// Level-Config aus game_levels (params = JSON). Schema: game_id, level_name, sort_order, params
|
|
$levels = $db->query("SELECT level_name, sort_order, params FROM game_levels WHERE game_id='logistik' ORDER BY sort_order")->fetchAll(PDO::FETCH_ASSOC);
|
|
$levelsJson = json_encode(array_map(
|
|
fn($r) => ['level' => (int)$r['sort_order'], 'name' => $r['level_name'], 'params' => json_decode($r['params'] ?? '{}', true)],
|
|
$levels
|
|
), JSON_UNESCAPED_UNICODE);
|
|
|
|
$html = file_get_contents(__DIR__ . '/../sims/logistik/game.html');
|
|
$base = BASE_PATH . '/sims/logistik/';
|
|
|
|
$modeJs = json_encode($mode);
|
|
$forcedLevelJs = json_encode($forcedLevel);
|
|
$easyJs = $easy ? 'true' : 'false';
|
|
|
|
$injection = <<<JS
|
|
window.LOGISTIK_BASE = '{$base}';
|
|
window.LOGISTIK_SIM_NAME = '{$simName}';
|
|
window.LOGISTIK_SEEDS = {
|
|
locations: {$locations},
|
|
vehicleTypes: {$vehicleTypes},
|
|
cargoTypes: {$cargoTypes},
|
|
railnet: {$railnet},
|
|
roadnet: {$roadnet},
|
|
routesOsm: {$routesOsm},
|
|
contractTemplates: {$contractTemplates}
|
|
};
|
|
window.LOGISTIK_LEVELS = {$levelsJson};
|
|
// Integrations-Vertrag: mode + forcedLevel + easy aus Session
|
|
window.LOGISTIK_SESSION_MODE = {$modeJs};
|
|
window.LOGISTIK_FORCED_LEVEL = {$forcedLevelJs};
|
|
window.LOGISTIK_EASY = {$easyJs};
|
|
window.STUDENT_EASY = {$easyJs};
|
|
JS;
|
|
|
|
$html = str_replace('/*__LOGISTIK_INJECTION__*/', $injection, $html);
|
|
|
|
// Relative Asset-Pfade aus game.html auf BASE_PATH/LOGISTIK_BASE umbiegen
|
|
// (unter /App/logistik würden ../../ falsch aufgelöst — siehe heli-game.php).
|
|
$tileProxy = BASE_PATH . '/php/tile-proxy.php';
|
|
$html = strtr($html, [
|
|
'href="../../assets/css/design-system.css"' => 'href="' . BASE_PATH . '/assets/css/design-system.css"',
|
|
'href="../../assets/fonts/inter.css"' => 'href="' . BASE_PATH . '/assets/fonts/inter.css"',
|
|
'href="../../favicon.svg"' => 'href="' . BASE_PATH . '/favicon.svg"',
|
|
'href="../../favicon-96x96.png"' => 'href="' . BASE_PATH . '/favicon-96x96.png"',
|
|
'src="../../assets/img/bildLogo.png"' => 'src="' . BASE_PATH . '/assets/img/bildLogo.png"',
|
|
'src="../../assets/img/textlogo_geograsim.svg"' => 'src="' . BASE_PATH . '/assets/img/textlogo_geograsim.svg"',
|
|
'href="../../schueler"' => 'href="' . cockpit_href() . '"',
|
|
'href="../../"' => 'href="' . BASE_PATH . '/"',
|
|
'src="engine.js"' => 'src="' . $base . 'engine.js"',
|
|
'src="headless-runner.js"' => 'src="' . $base . 'headless-runner.js"',
|
|
'src="assets/vendor/three/three.min.js"' => 'src="' . $base . 'assets/vendor/three/three.min.js"',
|
|
'src="assets/vendor/autobahn-game/autobahn-game.js"' => 'src="' . $base . 'assets/vendor/autobahn-game/autobahn-game.js"',
|
|
// Leaflet lokal + Tile-Proxy (DSGVO-sicher)
|
|
'https://unpkg.com/leaflet@1.9.4/dist/leaflet.css' => BASE_PATH . '/assets/vendor/leaflet/leaflet.css',
|
|
'https://unpkg.com/leaflet@1.9.4/dist/leaflet.js' => BASE_PATH . '/assets/vendor/leaflet/leaflet.js',
|
|
"'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png'" => "'{$tileProxy}?z={z}&x={x}&y={y}&p=osm-de'",
|
|
]);
|
|
$html = str_replace('href="/schueler"', 'href="' . cockpit_href() . '"', $html);
|
|
|
|
if (function_exists('ggs_inject_live')) $html = ggs_inject_live($html, 'logistik');
|
|
echo $html;
|