From a68c58ac9ef7f5d15c6b6d2af4c523bc8075b57b Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 21 Aug 2026 12:13:27 +0200 Subject: [PATCH] Weltkueche Teil A: Land pro Lehrer persistent (teachers.country) + Sim-Verdrahtung MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - profil.html: Länderauswahl (AT/DE/CH/LI) im Lehrer-Profil, lädt/zeigt aktuelles Land. - profile.php: speichert country in teachers.country; gibt country zurück. - weltkueche.php: injiziert window.WK_COUNTRY = Country::current() (Kaskade Schüler→Klasse→Lehrer→AT) — Fundament für die konsumentenland-basierte Herkunft (Teil B). Spalte teachers.country existierte bereits, keine Migration nötig. Co-Authored-By: Claude Opus 4.8 --- App/pages/weltkueche.php | 2 ++ App/php/api/profile.php | 6 +++++- App/profil.html | 7 ++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/App/pages/weltkueche.php b/App/pages/weltkueche.php index a3cced9..e6fbfd0 100644 --- a/App/pages/weltkueche.php +++ b/App/pages/weltkueche.php @@ -6,6 +6,7 @@ require_once __DIR__ . '/../php/config/app.php'; require_once __DIR__ . '/../php/lib/Database.php'; require_once __DIR__ . '/../php/lib/Session.php'; +require_once __DIR__ . '/../php/lib/Country.php'; if (session_status() === PHP_SESSION_NONE) Session::start(); @@ -58,6 +59,7 @@ $injection = ''; diff --git a/App/php/api/profile.php b/App/php/api/profile.php index 9216118..550c6a8 100644 --- a/App/php/api/profile.php +++ b/App/php/api/profile.php @@ -57,7 +57,7 @@ if ($method === 'GET') { if ($teacherId) { $teacher = $db->fetchOne( - 'SELECT id, username, email, display_name, school_name, emoji_avatar, created_at FROM teachers WHERE id = ?', + 'SELECT id, username, email, display_name, school_name, emoji_avatar, country, created_at FROM teachers WHERE id = ?', [$teacherId] ); Response::ok(['role' => 'teacher', 'profile' => $teacher]); @@ -111,6 +111,10 @@ if ($method === 'POST') { if ($displayName) $db->execute('UPDATE teachers SET display_name = ? WHERE id = ?', [$displayName, $teacherId]); if ($schoolName !== '') $db->execute('UPDATE teachers SET school_name = ? WHERE id = ?', [$schoolName, $teacherId]); + if (isset($body['country'])) { + $cc = strtoupper(trim((string)$body['country'])); + if (in_array($cc, ['AT','DE','CH','LI'], true)) $db->execute('UPDATE teachers SET country = ? WHERE id = ?', [$cc, $teacherId]); + } if ($email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) Response::error('Ungültige E-Mail-Adresse'); $existing = $db->fetchOne('SELECT id FROM teachers WHERE email = ? AND id != ?', [$email, $teacherId]); diff --git a/App/profil.html b/App/profil.html index c2cd717..3bee95d 100644 --- a/App/profil.html +++ b/App/profil.html @@ -416,6 +416,10 @@ function renderTeacherProfile(p) { html += '
'; html += '
'; html += '
'; + html += '
'; html += ''; html += '
'; html += ''; @@ -488,7 +492,8 @@ async function saveTeacher() { var name = document.getElementById('pf-name').value.trim(); var email = document.getElementById('pf-email').value.trim(); var school = document.getElementById('pf-school').value.trim(); - var r = await api('profile', {displayName: name, email: email, schoolName: school}); + var country = (document.getElementById('pf-country') || {}).value || 'AT'; + var r = await api('profile', {displayName: name, email: email, schoolName: school, country: country}); var m = document.getElementById('msg-teacher'); m.className = r.error ? 'msg err' : 'msg ok'; m.textContent = r.error || 'Gespeichert!';