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); }