getConnection(); if ($_SERVER['REQUEST_METHOD'] !== 'POST') { header('Location: options.php'); exit; } $waiting = isset($_POST['waitinglist_enabled']) ? 'Y' : 'N'; $showTeacher = isset($_POST['show_teacher']) ? 'Y' : 'N'; $maxCancel = max(0, (int) ($_POST['maxbeforetimecancell'] ?? 0)); try { $exists = (int) $pdo->query("SELECT COUNT(*) AS c FROM `option`")->fetch()['c'] > 0; if ($exists) { $st = $pdo->prepare("UPDATE `option` SET waitinglist_enabled = :w, show_teacher = :s, maxbeforetimecancell = :m LIMIT 1"); } else { $st = $pdo->prepare("INSERT INTO `option` (waitinglist_enabled, show_teacher, maxbeforetimecancell) VALUES (:w, :s, :m)"); } $st->execute([':w' => $waiting, ':s' => $showTeacher, ':m' => (string) $maxCancel]); header('Location: optionsschool.php?message=success'); } catch (Throwable $e) { error_log('options_save: ' . $e->getMessage()); header('Location: options.php?message=error'); } exit;