asdasd
All checks were successful
Deploy / deploy (push) Successful in 58s

This commit is contained in:
2026-07-29 22:54:50 +02:00
parent d26f4a5792
commit 76591569b6
5 changed files with 115 additions and 22 deletions

View File

@@ -207,19 +207,63 @@ final class AccountPages
);
}
$info = 'Einstellungen gespeichert.';
} elseif ($action === 'child_add') {
$firstNameEnc = $crypto ? $crypto->encrypt(trim((string)$_POST['first_name'])) : trim((string)$_POST['first_name']);
$noteEnc = $crypto ? $crypto->encrypt(trim((string)$_POST['note'])) : trim((string)$_POST['note']);
$stmt = $pdo?->prepare('INSERT INTO children (user_id, gender, birthdate, age_years, encrypted_first_name, note, created_at, updated_at) VALUES (:uid, :gender, :birthdate, :age, :name, :note, NOW(), NOW())');
} elseif ($action === 'child_add' || $action === 'child_update') {
$childId = (int)($_POST['child_id'] ?? 0);
$firstName = trim((string)($_POST['first_name'] ?? ''));
$gender = (string)($_POST['gender'] ?? 'unknown');
$birthdate = trim((string)($_POST['birthdate'] ?? ''));
$ageYearsRaw = trim((string)($_POST['age_years'] ?? ''));
$ageYears = $ageYearsRaw !== '' ? max(0, min(18, (int)$ageYearsRaw)) : null;
$note = trim((string)($_POST['note'] ?? ''));
if ($firstName === '') {
throw new \RuntimeException('Bitte gib einen Vornamen an.');
}
if (!in_array($gender, ['male', 'female', 'diverse', 'unknown'], true)) {
$gender = 'unknown';
}
$firstNameEnc = $crypto ? $crypto->encrypt($firstName) : $firstName;
$noteEnc = $crypto ? $crypto->encrypt($note) : $note;
if ($action === 'child_add') {
$stmt = $pdo?->prepare('INSERT INTO children (user_id, gender, birthdate, age_years, encrypted_first_name, note, created_at, updated_at) VALUES (:uid, :gender, :birthdate, :age, :name, :note, NOW(), NOW())');
$stmt?->execute([
'uid' => $userId,
'gender' => $gender,
'birthdate' => $birthdate !== '' ? $birthdate : null,
'age' => $ageYears,
'name' => $firstNameEnc,
'note' => $noteEnc,
]);
$info = 'Kind hinzugefügt.';
} else {
$stmt = $pdo?->prepare('UPDATE children SET gender = :gender, birthdate = :birthdate, age_years = :age, encrypted_first_name = :name, note = :note, updated_at = NOW() WHERE id = :childId AND user_id = :uid');
$stmt?->execute([
'uid' => $userId,
'childId' => $childId,
'gender' => $gender,
'birthdate' => $birthdate !== '' ? $birthdate : null,
'age' => $ageYears,
'name' => $firstNameEnc,
'note' => $noteEnc,
]);
if ($stmt && $stmt->rowCount() < 1) {
throw new \RuntimeException('Kind nicht gefunden.');
}
$info = 'Kind gespeichert.';
}
} elseif ($action === 'child_delete') {
$childId = (int)($_POST['child_id'] ?? 0);
$stmt = $pdo?->prepare('DELETE FROM children WHERE id = :childId AND user_id = :uid');
$stmt?->execute([
'childId' => $childId,
'uid' => $userId,
'gender' => $_POST['gender'] ?? 'unknown',
'birthdate' => $_POST['birthdate'] ?: null,
'age' => $_POST['age_years'] ?: null,
'name' => $firstNameEnc,
'note' => $noteEnc,
]);
$info = 'Kind hinzugefügt.';
if ($stmt && $stmt->rowCount() < 1) {
throw new \RuntimeException('Kind nicht gefunden.');
}
$info = 'Kind gelöscht.';
} elseif ($action === 'event_add' || $action === 'event_update') {
$street = trim((string)($_POST['street'] ?? ''));
$zip = trim((string)($_POST['zip'] ?? ''));
@@ -371,6 +415,8 @@ final class AccountPages
}
$profile = AvatarManager::normalizeProfile($profile, $userId);
$editChildId = isset($_GET['edit_child']) ? (int)$_GET['edit_child'] : 0;
$editChild = null;
$children = [];
$stmt = $pdo?->prepare('SELECT id, encrypted_first_name AS first_name, note, gender, birthdate, age_years FROM children WHERE user_id = :id ORDER BY id DESC');
$stmt?->execute(['id' => $userId]);
@@ -381,6 +427,9 @@ final class AccountPages
$c['note'] = $crypto->decrypt((string)($c['note'] ?? '')) ?: '';
}
$children[] = $c;
if ($editChildId > 0 && (int)$c['id'] === $editChildId) {
$editChild = $c;
}
}
$eventsUpcoming = [];
@@ -434,6 +483,7 @@ final class AccountPages
'error',
'profile',
'children',
'editChild',
'eventsUpcoming',
'eventsPast',
'editEvent',