Weltkueche Teil A: Land pro Lehrer persistent (teachers.country) + Sim-Verdrahtung
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 = '<script>'
|
||||
. 'window.WK_CLASS_ID = ' . json_encode($classId) . ';'
|
||||
. 'window.WK_MODE = ' . json_encode($mode) . ';'
|
||||
. 'window.WK_API_BASE = ' . json_encode(BASE_PATH . '/api') . ';'
|
||||
. 'window.WK_COUNTRY = ' . json_encode(class_exists('Country') ? Country::current() : 'AT') . ';'
|
||||
. 'window.__GGS__ = ' . json_encode($ggs, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . ';'
|
||||
. '</script>';
|
||||
|
||||
|
||||
@@ -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]);
|
||||
|
||||
+6
-1
@@ -416,6 +416,10 @@ function renderTeacherProfile(p) {
|
||||
html += '<div class="field"><label>Anzeigename</label><input type="text" id="pf-name" value="' + (p.display_name || '') + '"></div>';
|
||||
html += '<div class="field"><label>E-Mail</label><input type="email" id="pf-email" value="' + (p.email || '') + '"></div>';
|
||||
html += '<div class="field"><label>Schule</label><input type="text" id="pf-school" value="' + (p.school_name || '') + '"></div>';
|
||||
html += '<div class="field"><label>Land (bestimmt die „lokale" Herkunft der Zutaten in Weltküche)</label><select id="pf-country">' +
|
||||
[['AT','🇦🇹 Österreich'],['DE','🇩🇪 Deutschland'],['CH','🇨🇭 Schweiz'],['LI','🇱🇮 Liechtenstein']]
|
||||
.map(function(o){ return '<option value="'+o[0]+'"'+(((p.country||'AT').toUpperCase())===o[0]?' selected':'')+'>'+o[1]+'</option>'; }).join('') +
|
||||
'</select></div>';
|
||||
html += '<button class="btn" onclick="saveTeacher()">Speichern</button>';
|
||||
html += '<div class="msg" id="msg-teacher"></div>';
|
||||
html += '</div>';
|
||||
@@ -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!';
|
||||
|
||||
Reference in New Issue
Block a user