349 lines
14 KiB
PHP
349 lines
14 KiB
PHP
<?php
|
|
// Forza la visualizzazione degli errori (solo dev)
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
session_start();
|
|
}
|
|
|
|
include('include/headscript.php');
|
|
|
|
// Connessione DB
|
|
$dbHandler = DBHandlerSelect::getInstance();
|
|
$pdo = $dbHandler->getConnection();
|
|
|
|
// Verifica utente loggato
|
|
if (!isset($iduserlogin)) {
|
|
header("Location: login.php");
|
|
exit;
|
|
}
|
|
|
|
// ===========================
|
|
// Helpers flash
|
|
// ===========================
|
|
function setFlash(string $type, string $text): void
|
|
{
|
|
$_SESSION['flash'] = ['type' => $type, 'text' => $text];
|
|
}
|
|
|
|
function getFlash(): ?array
|
|
{
|
|
if (!isset($_SESSION['flash'])) return null;
|
|
$f = $_SESSION['flash'];
|
|
unset($_SESSION['flash']);
|
|
return $f;
|
|
}
|
|
|
|
// ===========================
|
|
// POST - Salva impostazioni utente
|
|
// ===========================
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
try {
|
|
$receive_newsletter = isset($_POST['receive_newsletter']) ? 1 : 0;
|
|
$receive_marketing_offers = isset($_POST['receive_marketing_offers']) ? 1 : 0;
|
|
$notify_new_appointment = isset($_POST['notify_new_appointment']) ? 1 : 0;
|
|
$notify_reminder = isset($_POST['notify_reminder']) ? 1 : 0;
|
|
$notify_cancellation = isset($_POST['notify_cancellation']) ? 1 : 0;
|
|
$notify_modification = isset($_POST['notify_modification']) ? 1 : 0;
|
|
$notify_email = isset($_POST['notify_email']) ? 1 : 0;
|
|
$notify_sms = isset($_POST['notify_sms']) ? 1 : 0;
|
|
$notify_whatsapp = isset($_POST['notify_whatsapp']) ? 1 : 0;
|
|
|
|
// Controlla esistenza riga
|
|
$stmt = $pdo->prepare("SELECT id FROM user_settings WHERE user_id = ?");
|
|
$stmt->execute([$iduserlogin]);
|
|
$exists = $stmt->fetchColumn() !== false;
|
|
|
|
if ($exists) {
|
|
$stmt = $pdo->prepare("
|
|
UPDATE user_settings SET
|
|
receive_newsletter = ?,
|
|
receive_marketing_offers = ?,
|
|
notify_new_appointment = ?,
|
|
notify_reminder = ?,
|
|
notify_cancellation = ?,
|
|
notify_modification = ?,
|
|
notify_email = ?,
|
|
notify_sms = ?,
|
|
notify_whatsapp = ?,
|
|
updated_at = NOW()
|
|
WHERE user_id = ?
|
|
");
|
|
$ok = $stmt->execute([
|
|
$receive_newsletter,
|
|
$receive_marketing_offers,
|
|
$notify_new_appointment,
|
|
$notify_reminder,
|
|
$notify_cancellation,
|
|
$notify_modification,
|
|
$notify_email,
|
|
$notify_sms,
|
|
$notify_whatsapp,
|
|
$iduserlogin
|
|
]);
|
|
} else {
|
|
$stmt = $pdo->prepare("
|
|
INSERT INTO user_settings (
|
|
user_id, receive_newsletter, receive_marketing_offers,
|
|
notify_new_appointment, notify_reminder, notify_cancellation,
|
|
notify_modification, notify_email, notify_sms, notify_whatsapp
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
");
|
|
$ok = $stmt->execute([
|
|
$iduserlogin,
|
|
$receive_newsletter,
|
|
$receive_marketing_offers,
|
|
$notify_new_appointment,
|
|
$notify_reminder,
|
|
$notify_cancellation,
|
|
$notify_modification,
|
|
$notify_email,
|
|
$notify_sms,
|
|
$notify_whatsapp
|
|
]);
|
|
}
|
|
|
|
setFlash($ok ? 'success' : 'danger', $ok ? "Preferenze utente salvate!" : "Errore durante il salvataggio.");
|
|
header("Location: user_settings.php");
|
|
exit;
|
|
} catch (Throwable $e) {
|
|
setFlash('danger', "Errore: " . $e->getMessage());
|
|
header("Location: user_settings.php");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// Fetch impostazioni utente
|
|
$stmt = $pdo->prepare("SELECT * FROM user_settings WHERE user_id = ?");
|
|
$stmt->execute([$iduserlogin]);
|
|
$userSettings = $stmt->fetch(PDO::FETCH_ASSOC) ?: [
|
|
'receive_newsletter' => 1,
|
|
'receive_marketing_offers' => 1,
|
|
'notify_new_appointment' => 1,
|
|
'notify_reminder' => 1,
|
|
'notify_cancellation' => 1,
|
|
'notify_modification' => 1,
|
|
'notify_email' => 1,
|
|
'notify_sms' => 0,
|
|
'notify_whatsapp' => 0
|
|
];
|
|
|
|
$flash = getFlash();
|
|
?>
|
|
|
|
<!doctype html>
|
|
<html lang="it">
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
|
|
<?php include('cssinclude.php'); ?>
|
|
<?php include('siteinfo.php'); ?>
|
|
<title>Le Mie Impostazioni - Notifiche & Newsletter</title>
|
|
<style>
|
|
.settings-card {
|
|
border: none;
|
|
border-radius: 16px;
|
|
overflow: hidden;
|
|
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
|
|
}
|
|
|
|
.settings-header {
|
|
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
|
|
color: white;
|
|
padding: 2rem;
|
|
}
|
|
|
|
.form-section {
|
|
background: #ffffff;
|
|
padding: 2.5rem;
|
|
}
|
|
|
|
.section-title {
|
|
font-size: 1.35rem;
|
|
font-weight: 700;
|
|
margin: 2.5rem 0 1.5rem;
|
|
color: #1f2937;
|
|
position: relative;
|
|
}
|
|
|
|
.section-title::after {
|
|
content: '';
|
|
position: absolute;
|
|
bottom: -8px;
|
|
left: 0;
|
|
width: 60px;
|
|
height: 3px;
|
|
background: #3b82f6;
|
|
border-radius: 3px;
|
|
}
|
|
|
|
.toggle-group {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 1.25rem 0;
|
|
border-bottom: 1px solid #f3f4f6;
|
|
}
|
|
|
|
.toggle-group:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.toggle-label {
|
|
font-size: 1.15rem;
|
|
font-weight: 600;
|
|
color: #111827;
|
|
}
|
|
|
|
.form-check-input-lg {
|
|
width: 3.2rem;
|
|
height: 1.7rem;
|
|
}
|
|
|
|
.form-check-input-lg:checked {
|
|
background-color: #3b82f6;
|
|
border-color: #3b82f6;
|
|
}
|
|
|
|
.btn-save {
|
|
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
|
|
border: none;
|
|
padding: 1.2rem 3rem;
|
|
font-size: 1.15rem;
|
|
font-weight: 600;
|
|
border-radius: 12px;
|
|
transition: all 0.3s;
|
|
}
|
|
|
|
.btn-save:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 10px 25px rgba(16, 185, 129, 0.4);
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="wrapper">
|
|
<?php include('include/navbar.php'); ?>
|
|
<?php include('include/topbar.php'); ?>
|
|
|
|
<div class="page-wrapper">
|
|
<div class="page-content">
|
|
<div class="settings-card">
|
|
<div class="settings-header d-flex justify-content-between align-items-center">
|
|
<h5 class="mb-0">Le Mie Impostazioni</h5>
|
|
<a href="user_dashboard.php" class="btn btn-light btn-sm px-4">
|
|
<i class="bx bx-arrow-back me-2"></i> Dashboard
|
|
</a>
|
|
</div>
|
|
|
|
<div class="form-section">
|
|
<?php if ($flash): ?>
|
|
<div class="alert alert-<?= $flash['type'] ?> alert-dismissible fade show mb-5 shadow-sm" role="alert">
|
|
<i class="bx <?= $flash['type'] === 'success' ? 'bx-check-circle' : 'bx-error-circle' ?> me-2"></i>
|
|
<?= htmlspecialchars($flash['text']) ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form action="" method="POST">
|
|
<!-- Sezione Newsletter & Marketing -->
|
|
<div class="section-title">Newsletter & Offerte</div>
|
|
<div class="toggle-group">
|
|
<label class="toggle-label" for="newsletter">Ricevi newsletter e promozioni</label>
|
|
<div class="form-check form-switch form-switch-lg">
|
|
<input class="form-check-input form-check-input-lg" type="checkbox" name="receive_newsletter" id="newsletter" <?= $userSettings['receive_newsletter'] ? 'checked' : '' ?>>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="toggle-group">
|
|
<label class="toggle-label" for="marketing">Ricevi offerte speciali e sconti</label>
|
|
<div class="form-check form-switch form-switch-lg">
|
|
<input class="form-check-input form-check-input-lg" type="checkbox" name="receive_marketing_offers" id="marketing" <?= $userSettings['receive_marketing_offers'] ? 'checked' : '' ?>>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Sezione Notifiche Appuntamenti -->
|
|
<div class="section-title mt-5">Notifiche Appuntamenti</div>
|
|
<div class="toggle-group">
|
|
<label class="toggle-label" for="newAppt">Nuova prenotazione effettuata</label>
|
|
<div class="form-check form-switch form-switch-lg">
|
|
<input class="form-check-input form-check-input-lg" type="checkbox" name="notify_new_appointment" id="newAppt" <?= $userSettings['notify_new_appointment'] ? 'checked' : '' ?>>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="toggle-group">
|
|
<label class="toggle-label" for="reminder">Promemoria appuntamento (24h prima)</label>
|
|
<div class="form-check form-switch form-switch-lg">
|
|
<input class="form-check-input form-check-input-lg" type="checkbox" name="notify_reminder" id="reminder" <?= $userSettings['notify_reminder'] ? 'checked' : '' ?>>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="toggle-group">
|
|
<label class="toggle-label" for="cancel">Cancellazione appuntamento</label>
|
|
<div class="form-check form-switch form-switch-lg">
|
|
<input class="form-check-input form-check-input-lg" type="checkbox" name="notify_cancellation" id="cancel" <?= $userSettings['notify_cancellation'] ? 'checked' : '' ?>>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="toggle-group">
|
|
<label class="toggle-label" for="modify">Modifica appuntamento (orario/servizio)</label>
|
|
<div class="form-check form-switch form-switch-lg">
|
|
<input class="form-check-input form-check-input-lg" type="checkbox" name="notify_modification" id="modify" <?= $userSettings['notify_modification'] ? 'checked' : '' ?>>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Sezione Canali Notifica -->
|
|
<div class="section-title mt-5">Canali di Notifica</div>
|
|
<div class="row g-4">
|
|
<div class="col-md-4">
|
|
<div class="toggle-group flex-column align-items-start">
|
|
<label class="toggle-label mb-2" for="emailNotify">Email</label>
|
|
<div class="form-check form-switch form-switch-lg">
|
|
<input class="form-check-input" type="checkbox" name="notify_email" id="emailNotify" <?= $userSettings['notify_email'] ? 'checked' : '' ?>>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-4">
|
|
<div class="toggle-group flex-column align-items-start">
|
|
<label class="toggle-label mb-2" for="smsNotify">SMS</label>
|
|
<div class="form-check form-switch form-switch-lg">
|
|
<input class="form-check-input" type="checkbox" name="notify_sms" id="smsNotify" <?= $userSettings['notify_sms'] ? 'checked' : '' ?>>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-4">
|
|
<div class="toggle-group flex-column align-items-start">
|
|
<label class="toggle-label mb-2" for="waNotify">WhatsApp</label>
|
|
<div class="form-check form-switch form-switch-lg">
|
|
<input class="form-check-input" type="checkbox" name="notify_whatsapp" id="waNotify" <?= $userSettings['notify_whatsapp'] ? 'checked' : '' ?>>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Pulsante salva -->
|
|
<div class="d-grid mt-5">
|
|
<button type="submit" class="btn btn-save">
|
|
<i class="bx bx-save me-2"></i> Salva Le Mie Preferenze
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include('include/footer.php'); ?>
|
|
</div>
|
|
|
|
<?php include('jsinclude.php'); ?>
|
|
</body>
|
|
|
|
</html>
|