Files
yogibook_aury_new/public/event_options_save.php
T
2026-09-18 09:52:51 +02:00

58 lines
2.1 KiB
PHP

<?php
require_once('include/headscript.php');
/**
* Salvataggio Opzioni Eventi (email/copie/promemoria) nella tabella `option`.
*/
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('Location: event_options.php');
exit();
}
$pdo = DBHandlerSelect::getInstance()->getConnection();
function yn(string $k): string
{
return (isset($_POST[$k]) && $_POST[$k] === 'Y') ? 'Y' : 'N';
}
$ccEmail = trim($_POST['event_notify_email'] ?? '');
$reminderH = max(1, min(168, (int) ($_POST['event_reminder_hours'] ?? 24)));
$offerH = max(1, min(336, (int) ($_POST['event_offer_expiry_hours'] ?? 24)));
try {
// Individua la riga singola di configurazione
$idption = (int) $pdo->query("SELECT idption FROM `option` ORDER BY idption ASC LIMIT 1")->fetchColumn();
$sql = "UPDATE `option` SET
event_notify_email = :cc_email,
event_cc_booking = :cc_booking,
event_cc_promotion = :cc_promotion,
event_cc_user_cancel = :cc_user_cancel,
event_cc_event_cancel = :cc_event_cancel,
event_cc_reminder = :cc_reminder,
event_reminder_enabled = :rem_enabled,
event_reminder_hours = :rem_hours,
event_offer_expiry_hours = :offer_hours
WHERE idption = :idption";
$pdo->prepare($sql)->execute([
':cc_email' => $ccEmail !== '' ? $ccEmail : null,
':cc_booking' => yn('event_cc_booking'),
':cc_promotion' => yn('event_cc_promotion'),
':cc_user_cancel' => yn('event_cc_user_cancel'),
':cc_event_cancel' => yn('event_cc_event_cancel'),
':cc_reminder' => yn('event_cc_reminder'),
':rem_enabled' => yn('event_reminder_enabled'),
':rem_hours' => $reminderH,
':offer_hours' => $offerH,
':idption' => $idption,
]);
header('Location: event_options.php?message=success');
exit();
} catch (Throwable $ex) {
error_log('[event_options_save] ' . $ex->getMessage());
header('Location: event_options.php?message=error');
exit();
}