Lehrplan: Country-Helper + Landeinstellung live
- App/php/lib/Country.php: Kaskade session → classes → teachers → cookie → 'AT', Helper current()/flag()/label()/allCountries() - App/php/api/country.php: GET + POST /api/country - country-Spalten in teachers, classes, student_sessions (idempotent) - Native-<select>-Picker im Header aller öffentlichen Seiten (modul-*.php, lehrplan.php, simulationen.php) - Footer-Links "Andere Länder: 🇨🇭 🇩🇪 🇱🇮" - lehrplan.php liest Default-Filter jetzt aus Country::current() - iPad-freundlich: Native Select gibt Wheel-Picker auf iOS, Touch-Ziel >=40px Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Country-Footer — „Andere Länder: 🇨🇭 / 🇩🇪 / 🇱🇮"
|
||||
* --------------------------------------------------
|
||||
* Kleine Zeile unten in den öffentlichen Seiten. Zeigt die jeweils
|
||||
* *nicht* aktuell gewählten Länder mit Flaggen-Link.
|
||||
*/
|
||||
require_once __DIR__ . '/../../php/lib/Country.php';
|
||||
|
||||
$current = Country::current();
|
||||
$others = array_filter(Country::allCountries(), fn($c) => $c !== $current);
|
||||
?>
|
||||
<div class="md-country-foot">
|
||||
Andere Länder:
|
||||
<?php foreach ($others as $c): ?>
|
||||
<a href="?country=<?= htmlspecialchars($c) ?>"
|
||||
onclick="event.preventDefault(); window.__GGS_setCountry('<?= htmlspecialchars($c) ?>');"
|
||||
class="md-country-foot-link"
|
||||
title="<?= htmlspecialchars(Country::label($c)) ?>">
|
||||
<?= Country::flag($c) ?> <?= htmlspecialchars(Country::label($c)) ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.md-country-foot {
|
||||
font-size: .78rem; color: var(--ggs-text-muted);
|
||||
padding: .6rem 0 0;
|
||||
text-align: center;
|
||||
}
|
||||
.md-country-foot a {
|
||||
display: inline-block; margin: 0 .3rem; padding: .3rem .5rem;
|
||||
color: var(--ggs-fjord); text-decoration: none;
|
||||
border-radius: var(--ggs-radius-sm);
|
||||
min-height: 32px;
|
||||
}
|
||||
.md-country-foot a:hover { background: var(--ggs-fjord-light); }
|
||||
</style>
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* Country-Picker — Native <select> im Header
|
||||
* -------------------------------------------
|
||||
* Wird per include in den Modul-/Lehrplan-/Simulationen-Seiten eingebunden.
|
||||
*
|
||||
* Erwartet im eltern-Scope:
|
||||
* $bp BASE_PATH
|
||||
*
|
||||
* Beim Ändern:
|
||||
* - POST auf /php/api/country.php (Session + Cookie)
|
||||
* - Fallback: Cookie via JS
|
||||
* - Seite wird neu geladen, damit alle Server-seitigen Filter greifen
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../../php/lib/Country.php';
|
||||
|
||||
if (!isset($bp)) $bp = defined('BASE_PATH') ? BASE_PATH : '';
|
||||
$currentCountry = Country::current();
|
||||
?>
|
||||
<form class="md-country-form" method="post" action="#" onsubmit="return false;" aria-label="Land auswählen">
|
||||
<label for="md-country-select" class="md-country-label">
|
||||
<?= Country::flag($currentCountry) ?>
|
||||
</label>
|
||||
<select id="md-country-select" class="md-country-select"
|
||||
onchange="window.__GGS_setCountry(this.value)">
|
||||
<?php foreach (Country::allCountries() as $code): ?>
|
||||
<option value="<?= htmlspecialchars($code) ?>"
|
||||
<?= $code === $currentCountry ? 'selected' : '' ?>>
|
||||
<?= Country::flag($code) ?> <?= Country::label($code) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
/* Native-Select iPad-freundlich gestylt */
|
||||
.md-country-form {
|
||||
display: inline-flex; align-items: center; gap: .3rem;
|
||||
background: var(--ggs-white); border: 1px solid var(--ggs-border);
|
||||
border-radius: var(--ggs-radius-sm);
|
||||
padding: 0 .5rem 0 .75rem; min-height: 40px;
|
||||
}
|
||||
.md-country-form:hover, .md-country-form:focus-within {
|
||||
border-color: var(--ggs-fjord);
|
||||
}
|
||||
.md-country-label {
|
||||
font-size: 1.1rem; line-height: 1; pointer-events: none;
|
||||
}
|
||||
.md-country-select {
|
||||
appearance: auto; /* native Wheel-Picker auf iOS */
|
||||
-webkit-appearance: auto;
|
||||
background: transparent; border: 0; cursor: pointer;
|
||||
font-size: .85rem; font-weight: 600; font-family: inherit;
|
||||
color: var(--ggs-fjord-dark);
|
||||
padding: .5rem .2rem; min-height: 40px;
|
||||
}
|
||||
.md-country-select:focus { outline: none; }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* window.__GGS_setCountry(code)
|
||||
*
|
||||
* 1. POST an /php/api/country.php (falls verfügbar) — persistiert Session + Cookie.
|
||||
* 2. Zusätzlich lokalen Cookie setzen (Fallback, wenn API-Call scheitert).
|
||||
* 3. Seite reloaden, damit Server-Filter greifen (Lehrplan-Default etc.).
|
||||
*/
|
||||
if (typeof window.__GGS_setCountry !== 'function') {
|
||||
window.__GGS_setCountry = function (code) {
|
||||
try {
|
||||
// Local Cookie als sofortiger Fallback (1 Jahr)
|
||||
document.cookie = 'ggs-country=' + encodeURIComponent(code)
|
||||
+ '; Max-Age=' + (60*60*24*365)
|
||||
+ '; Path=<?= $bp ?: "/" ?>; SameSite=Lax';
|
||||
} catch (e) {}
|
||||
// Server-Speicherung
|
||||
fetch('<?= $bp ?>/api/country', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ country: code })
|
||||
}).catch(function () {
|
||||
// Netz weg, kein Problem — Cookie reicht als Fallback
|
||||
}).finally(function () {
|
||||
// Seite neu laden, damit Server-Filter (z.B. lehrplan.php ?country=...) greifen
|
||||
// Wenn in URL bereits ?country=... steht, diesen Parameter überschreiben
|
||||
var u = new URL(window.location.href);
|
||||
u.searchParams.set('country', code);
|
||||
window.location.href = u.toString();
|
||||
});
|
||||
};
|
||||
}
|
||||
</script>
|
||||
@@ -404,6 +404,7 @@ $countryMeta = [
|
||||
<?php if ($easyActive): ?>
|
||||
<span class="md-btn-sm md-easy-pill" title="Leichte Sprache ist aktiv">🟢 Leichte Sprache</span>
|
||||
<?php endif; ?>
|
||||
<?php include __DIR__ . '/country_picker.php'; ?>
|
||||
<a href="<?= $bp ?>/pages/simulationen.php" class="md-btn-sm">Alle Simulationen</a>
|
||||
<a href="<?= $bp ?>/pages/lehrplan.php" class="md-btn-sm">Lehrplan</a>
|
||||
<a href="<?= $bp ?>/glossar" class="md-btn-sm">Glossar</a>
|
||||
@@ -631,6 +632,7 @@ $countryMeta = [
|
||||
<a href="<?= $bp ?>/impressum.html">Impressum</a> ·
|
||||
<a href="<?= $bp ?>/datenschutz.html">Datenschutz</a>
|
||||
</div>
|
||||
<?php include __DIR__ . '/country_footer.php'; ?>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
|
||||
Reference in New Issue
Block a user