71 lines
2.3 KiB
PHP
71 lines
2.3 KiB
PHP
<?php
|
|
// include/user_settings_loader.php
|
|
|
|
// Evita inclusioni multiple
|
|
if (defined('USER_SETTINGS_LOADED')) return;
|
|
define('USER_SETTINGS_LOADED', true);
|
|
|
|
global $userSettings; // o usa $_SESSION['user_settings'] se preferisci
|
|
|
|
$user_id = (int)($iduserlogin ?? $_SESSION['iduserlogin'] ?? 0);
|
|
|
|
if ($user_id <= 0) {
|
|
// Utente non loggato → valori di default minimi/sicuri
|
|
$userSettings = [
|
|
'notify_email' => 1,
|
|
'notify_whatsapp' => 0,
|
|
'notify_push' => 0,
|
|
'notify_booking_confirm' => 1,
|
|
'notify_booking_cancel' => 1,
|
|
'notify_session_cancel' => 1,
|
|
'notify_payment_receipt' => 1,
|
|
'notify_expiration_reminder' => 1,
|
|
'newsletter_opt_in' => 0,
|
|
'marketing_opt_in' => 0,
|
|
'locale' => 'it',
|
|
'timezone' => 'Europe/Rome',
|
|
];
|
|
} else {
|
|
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
|
|
|
$stmt = $pdo->prepare("
|
|
SELECT *
|
|
FROM user_settings
|
|
WHERE user_id = ?
|
|
LIMIT 1
|
|
");
|
|
$stmt->execute([$user_id]);
|
|
$settings = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($settings) {
|
|
$userSettings = $settings;
|
|
} else {
|
|
// Utente senza impostazioni → crea record con default
|
|
$stmt_insert = $pdo->prepare("
|
|
INSERT INTO user_settings (user_id) VALUES (?)
|
|
");
|
|
$stmt_insert->execute([$user_id]);
|
|
|
|
// Ricarica dopo insert
|
|
$stmt = $pdo->prepare("SELECT * FROM user_settings WHERE user_id = ? LIMIT 1");
|
|
$stmt->execute([$user_id]);
|
|
$userSettings = $stmt->fetch(PDO::FETCH_ASSOC) ?: [];
|
|
}
|
|
|
|
// Fallback per campi che potrebbero essere NULL o mancanti
|
|
$userSettings = array_merge([
|
|
'notify_email' => 1,
|
|
'notify_whatsapp' => 0,
|
|
'notify_push' => 0,
|
|
'notify_booking_confirm' => 1,
|
|
'notify_booking_cancel' => 1,
|
|
'notify_session_cancel' => 1,
|
|
'notify_payment_receipt' => 1,
|
|
'notify_expiration_reminder' => 1,
|
|
'newsletter_opt_in' => 0,
|
|
'marketing_opt_in' => 0,
|
|
'locale' => 'it',
|
|
'timezone' => 'Europe/Rome',
|
|
], $userSettings);
|
|
}
|