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>
92 lines
3.6 KiB
PHP
92 lines
3.6 KiB
PHP
<?php
|
|
/**
|
|
* GeoGraSim — App Configuration
|
|
* Umgebungserkennung und Grundkonstanten
|
|
*/
|
|
|
|
// API-Antworten dürfen NIE durch PHP-Warnings/Deprecations korrumpiert werden.
|
|
// Production: Errors gehen ins Log, niemals in den Output (sonst zerbricht JSON).
|
|
// Local: Errors weiter sichtbar zum Debuggen.
|
|
$_isApiCall = strpos($_SERVER['REQUEST_URI'] ?? '', '/api/') !== false;
|
|
$_isProd = (($_SERVER['HTTP_HOST'] ?? '') !== 'localhost');
|
|
if ($_isApiCall || $_isProd) {
|
|
ini_set('display_errors', '0');
|
|
ini_set('display_startup_errors', '0');
|
|
error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED);
|
|
ini_set('log_errors', '1');
|
|
}
|
|
|
|
// Umgebungserkennung via Hostname
|
|
$host = $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? 'localhost';
|
|
// Docker-Container oder fehlender Host = Production wenn .env.production existiert
|
|
$envProdExists = file_exists(dirname(__DIR__, 2) . '/.env.production');
|
|
define('IS_PRODUCTION', $host !== 'localhost' || ($envProdExists && !file_exists(dirname(__DIR__, 2) . '/.env.local')));
|
|
|
|
// BASE_PATH: konfigurierbar per Host
|
|
// geograsim.at → /
|
|
// staatsgeheimnis.at/geograsim/ → /geograsim
|
|
// localhost/geograsim/App/ → /geograsim/App
|
|
if (strpos($host, 'geograsim.at') !== false) {
|
|
define('BASE_PATH', '');
|
|
define('BASE_URL', 'https://geograsim.at');
|
|
} elseif (strpos($host, 'staatsgeheimnis.at') !== false) {
|
|
define('BASE_PATH', '/geograsim');
|
|
define('BASE_URL', 'https://www.staatsgeheimnis.at/geograsim');
|
|
} else {
|
|
define('BASE_PATH', '/geograsim/App');
|
|
define('BASE_URL', 'http://localhost/geograsim/App');
|
|
}
|
|
define('APP_ROOT', dirname(__DIR__, 2));
|
|
|
|
// Plattform-Limits — eine einzelne Sim-Session darf nie länger als 120 min
|
|
// dauern. Schützt DB vor absurden Werten (Tab über Nacht offen, Bug im
|
|
// Frontend-Zeit-Tracking, etc.). Backend-Cap ist defensive Garantie:
|
|
// auch wenn Frontend falsch rechnet, schreibt die DB max 7_200_000 ms.
|
|
// Idle-Pause vorgelagert im Frontend; dieser Cap ist die letzte Schranke.
|
|
if (!defined('GGS_MAX_SESSION_MS')) define('GGS_MAX_SESSION_MS', 7200000);
|
|
if (!defined('GGS_IDLE_THRESHOLD_MS')) define('GGS_IDLE_THRESHOLD_MS', 90000);
|
|
|
|
// .env laden
|
|
$envFile = IS_PRODUCTION
|
|
? APP_ROOT . '/.env.production'
|
|
: APP_ROOT . '/.env.local';
|
|
|
|
if (file_exists($envFile)) {
|
|
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
foreach ($lines as $line) {
|
|
$line = trim($line);
|
|
if ($line === '' || $line[0] === '#') continue;
|
|
if (strpos($line, '=') === false) continue;
|
|
[$key, $value] = explode('=', $line, 2);
|
|
$key = trim($key);
|
|
$value = trim($value);
|
|
if (!defined($key)) {
|
|
define($key, $value);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Defaults fuer lokale Entwicklung (XAMPP)
|
|
if (!defined('DB_HOST')) define('DB_HOST', 'localhost');
|
|
if (!defined('DB_NAME')) define('DB_NAME', 'geograsim');
|
|
if (!defined('DB_USER')) define('DB_USER', 'root');
|
|
if (!defined('DB_PASS')) define('DB_PASS', '');
|
|
if (!defined('DB_PORT')) define('DB_PORT', '3306');
|
|
|
|
/**
|
|
* Cockpit-URL je nach Login-Status:
|
|
* - Lehrkraft eingeloggt → /teacher
|
|
* - Schueler*in eingeloggt → /schueler
|
|
* - sonst → / (Plattform-Startseite)
|
|
*
|
|
* Wird von Sim-Wrappern benutzt, um den Logo- und Home-Button in der Sim
|
|
* auf das richtige Ziel umzubiegen. Idempotent — kann mehrfach aufgerufen
|
|
* werden.
|
|
*/
|
|
function cockpit_href(): string {
|
|
if (session_status() === PHP_SESSION_NONE) @session_start();
|
|
if (!empty($_SESSION['teacher_id'])) return BASE_PATH . '/teacher';
|
|
if (!empty($_COOKIE['ggs_session'])) return BASE_PATH . '/schueler';
|
|
return BASE_PATH . '/';
|
|
}
|