Aufgabe: Ab-wann + Bis-wann mit gutem Picker; neue Klasse nur Weltkueche frei

- Modal: "Ab wann" (Sofort/Zeitpunkt) + "Bis wann" (Presets + date/time statt
  datetime-local), Live-Zusammenfassung; zukuenftiger Start => vorbereitet
- assignments.php: startsAt-Param (Default NOW()), T->Space
- modules.php: neue Klasse ohne Eintrag -> nur Weltkueche frei (_defaultMode),
  Rest gesperrt; Freigabe-Matrix bleibt (getrennt von der Aufgabe)
- schueler.html: Hinweis "Deine Lehrperson kann weitere Simulationen freischalten"

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-22 17:39:28 +02:00
parent 7f774c7b2a
commit 405fcc2b69
4 changed files with 87 additions and 30 deletions
+14 -5
View File
@@ -50,7 +50,9 @@ if ($method === 'POST') {
$classId = (int)($body['classId'] ?? 0); $classId = (int)($body['classId'] ?? 0);
$moduleId = $body['moduleId'] ?? ''; $moduleId = $body['moduleId'] ?? '';
$level = max(1, min(5, (int)($body['level'] ?? 1))); $level = max(1, min(5, (int)($body['level'] ?? 1)));
$endsAt = !empty($body['endsAt']) ? $body['endsAt'] : null; // datetime-local liefert 'YYYY-MM-DDTHH:MM' → 'T' für MySQL zu Leerzeichen.
$endsAt = !empty($body['endsAt']) ? str_replace('T', ' ', $body['endsAt']) : null;
$startsAt = !empty($body['startsAt']) ? str_replace('T', ' ', $body['startsAt']) : null;
if (!$classId || !$moduleId) Response::error('classId und moduleId erforderlich'); if (!$classId || !$moduleId) Response::error('classId und moduleId erforderlich');
@@ -63,10 +65,17 @@ if ($method === 'POST') {
[$classId, $moduleId] [$classId, $moduleId]
); );
$db->execute( if ($startsAt) {
'INSERT INTO class_assignments (class_id, teacher_id, module_id, level, starts_at, ends_at) VALUES (?, ?, ?, ?, NOW(), ?)', $db->execute(
[$classId, $teacherId, $moduleId, $level, $endsAt] 'INSERT INTO class_assignments (class_id, teacher_id, module_id, level, starts_at, ends_at) VALUES (?, ?, ?, ?, ?, ?)',
); [$classId, $teacherId, $moduleId, $level, $startsAt, $endsAt]
);
} else {
$db->execute(
'INSERT INTO class_assignments (class_id, teacher_id, module_id, level, starts_at, ends_at) VALUES (?, ?, ?, ?, NOW(), ?)',
[$classId, $teacherId, $moduleId, $level, $endsAt]
);
}
Response::ok(['id' => (int)$db->lastInsertId()]); Response::ok(['id' => (int)$db->lastInsertId()]);
} }
+9 -4
View File
@@ -16,6 +16,11 @@ require_once __DIR__ . '/../lib/Response.php';
$method = $_SERVER['REQUEST_METHOD']; $method = $_SERVER['REQUEST_METHOD'];
$db = Database::get(); $db = Database::get();
// Default-Modus für eine Klasse OHNE expliziten Eintrag: eine neue Klasse startet
// mit NUR Weltküche frei (Einstiegs-Sim), alles andere gesperrt. Die Lehrperson
// gibt weitere Module über die Freigabe-Matrix frei.
function _defaultMode($moduleId) { return $moduleId === 'weltkueche' ? 'free' : 'locked'; }
// Modul-Katalog dynamisch aus module_info (Source of Truth) // Modul-Katalog dynamisch aus module_info (Source of Truth)
// Nur aktive + beta + geplante Module anzeigen (keine archivierten) // Nur aktive + beta + geplante Module anzeigen (keine archivierten)
$ALL_MODULES = $db->fetchAll( $ALL_MODULES = $db->fetchAll(
@@ -85,7 +90,7 @@ if ($method === 'GET') {
foreach ($ALL_MODULES as $mod) { foreach ($ALL_MODULES as $mod) {
if ($filterId && $mod['id'] !== $filterId) continue; if ($filterId && $mod['id'] !== $filterId) continue;
$cm = $classMap[$mod['id']] ?? null; $cm = $classMap[$mod['id']] ?? null;
$mode = $overrides[$mod['id']] ?? ($cm['mode'] ?? 'locked'); $mode = $overrides[$mod['id']] ?? ($cm['mode'] ?? _defaultMode($mod['id']));
// 'geplant' überschreibt jeden mode-Eintrag — Modul ist nicht spielbar. // 'geplant' überschreibt jeden mode-Eintrag — Modul ist nicht spielbar.
if ($mod['status'] === 'geplant') $mode = 'coming_soon'; if ($mod['status'] === 'geplant') $mode = 'coming_soon';
@@ -172,7 +177,7 @@ if ($method === 'GET') {
'modules' => [], 'modules' => [],
]; ];
foreach ($ALL_MODULES as $mod) { foreach ($ALL_MODULES as $mod) {
$row['modules'][$mod['id']] = $overrides[$s['id']][$mod['id']] ?? $classMap[$mod['id']] ?? 'locked'; $row['modules'][$mod['id']] = $overrides[$s['id']][$mod['id']] ?? $classMap[$mod['id']] ?? _defaultMode($mod['id']);
} }
$matrix[] = $row; $matrix[] = $row;
} }
@@ -189,7 +194,7 @@ if ($method === 'GET') {
'card_image' => $mod['card_image'], 'card_image' => $mod['card_image'],
'status' => $mod['status'], 'status' => $mod['status'],
'available_from' => $mod['available_from'], 'available_from' => $mod['available_from'],
'classMode' => $classMap[$mod['id']] ?? 'locked', 'classMode' => $classMap[$mod['id']] ?? _defaultMode($mod['id']),
'currentLevel' => $meta ? (int)($meta['current_level'] ?? 1) : 1, 'currentLevel' => $meta ? (int)($meta['current_level'] ?? 1) : 1,
'paused' => $meta ? (bool)($meta['paused'] ?? 0) : false, 'paused' => $meta ? (bool)($meta['paused'] ?? 0) : false,
'audioInfo' => $meta ? (bool)($meta['audio_info'] ?? 1) : true, 'audioInfo' => $meta ? (bool)($meta['audio_info'] ?? 1) : true,
@@ -210,7 +215,7 @@ if ($method === 'GET') {
'desc' => $mod['desc'], 'desc' => $mod['desc'],
'icon' => $mod['icon'], 'icon' => $mod['icon'],
'status' => $mod['status'], 'status' => $mod['status'],
'mode' => $classMap[$mod['id']] ?? 'locked', 'mode' => $classMap[$mod['id']] ?? _defaultMode($mod['id']),
]; ];
} }
Response::ok($result); Response::ok($result);
+1 -1
View File
@@ -311,7 +311,7 @@ async function renderModules() {
html += '</div>'; html += '</div>';
if (lockedByTeacher.length > 0) { if (lockedByTeacher.length > 0) {
html += '<div class="coming-divider">Kann durch die Lehrperson freigegeben werden</div>'; html += '<div class="coming-divider">🔒 Deine Lehrperson kann weitere Simulationen freischalten</div>';
html += '<div class="mod-grid">'; html += '<div class="mod-grid">';
lockedByTeacher.forEach(function(m) { html += renderModCard(m); }); lockedByTeacher.forEach(function(m) { html += renderModCard(m); });
html += '</div>'; html += '</div>';
+63 -20
View File
@@ -386,14 +386,26 @@ schueler01,Max M.,,,,,</pre>
<option value="2">Stufe 2 — Fortgeschritten</option> <option value="2">Stufe 2 — Fortgeschritten</option>
<option value="3">Stufe 3 — Profi</option> <option value="3">Stufe 3 — Profi</option>
</select> </select>
<label>Fällig bis</label> <label>Ab wann?</label>
<div style="display:flex;gap:.3rem;flex-wrap:wrap;margin-bottom:.35rem"> <div style="display:flex;gap:.3rem;margin-bottom:.4rem">
<button type="button" id="ss-start-now" class="btn" style="font-size:.7rem;padding:.3rem .7rem" onclick="ssStartMode('now')">▶ Sofort</button>
<button type="button" id="ss-start-at" class="btn btn-outline" style="font-size:.7rem;padding:.3rem .7rem" onclick="ssStartMode('at')">🕒 Zeitpunkt wählen</button>
</div>
<div id="ss-start-fields" style="display:none;gap:.4rem;margin-bottom:.5rem">
<input type="date" id="ss-start-date" onchange="ssUpdateSummary()" style="padding:.35rem .5rem;border:1.5px solid rgba(0,0,0,.12);border-radius:6px;font-size:.78rem;font-family:inherit">
<input type="time" id="ss-start-time" value="08:00" onchange="ssUpdateSummary()" style="padding:.35rem .5rem;border:1.5px solid rgba(0,0,0,.12);border-radius:6px;font-size:.78rem;font-family:inherit">
</div>
<label>Bis wann (Frist)</label>
<div style="display:flex;gap:.3rem;flex-wrap:wrap;margin-bottom:.4rem">
<button type="button" class="btn btn-outline" style="font-size:.66rem;padding:.25rem .55rem" onclick="ssSetDue('heute')">Heute 13:00</button> <button type="button" class="btn btn-outline" style="font-size:.66rem;padding:.25rem .55rem" onclick="ssSetDue('heute')">Heute 13:00</button>
<button type="button" class="btn btn-outline" style="font-size:.66rem;padding:.25rem .55rem" onclick="ssSetDue('morgen')">Morgen</button> <button type="button" class="btn btn-outline" style="font-size:.66rem;padding:.25rem .55rem" onclick="ssSetDue('morgen')">Morgen</button>
<button type="button" class="btn btn-outline" style="font-size:.66rem;padding:.25rem .55rem" onclick="ssSetDue('woche')">+1 Woche</button> <button type="button" class="btn btn-outline" style="font-size:.66rem;padding:.25rem .55rem" onclick="ssSetDue('woche')">+1 Woche</button>
<button type="button" class="btn btn-outline" style="font-size:.66rem;padding:.25rem .55rem" onclick="ssSetDue('')">Kein Limit</button> <button type="button" class="btn btn-outline" style="font-size:.66rem;padding:.25rem .55rem" onclick="ssSetDue('')">Kein Limit</button>
</div> </div>
<input type="datetime-local" id="ss-ends" onchange="ssUpdateSummary()"> <div style="display:flex;gap:.4rem;align-items:center">
<input type="date" id="ss-end-date" onchange="ssUpdateSummary()" style="padding:.35rem .5rem;border:1.5px solid rgba(0,0,0,.12);border-radius:6px;font-size:.78rem;font-family:inherit">
<input type="time" id="ss-end-time" value="13:00" onchange="ssUpdateSummary()" style="padding:.35rem .5rem;border:1.5px solid rgba(0,0,0,.12);border-radius:6px;font-size:.78rem;font-family:inherit">
</div>
<label style="display:flex;align-items:flex-start;gap:.4rem;margin-top:.6rem;cursor:pointer"> <label style="display:flex;align-items:flex-start;gap:.4rem;margin-top:.6rem;cursor:pointer">
<input type="checkbox" id="ss-paused" onchange="ssUpdateSummary()" style="margin-top:.15rem"> <span style="font-size:.74rem">⏸ Vorbereiten — die Klasse startet erst, wenn du auf der Aufgaben-Card „▶ Start freigeben" drückst (gemeinsamer Start)</span> <input type="checkbox" id="ss-paused" onchange="ssUpdateSummary()" style="margin-top:.15rem"> <span style="font-size:.74rem">⏸ Vorbereiten — die Klasse startet erst, wenn du auf der Aufgaben-Card „▶ Start freigeben" drückst (gemeinsamer Start)</span>
</label> </label>
@@ -2895,7 +2907,9 @@ async function loadModuleMatrix() {
var thumb = img var thumb = img
? '<img src="'+img+'" alt="" style="width:50px;height:50px;border-radius:9px;object-fit:cover;flex:none">' ? '<img src="'+img+'" alt="" style="width:50px;height:50px;border-radius:9px;object-fit:cover;flex:none">'
: '<span style="font-size:1.6rem;width:50px;text-align:center">'+(mod?mod.icon:'📋')+'</span>'; : '<span style="font-size:1.6rem;width:50px;text-align:center">'+(mod?mod.icon:'📋')+'</span>';
var end = a.ends_at ? 'fällig ' + new Date(a.ends_at).toLocaleDateString('de-AT',{weekday:'short',day:'2-digit',month:'2-digit',hour:'2-digit',minute:'2-digit'}) : 'ohne Zeitlimit'; var end = a.ends_at ? 'fällig ' + new Date(a.ends_at.replace(' ','T')).toLocaleDateString('de-AT',{weekday:'short',day:'2-digit',month:'2-digit',hour:'2-digit',minute:'2-digit'}) : 'ohne Zeitlimit';
var startMs = a.starts_at ? new Date(a.starts_at.replace(' ','T')).getTime() : 0;
if (startMs && startMs > Date.now()) end = 'ab ' + new Date(startMs).toLocaleDateString('de-AT',{weekday:'short',day:'2-digit',month:'2-digit',hour:'2-digit',minute:'2-digit'}) + ' · ' + end;
var stateBadge = paused var stateBadge = paused
? '<span style="background:#fdf1e6;color:#c25e1e;border:1px solid #e8c3a0;padding:.08rem .5rem;border-radius:99px;font-size:.62rem;font-weight:700">⏸ Vorbereitet</span>' ? '<span style="background:#fdf1e6;color:#c25e1e;border:1px solid #e8c3a0;padding:.08rem .5rem;border-radius:99px;font-size:.62rem;font-weight:700">⏸ Vorbereitet</span>'
: '<span style="background:#e5f2e7;color:#2a7a3a;border:1px solid #b9dcc0;padding:.08rem .5rem;border-radius:99px;font-size:.62rem;font-weight:700">▶ Läuft</span>'; : '<span style="background:#e5f2e7;color:#2a7a3a;border:1px solid #b9dcc0;padding:.08rem .5rem;border-radius:99px;font-size:.62rem;font-weight:700">▶ Läuft</span>';
@@ -3041,6 +3055,7 @@ async function loadAllMods() {
if (Array.isArray(r)) ALL_MODS = r.filter(function(m){return m.status!=='archiv' && m.status!=='geplant';}); if (Array.isArray(r)) ALL_MODS = r.filter(function(m){return m.status!=='archiv' && m.status!=='geplant';});
return ALL_MODS; return ALL_MODS;
} }
var _ssStartMode = 'now';
async function showStartSim(preselectedModuleId) { async function showStartSim(preselectedModuleId) {
await loadAllMods(); await loadAllMods();
var sel = document.getElementById('ss-module'); var sel = document.getElementById('ss-module');
@@ -3049,44 +3064,72 @@ async function showStartSim(preselectedModuleId) {
if (preselectedModuleId) sel.value = preselectedModuleId; if (preselectedModuleId) sel.value = preselectedModuleId;
document.getElementById('ss-paused').checked = false; document.getElementById('ss-paused').checked = false;
document.getElementById('ss-level').value = '1'; document.getElementById('ss-level').value = '1';
ssSetDue('woche'); // Default-Frist: +1 Woche (Hausübung); setzt Feld + Bestätigung var now = new Date();
document.getElementById('ss-start-date').value = _ssDate(now);
document.getElementById('ss-start-time').value = '08:00';
ssStartMode('now');
ssSetDue('woche'); // Default-Frist: +1 Woche
showModal('modal-startsim'); showModal('modal-startsim');
} }
function _ssPad(n){ return String(n).padStart(2,'0'); } function _ssPad(n){ return String(n).padStart(2,'0'); }
function _ssDtLocal(d){ return d.getFullYear()+'-'+_ssPad(d.getMonth()+1)+'-'+_ssPad(d.getDate())+'T'+_ssPad(d.getHours())+':'+_ssPad(d.getMinutes()); } function _ssDate(d){ return d.getFullYear()+'-'+_ssPad(d.getMonth()+1)+'-'+_ssPad(d.getDate()); }
function ssStartMode(mode){
_ssStartMode = mode;
var now = document.getElementById('ss-start-now'), at = document.getElementById('ss-start-at');
var fields = document.getElementById('ss-start-fields');
now.className = mode==='now' ? 'btn' : 'btn btn-outline';
at.className = mode==='at' ? 'btn' : 'btn btn-outline';
fields.style.display = mode==='at' ? 'flex' : 'none';
ssUpdateSummary();
}
function ssSetDue(kind){ function ssSetDue(kind){
var el = document.getElementById('ss-ends'); var dd = document.getElementById('ss-end-date'), tt = document.getElementById('ss-end-time');
if (kind === '') { el.value = ''; ssUpdateSummary(); return; } if (kind === '') { dd.value = ''; ssUpdateSummary(); return; }
var d = new Date(); var d = new Date();
if (kind === 'morgen') d.setDate(d.getDate()+1); if (kind === 'morgen') d.setDate(d.getDate()+1);
else if (kind === 'woche') d.setDate(d.getDate()+7); else if (kind === 'woche') d.setDate(d.getDate()+7);
d.setHours(13, 0, 0, 0); dd.value = _ssDate(d);
el.value = _ssDtLocal(d); tt.value = '13:00';
ssUpdateSummary(); ssUpdateSummary();
} }
// Kombiniert date+time zu 'YYYY-MM-DDTHH:MM' (oder null, wenn kein Datum)
function _ssCombine(dateId, timeId){
var d = document.getElementById(dateId).value;
if (!d) return null;
var t = document.getElementById(timeId).value || '00:00';
return d + 'T' + t;
}
function ssStartValue(){ return _ssStartMode === 'now' ? null : _ssCombine('ss-start-date','ss-start-time'); }
function ssEndValue(){ return _ssCombine('ss-end-date','ss-end-time'); }
function _ssFmt(v){ return new Date(v).toLocaleDateString('de-AT',{weekday:'short',day:'2-digit',month:'2-digit',hour:'2-digit',minute:'2-digit'}); }
function ssUpdateSummary(){ function ssUpdateSummary(){
var el = document.getElementById('ss-summary'); if (!el) return; var el = document.getElementById('ss-summary'); if (!el) return;
var modSel = document.getElementById('ss-module'); var modSel = document.getElementById('ss-module');
var modTxt = (modSel && modSel.options[modSel.selectedIndex]) ? modSel.options[modSel.selectedIndex].text : '—'; var modTxt = (modSel && modSel.options[modSel.selectedIndex]) ? modSel.options[modSel.selectedIndex].text : '—';
var lvl = document.getElementById('ss-level').value; var lvl = document.getElementById('ss-level').value;
var ends = document.getElementById('ss-ends').value; var startsAt = ssStartValue();
var paused = document.getElementById('ss-paused').checked; var endsAt = ssEndValue();
var endTxt = ends ? new Date(ends).toLocaleDateString('de-AT',{weekday:'short',day:'2-digit',month:'2-digit',hour:'2-digit',minute:'2-digit'}) : 'ohne Zeitlimit'; var paused = document.getElementById('ss-paused').checked;
var startTxt = paused ? '⏸ startet auf dein Signal' : '▶ startet sofort'; var future = startsAt && new Date(startsAt) > new Date();
el.innerHTML = '<b>'+esc(modTxt)+'</b> · Stufe '+lvl+' · fällig <b>'+esc(endTxt)+'</b> · '+startTxt; var startTxt = startsAt ? ('ab <b>'+esc(_ssFmt(startsAt))+'</b>') : (paused ? '⏸ auf dein Signal' : '▶ sofort');
var endTxt = endsAt ? ('fällig <b>'+esc(_ssFmt(endsAt))+'</b>') : 'ohne Frist';
var note = (paused || future) ? ' <span style="color:#c25e1e">· Klasse wartet auf „Start freigeben"</span>' : '';
el.innerHTML = '<b>'+esc(modTxt)+'</b> · Stufe '+lvl+' · '+startTxt+' · '+endTxt+note;
} }
async function startSimulation() { async function startSimulation() {
var moduleId = document.getElementById('ss-module').value; var moduleId = document.getElementById('ss-module').value;
var level = parseInt(document.getElementById('ss-level').value); var level = parseInt(document.getElementById('ss-level').value);
var endsAt = document.getElementById('ss-ends').value || null; var startsAt = ssStartValue();
var paused = document.getElementById('ss-paused').checked; var endsAt = ssEndValue();
var future = startsAt && new Date(startsAt) > new Date();
// Zukünftiger Start ⇒ automatisch „vorbereitet" (Klasse wartet), sonst Checkbox.
var paused = document.getElementById('ss-paused').checked || !!future;
// Sowohl class_modules (Modus + Level + Pause) als auch class_assignments // Sowohl class_modules (Modus + Level + Pause) als auch class_assignments
// (Auftragshistorie) setzen, damit Schüler-Cockpit + saves.php-Filter + // (Auftragshistorie inkl. Zeitfenster) setzen.
// Live-View den gleichen Auftragszustand sehen.
var rm = await api('modules', {action:'set_mode', classId:currentClassId, moduleId:moduleId, mode:'teacher_started', currentLevel:level, dueDate:endsAt, paused:paused}); var rm = await api('modules', {action:'set_mode', classId:currentClassId, moduleId:moduleId, mode:'teacher_started', currentLevel:level, dueDate:endsAt, paused:paused});
if (rm && rm.error) { alert(rm.error); return; } if (rm && rm.error) { alert(rm.error); return; }
var r = await api('assignments', {action:'create', classId:currentClassId, moduleId:moduleId, level:level, endsAt:endsAt}); var r = await api('assignments', {action:'create', classId:currentClassId, moduleId:moduleId, level:level, startsAt:startsAt, endsAt:endsAt});
if (r.error) { alert(r.error); return; } if (r.error) { alert(r.error); return; }
hideModal('modal-startsim'); hideModal('modal-startsim');
loadModuleMatrix(); loadModuleMatrix();