Lizenz-Feinschliff: CSV-Mailanhang, Lehrer-Listenspalten, Klassenliste-Haken

- Mailanhang bei grossen Chargen: zusaetzlich zur .txt jetzt auch .csv
  (gleiche reine Codeliste), Dateiname <ExtBestellnr|Datum>_geograsim_<intNr>.
- Lehrer-Lizenzlisten (zugewiesen + frei): vorne laufende Nr., Eingeloest am,
  Gueltig bis (Backend liefert redeemed_at + valid_until).
- Klassenliste Lizenz-Spalte: nur Haken (gruen) bzw. "fehlt" (rot); Tooltip
  zeigt Lizenznummer + gueltig bis. "Gueltig" via unlicensed-Liste (nicht
  storniert/abgelaufen). Bulk-Auswahl/Zaehler nutzen jetzt dieselbe Wahrheit.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-27 11:33:44 +02:00
parent ff889865e1
commit 3dba841830
3 changed files with 35 additions and 20 deletions
+11 -4
View File
@@ -215,19 +215,19 @@ if ($method === 'GET') {
if (!$class) Response::error('Klasse nicht gefunden', 404);
$licenses = $db->fetchAll(
'SELECT l.id, l.code, l.school_year, l.student_id, l.redeemed_at,
'SELECT l.id, l.code, l.school_year, l.student_id, l.redeemed_at, l.valid_until,
s.username as student_name, s.display_name as student_display
FROM licenses l
JOIN students s ON s.id = l.student_id
WHERE s.class_id = ?
ORDER BY s.username',
ORDER BY l.redeemed_at, l.id',
[$classId]
);
// Auch freie Lizenzen des Lehrers (noch nicht zugewiesen), storniert ausgeschlossen.
// Reihenfolge = id (= Reihenfolge, in der die Codes ausgegeben/reinkopiert wurden).
$freeLicenses = $db->fetchAll(
'SELECT id, code, school_year FROM licenses WHERE teacher_id = ? AND student_id IS NULL AND canceled_at IS NULL ORDER BY id',
'SELECT id, code, school_year, redeemed_at, valid_until FROM licenses WHERE teacher_id = ? AND student_id IS NULL AND canceled_at IS NULL ORDER BY id',
[$teacherId]
);
@@ -484,7 +484,14 @@ if ($method === 'POST') {
$html = Mailer::renderPlainBody($textBody);
$attach = [];
if (count($codeList) > 40) {
$attach[] = ['content' => implode("\r\n", $codeList) . "\r\n", 'name' => 'lizenzcodes.txt', 'type' => 'text/plain'];
// Reine Code-Liste (eine pro Zeile) als .txt UND .csv anhängen.
// Dateiname wie beim Download: <ExtBestellnr|Datum>_geograsim_<interneNr>.
$codesTxt = implode("\r\n", $codeList) . "\r\n";
$bRow = $db->fetchOne("SELECT order_no FROM license_batches WHERE id = ?", [$bid]);
$ord = ($bRow && !empty($bRow['order_no'])) ? preg_replace('/[^A-Za-z0-9_\-]/', '_', $bRow['order_no']) : date('Y-m-d-H-i');
$fbase = $ord . '_geograsim_' . $bid;
$attach[] = ['content' => $codesTxt, 'name' => $fbase . '.txt', 'type' => 'text/plain'];
$attach[] = ['content' => $codesTxt, 'name' => $fbase . '.csv', 'type' => 'text/csv'];
}
$db->execute(
"INSERT INTO license_mails (batch_id, to_email, subject, body_text, body_html, provider, status, created_by) VALUES (?,?,?,?,?,?,?,?)",