415 lines
12 KiB
PHP
415 lines
12 KiB
PHP
<?php include('include/headscript.php'); ?>
|
|
<?php
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
$userId = (int)($iduserlogin ?? 0);
|
|
|
|
if ($userId <= 0) {
|
|
die('Utente non valido.');
|
|
}
|
|
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
session_start();
|
|
}
|
|
|
|
if (empty($_SESSION['notif_settings_csrf'])) {
|
|
$_SESSION['notif_settings_csrf'] = bin2hex(random_bytes(32));
|
|
}
|
|
|
|
$csrfToken = $_SESSION['notif_settings_csrf'];
|
|
|
|
$successMessage = '';
|
|
$errorMessage = '';
|
|
|
|
// Load current user notification preferences.
|
|
$stmtUser = $pdo->prepare("
|
|
SELECT
|
|
id,
|
|
email,
|
|
first_name,
|
|
last_name,
|
|
notify_email,
|
|
notify_webapp
|
|
FROM auth_users
|
|
WHERE id = ?
|
|
LIMIT 1
|
|
");
|
|
$stmtUser->execute([$userId]);
|
|
$profileUser = $stmtUser->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$profileUser) {
|
|
die('Utente non trovato.');
|
|
}
|
|
|
|
function e($value)
|
|
{
|
|
return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$postedToken = $_POST['csrf_token'] ?? '';
|
|
|
|
if (!hash_equals($csrfToken, $postedToken)) {
|
|
$errorMessage = 'Sessione non valida. Ricarica la pagina e riprova.';
|
|
} else {
|
|
$notifyEmail = isset($_POST['notify_email']) ? 1 : 0;
|
|
$notifyWebapp = isset($_POST['notify_webapp']) ? 1 : 0;
|
|
|
|
try {
|
|
$stmtUpdate = $pdo->prepare("
|
|
UPDATE auth_users
|
|
SET
|
|
notify_email = :notify_email,
|
|
notify_webapp = :notify_webapp,
|
|
updated_at = NOW()
|
|
WHERE id = :id
|
|
LIMIT 1
|
|
");
|
|
|
|
$stmtUpdate->execute([
|
|
':notify_email' => $notifyEmail,
|
|
':notify_webapp' => $notifyWebapp,
|
|
':id' => $userId,
|
|
]);
|
|
|
|
$successMessage = 'Preferenze di notifica aggiornate correttamente.';
|
|
|
|
// Reload updated user.
|
|
$stmtUser->execute([$userId]);
|
|
$profileUser = $stmtUser->fetch(PDO::FETCH_ASSOC);
|
|
|
|
$_SESSION['notif_settings_csrf'] = bin2hex(random_bytes(32));
|
|
$csrfToken = $_SESSION['notif_settings_csrf'];
|
|
} catch (Exception $e) {
|
|
$errorMessage = 'Errore durante il salvataggio delle preferenze.';
|
|
}
|
|
}
|
|
}
|
|
|
|
$notifyEmail = (int)($profileUser['notify_email'] ?? 0);
|
|
$notifyWebapp = (int)($profileUser['notify_webapp'] ?? 0);
|
|
?>
|
|
<!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'); ?>
|
|
<title>Notifiche <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
|
|
|
<style>
|
|
body {
|
|
background: linear-gradient(135deg, #f3f6f8, #e8eef3);
|
|
font-family: 'Segoe UI', sans-serif;
|
|
color: #2b3e50;
|
|
}
|
|
|
|
.page-content {
|
|
padding: 1.4rem 1rem;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
}
|
|
|
|
.settings-wrap {
|
|
width: 100%;
|
|
max-width: 820px;
|
|
}
|
|
|
|
h3.settings-title {
|
|
text-align: center;
|
|
font-weight: 800;
|
|
color: #2b3e50;
|
|
margin-bottom: 1.2rem;
|
|
letter-spacing: 0.3px;
|
|
}
|
|
|
|
.settings-card {
|
|
background: #fff;
|
|
border-radius: 16px;
|
|
box-shadow: 0 5px 12px rgba(0, 0, 0, 0.08);
|
|
margin-bottom: 16px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.settings-header {
|
|
padding: 16px 18px;
|
|
border-bottom: 1px solid rgba(0, 0, 0, 0.06);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
}
|
|
|
|
.settings-icon {
|
|
font-size: 1.8rem;
|
|
line-height: 1;
|
|
}
|
|
|
|
.settings-heading {
|
|
margin: 0;
|
|
font-weight: 800;
|
|
font-size: 1.1rem;
|
|
}
|
|
|
|
.settings-subtitle {
|
|
margin: 0;
|
|
color: #6b7a89;
|
|
font-size: 0.92rem;
|
|
}
|
|
|
|
.settings-body {
|
|
padding: 20px;
|
|
}
|
|
|
|
.notif-row {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 16px;
|
|
padding: 18px 20px;
|
|
border-radius: 16px;
|
|
border: 1px solid #e2e8f0;
|
|
background: linear-gradient(135deg, #f9fbfd, #f2f7fc);
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.notif-info {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 14px;
|
|
}
|
|
|
|
.notif-emoji {
|
|
font-size: 2rem;
|
|
line-height: 1;
|
|
width: 54px;
|
|
height: 54px;
|
|
border-radius: 16px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
background: #fff;
|
|
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.06);
|
|
}
|
|
|
|
.notif-texts h6 {
|
|
margin: 0;
|
|
font-weight: 800;
|
|
font-size: 1.02rem;
|
|
color: #2b3e50;
|
|
}
|
|
|
|
.notif-texts p {
|
|
margin: 2px 0 0 0;
|
|
color: #6b7a89;
|
|
font-size: 0.88rem;
|
|
}
|
|
|
|
/* Toggle switch */
|
|
.switch {
|
|
position: relative;
|
|
display: inline-block;
|
|
width: 58px;
|
|
height: 32px;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.switch input {
|
|
opacity: 0;
|
|
width: 0;
|
|
height: 0;
|
|
}
|
|
|
|
.slider {
|
|
position: absolute;
|
|
cursor: pointer;
|
|
inset: 0;
|
|
background: #cbd5e1;
|
|
transition: 0.3s;
|
|
border-radius: 34px;
|
|
}
|
|
|
|
.slider:before {
|
|
position: absolute;
|
|
content: "";
|
|
height: 24px;
|
|
width: 24px;
|
|
left: 4px;
|
|
bottom: 4px;
|
|
background: #fff;
|
|
transition: 0.3s;
|
|
border-radius: 50%;
|
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
|
}
|
|
|
|
input:checked+.slider {
|
|
background: linear-gradient(135deg, #61ce5d, #4fb84b);
|
|
}
|
|
|
|
input:checked+.slider:before {
|
|
transform: translateX(26px);
|
|
}
|
|
|
|
.btn-save-settings {
|
|
border: 0;
|
|
border-radius: 16px;
|
|
padding: 13px 24px;
|
|
font-size: 1rem;
|
|
font-weight: 800;
|
|
color: #fff;
|
|
background: linear-gradient(135deg, #61ce5dff, #61ce5dff);
|
|
box-shadow: 0 5px 12px rgba(0, 0, 0, 0.08);
|
|
transition: all 0.2s ease;
|
|
}
|
|
|
|
.btn-save-settings:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 8px 18px rgba(0, 0, 0, 0.13);
|
|
color: #fff;
|
|
}
|
|
|
|
.btn-back {
|
|
border: 0;
|
|
border-radius: 16px;
|
|
padding: 13px 20px;
|
|
font-size: 1rem;
|
|
font-weight: 800;
|
|
color: #2b3e50;
|
|
background: linear-gradient(135deg, #e5e7eb, #f3f4f6);
|
|
box-shadow: 0 5px 12px rgba(0, 0, 0, 0.08);
|
|
transition: all 0.2s ease;
|
|
text-decoration: none;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
}
|
|
|
|
.btn-back:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 8px 18px rgba(0, 0, 0, 0.13);
|
|
color: #2b3e50;
|
|
}
|
|
|
|
.alert {
|
|
border-radius: 16px;
|
|
border: 0;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.actions-row {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
gap: 12px;
|
|
flex-wrap: wrap;
|
|
margin-top: 8px;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.settings-body {
|
|
padding: 16px;
|
|
}
|
|
|
|
.notif-row {
|
|
flex-direction: row;
|
|
align-items: center;
|
|
}
|
|
|
|
.actions-row {
|
|
flex-direction: column;
|
|
}
|
|
|
|
.btn-save-settings,
|
|
.btn-back {
|
|
width: 100%;
|
|
justify-content: center;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="wrapper toggled">
|
|
<?php include('include/navbar.php'); ?>
|
|
<?php include('include/topbar.php'); ?>
|
|
|
|
<div class="page-wrapper">
|
|
<div class="page-content">
|
|
|
|
<div class="settings-wrap">
|
|
<h3 class="settings-title">Preferenze di Notifica</h3>
|
|
|
|
<?php if ($successMessage): ?>
|
|
<div class="alert alert-success">
|
|
<?= e($successMessage); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($errorMessage): ?>
|
|
<div class="alert alert-danger">
|
|
<?= e($errorMessage); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form method="post" autocomplete="off">
|
|
<input type="hidden" name="csrf_token" value="<?= e($csrfToken); ?>">
|
|
|
|
<div class="settings-card">
|
|
<div class="settings-header">
|
|
<div class="settings-icon">🔔</div>
|
|
<div>
|
|
<p class="settings-heading">Canali di notifica</p>
|
|
<p class="settings-subtitle">Scegli come vuoi ricevere gli avvisi del sistema</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="settings-body">
|
|
|
|
<div class="notif-row">
|
|
<div class="notif-info">
|
|
<div class="notif-emoji">📧</div>
|
|
<div class="notif-texts">
|
|
<h6>Notifiche via Email</h6>
|
|
<p>Ricevi gli avvisi all'indirizzo <?= e($profileUser['email']); ?></p>
|
|
</div>
|
|
</div>
|
|
<label class="switch">
|
|
<input type="checkbox" name="notify_email" value="1" <?= $notifyEmail ? 'checked' : ''; ?>>
|
|
<span class="slider"></span>
|
|
</label>
|
|
</div>
|
|
|
|
<div class="notif-row">
|
|
<div class="notif-info">
|
|
<div class="notif-emoji">💻</div>
|
|
<div class="notif-texts">
|
|
<h6>Notifiche in WebApp</h6>
|
|
<p>Ricevi gli avvisi direttamente nell'applicazione</p>
|
|
</div>
|
|
</div>
|
|
<label class="switch">
|
|
<input type="checkbox" name="notify_webapp" value="1" <?= $notifyWebapp ? 'checked' : ''; ?>>
|
|
<span class="slider"></span>
|
|
</label>
|
|
</div>
|
|
|
|
<div class="actions-row">
|
|
<a href="production_dashboard.php" class="btn-back">← Torna alla dashboard</a>
|
|
<button type="submit" class="btn-save-settings">Salva preferenze</button>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<?php include('jsinclude.php'); ?>
|
|
<?php include('include/footer.php'); ?>
|
|
</div>
|
|
</body>
|
|
|
|
</html>
|