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>
141 lines
5.1 KiB
PHP
141 lines
5.1 KiB
PHP
<?php
|
|
/**
|
|
* Farmer / Landwirtschaft — Wrapper
|
|
* Laedt sims/farmer/game.html und injiziert Base-Path + Session-Mode.
|
|
*
|
|
* Integrations-Vertrag §6.1: mode + forcedLevel + easy aus der
|
|
* Schueler-Session abgeleitet, an das Frontend uebergeben.
|
|
*
|
|
* Stand 2026-05-03: Modul ist 'geplant' — Phase 0 (Skelett) abgeschlossen.
|
|
* Phase 1 (Welt-Karte + Köppen-Layer + 3 Pflanzen + Reveal-Logik) folgt.
|
|
*/
|
|
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;
|
|
|
|
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'];
|
|
$cm = $db->prepare('SELECT mode, current_level FROM class_modules WHERE class_id = ? AND module_id = ?');
|
|
$cm->execute([$classId, 'farmer']);
|
|
$cmRow = $cm->fetch(PDO::FETCH_ASSOC);
|
|
if ($cmRow) {
|
|
$mode = $cmRow['mode'];
|
|
if ($mode === 'teacher_started') $forcedLevel = (int)($cmRow['current_level'] ?? 1);
|
|
} else {
|
|
$mode = 'locked';
|
|
}
|
|
$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'], 'farmer']);
|
|
$soRow = $so->fetch(PDO::FETCH_ASSOC);
|
|
if ($soRow) $mode = $soRow['mode'];
|
|
$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 · Landwirtschaft</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:#8b5a2b}.lock-card{background:#f5f3ea;border:1px solid #e2ddd1;padding:24px;border-radius:8px}</style>
|
|
</head><body>
|
|
<div class="lock-card">
|
|
<h1>🔒 Landwirtschaft 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;
|
|
}
|
|
|
|
// ---- Sim-Datei laden (Fallback solange noch leer) ----
|
|
$gamePath = __DIR__ . '/../sims/farmer/game.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 · Landwirtschaft</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:#8b5a2b}.wip-card{background:#f5f3ea;border:1px solid #e2ddd1;padding:24px;border-radius:8px}</style>
|
|
</head><body>
|
|
<div class="wip-card">
|
|
<h1>🌾 Landwirtschaft wird gerade gebaut.</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);
|
|
|
|
$modeJs = json_encode($mode);
|
|
$forcedLevelJs = json_encode($forcedLevel);
|
|
$easyJs = $easy ? 'true' : 'false';
|
|
$sessionIdJs = json_encode($sessionId);
|
|
|
|
$base = BASE_PATH . '/sims/farmer/';
|
|
$injection =
|
|
"window.FARMER_BASE = '$base';\n" .
|
|
"window.FARMER_SESSION_MODE = {$modeJs};\n" .
|
|
"window.FARMER_FORCED_LEVEL = {$forcedLevelJs};\n" .
|
|
"window.FARMER_SESSION_ID = {$sessionIdJs};\n" .
|
|
"window.STUDENT_EASY = {$easyJs};\n" .
|
|
"window.FARMER_API_BASE = '" . BASE_PATH . "/api';\n" .
|
|
"window.FARMER_TILE_PROXY = '" . BASE_PATH . "/php/tile-proxy.php';";
|
|
|
|
if (strpos($html, '/*__FARMER_INJECTION__*/') !== false) {
|
|
$html = str_replace('/*__FARMER_INJECTION__*/', $injection, $html);
|
|
} else {
|
|
$html = str_replace('</head>', "<script>$injection</script>\n</head>", $html);
|
|
}
|
|
|
|
// Asset-Pfade auf BASE_PATH umbiegen
|
|
$baseSim = BASE_PATH . '/sims/farmer/';
|
|
$html = preg_replace(
|
|
"/(['\"])assets\/(img|data|js|css)\//",
|
|
"$1{$baseSim}assets/$2/",
|
|
$html
|
|
);
|
|
|
|
// Engine.js relativ → absolut
|
|
$html = str_replace('src="engine.js"', 'src="' . $baseSim . 'engine.js"', $html);
|
|
|
|
// Cockpit-Link absolut
|
|
$html = str_replace('href="/schueler"', 'href="' . cockpit_href() . '"', $html);
|
|
|
|
if (function_exists('ggs_inject_live')) $html = ggs_inject_live($html, 'farmer');
|
|
echo $html;
|