prepare('SELECT id, name FROM member_characters WHERE user_id = ?'); $stmt->execute([$userId]); $input = static fn (string $key): array => is_array($_POST[$key] ?? null) ? $_POST[$key] : []; $raidsInput = $input('raids'); $scoreInput = $input('gs'); $powerInput = $input('cp'); // Je Charakter und Refugium: lead[Charakter][Refugium] usw. $perRaid = static fn (array $values, int $id, string $raid) => is_array($values[$id] ?? null) ? ($values[$id][$raid] ?? null) : null; $leadInput = $input('lead'); $shotInput = $input('shot'); $difficultyInput = $input('diff'); $progressInput = $input('progress'); $noteInput = $input('rnote'); $entries = []; foreach ($stmt->fetchAll() as $character) { $id = (int) $character['id']; $raids = array_values(array_intersect(array_keys(SANCTUARY_RAIDS), is_array($raidsInput[$id] ?? null) ? $raidsInput[$id] : [])); if (!$raids) { continue; } $score = sanctuary_number_input($scoreInput[$id] ?? '', SANCTUARY_GEARSCORE_MAX); $power = sanctuary_number_input($powerInput[$id] ?? '', SANCTUARY_POWER_MAX); if ($score === false) { $errors[] = $character['name'] . ': Der Gearscore muss eine Zahl bis ' . number_format(SANCTUARY_GEARSCORE_MAX, 0, ',', '.') . ' sein.'; } if ($power === false) { $errors[] = $character['name'] . ': Die Kampfkraft muss eine ganze Zahl sein, z. B. 98986.'; } $details = []; foreach ($raids as $raid) { $difficulty = $perRaid($difficultyInput, $id, $raid); if (!is_string($difficulty) || !isset(SANCTUARY_DIFFICULTIES[$difficulty])) { $errors[] = $character['name'] . ', ' . SANCTUARY_RAIDS[$raid]['short'] . ': Wähle bei „Möglich bei“ eine Stufe.'; $difficulty = ''; } $details[$raid] = [ 'lead' => !empty($perRaid($leadInput, $id, $raid)), 'shot' => !empty($perRaid($shotInput, $id, $raid)), 'difficulty' => $difficulty, 'progress' => sanctuary_text_input($perRaid($progressInput, $id, $raid), SANCTUARY_PROGRESS_MAX), 'note' => sanctuary_text_input($perRaid($noteInput, $id, $raid), SANCTUARY_NOTE_MAX), ]; } $entries[$id] = [ 'raids' => $raids, 'details' => $details, 'gearscore' => $score === false ? null : $score, 'combat_power' => $power === false ? null : $power, ]; } if (!$entries) { $errors[] = 'Wähle bei mindestens einem Charakter ein Refugium aus.'; } if (!$windows && !$errors) { $errors[] = 'Trage mindestens ein Zeitfenster ein – Wochentag, Beginn und Ende.'; } if ($errors) { set_flash('error', implode(' ', array_unique($errors))); redirect('/sanctuary.php#mein-eintrag'); } sanctuary_save($userId, $windows, $entries); set_flash('success', 'Gespeichert – du stehst jetzt im Refugien-Planer. Der Eintrag gilt ' . SANCTUARY_EXPIRE_DAYS . ' Tage als aktuell; ' . SANCTUARY_WARN_DAYS . ' Tage vorher erinnern wir dich, ihn zu bestätigen.'); redirect('/sanctuary.php');