Files
sld-php-template/pages/profile.php
T
2026-08-19 17:26:06 +01:00

236 lines
10 KiB
PHP

<?php
require_login();
$user = current_user();
$msg_password_success = "";
$msg_password_error = "";
$msg_theme_success = "";
$msg_theme_error = "";
$msg_lang_success = "";
$msg_lang_error = "";
$msg_landing_success = "";
$msg_landing_error = "";
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
if ($action === 'change_password') {
$new_pass = $_POST['new_password'] ?? '';
$confirm_pass = $_POST['confirm_password'] ?? '';
if ($new_pass !== $confirm_pass) {
$msg_password_error = "Le password inserite non coincidono.";
} else {
$res = update_user_password($user['id'], $new_pass);
if ($res['success']) {
$msg_password_success = $res['message'];
} else {
$msg_password_error = $res['message'];
}
}
} elseif ($action === 'update_theme') {
$pri = $_POST['theme_pri'] ?? 98;
$sec = $_POST['theme_sec'] ?? 207;
$thi = $_POST['theme_thi'] ?? 280;
$res = update_user_theme($user['id'], $pri, $sec, $thi);
if ($res['success']) {
$msg_theme_success = $res['message'];
$user = current_user(); // Refresh session data
} else {
$msg_theme_error = $res['message'];
}
} elseif ($action === 'update_language') {
$lang = $_POST['language'] ?? 'it';
$res = update_user_language($user['id'], $lang);
if ($res['success']) {
$msg_lang_success = $res['message'];
$user = current_user();
} else {
$msg_lang_error = $res['message'];
}
} elseif ($action === 'update_landing') {
$bn_id = $_POST['default_blocknote'] ?? '';
$res = update_user_default_blocknote($user['id'], $bn_id);
if ($res['success']) {
$msg_landing_success = $res['message'];
$user = current_user();
} else {
$msg_landing_error = $res['message'];
}
}
}
$pri = $user['theme_pri'] ?? 98;
$sec = $user['theme_sec'] ?? 207;
$thi = $user['theme_thi'] ?? 280;
$current_lang = $user['language'] ?? 'it';
$current_default_bn = $user['default_blocknote'] ?? '';
$user_blocknotes = get_user_blocknotes($user['username'], is_admin());
?>
<main class="main-content">
<div class="page-header">
<div class="page-title-group">
<h1><?= __('profile_title') ?></h1>
<p><?= __('profile_desc') ?></p>
</div>
</div>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 2rem;">
<!-- CARD LINGUA INTERFACCIA -->
<div class="card">
<h2 style="font-size: 1.3rem; font-weight: 700; color: #fff; margin-bottom: 1.25rem;"><?= __('card_lang_title') ?></h2>
<?php if (!empty($msg_lang_success)): ?>
<div class="alert alert-success">✅ <?= htmlspecialchars($msg_lang_success) ?></div>
<?php endif; ?>
<?php if (!empty($msg_lang_error)): ?>
<div class="alert alert-danger">⚠️ <?= htmlspecialchars($msg_lang_error) ?></div>
<?php endif; ?>
<form action="index.php?page=profile" method="POST">
<input type="hidden" name="action" value="update_language">
<div class="form-group">
<label for="language"><?= __('label_select_lang') ?></label>
<select name="language" id="language" class="form-control">
<option value="it" <?= ($current_lang === 'it') ? 'selected' : '' ?>>🇮🇹 Italiano</option>
<option value="en" <?= ($current_lang === 'en') ? 'selected' : '' ?>>🇬🇧 English</option>
<option value="es" <?= ($current_lang === 'es') ? 'selected' : '' ?>>🇪🇸 Español</option>
<option value="fr" <?= ($current_lang === 'fr') ? 'selected' : '' ?>>🇫🇷 Français</option>
</select>
</div>
<button type="submit" class="btn btn-secondary" style="margin-top: 1rem; width: 100%; justify-content: center;">
<?= __('btn_save_lang') ?>
</button>
</form>
</div>
<!-- CARD PAGINA DI PRIMO ACCESSO (LANDING PAGE) -->
<div class="card">
<h2 style="font-size: 1.3rem; font-weight: 700; color: #fff; margin-bottom: 1.25rem;"><?= __('card_landing_title') ?></h2>
<?php if (!empty($msg_landing_success)): ?>
<div class="alert alert-success">✅ <?= htmlspecialchars($msg_landing_success) ?></div>
<?php endif; ?>
<?php if (!empty($msg_landing_error)): ?>
<div class="alert alert-danger">⚠️ <?= htmlspecialchars($msg_landing_error) ?></div>
<?php endif; ?>
<form action="index.php?page=profile" method="POST">
<input type="hidden" name="action" value="update_landing">
<div class="form-group">
<label for="default_blocknote"><?= __('label_select_landing') ?></label>
<select name="default_blocknote" id="default_blocknote" class="form-control">
<option value=""><?= __('landing_option_dashboard') ?></option>
<?php foreach ($user_blocknotes as $bn): ?>
<option value="<?= htmlspecialchars($bn['id']) ?>" <?= ($current_default_bn === $bn['id']) ? 'selected' : '' ?>>
<?= __('landing_option_bn_prefix') ?><?= htmlspecialchars($bn['title']) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<button type="submit" class="btn btn-primary" style="margin-top: 1rem; width: 100%; justify-content: center;">
<?= __('btn_save_landing') ?>
</button>
</form>
</div>
<!-- CARD CAMBIO PASSWORD -->
<div class="card">
<h2 style="font-size: 1.3rem; font-weight: 700; color: #fff; margin-bottom: 1.25rem;"><?= __('card_password_title') ?></h2>
<?php if (!empty($msg_password_success)): ?>
<div class="alert alert-success">✅ <?= htmlspecialchars($msg_password_success) ?></div>
<?php endif; ?>
<?php if (!empty($msg_password_error)): ?>
<div class="alert alert-danger">⚠️ <?= htmlspecialchars($msg_password_error) ?></div>
<?php endif; ?>
<form action="index.php?page=profile" method="POST">
<input type="hidden" name="action" value="change_password">
<div class="form-group">
<label for="new_password"><?= __('label_new_pass') ?></label>
<input type="password" name="new_password" id="new_password" class="form-control" required placeholder="<?= htmlspecialchars(__('placeholder_password_new')) ?>">
</div>
<div class="form-group">
<label for="confirm_password"><?= __('label_confirm_pass') ?></label>
<input type="password" name="confirm_password" id="confirm_password" class="form-control" required placeholder="<?= htmlspecialchars(__('placeholder_password_confirm')) ?>">
</div>
<button type="submit" class="btn btn-primary" style="margin-top: 0.5rem; width: 100%; justify-content: center;">
<?= __('btn_update_pass') ?>
</button>
</form>
</div>
<!-- CARD PERSONALIZZAZIONE COLORI TEMA -->
<div class="card">
<h2 style="font-size: 1.3rem; font-weight: 700; color: #fff; margin-bottom: 1.25rem;"><?= __('card_colors_title') ?></h2>
<?php if (!empty($msg_theme_success)): ?>
<div class="alert alert-success">✅ <?= htmlspecialchars($msg_theme_success) ?></div>
<?php endif; ?>
<?php if (!empty($msg_theme_error)): ?>
<div class="alert alert-danger">⚠️ <?= htmlspecialchars($msg_theme_error) ?></div>
<?php endif; ?>
<form action="index.php?page=profile" method="POST">
<input type="hidden" name="action" value="update_theme">
<!-- Colore Primario -->
<div class="form-group">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:0.3rem;">
<label for="theme_pri">Primary Color (HSL Hue)</label>
<span id="pri_val" style="font-weight:700; color:var(--priCol10);"><?= (int)$pri ?>°</span>
</div>
<input type="range" min="0" max="360" name="theme_pri" id="theme_pri" value="<?= (int)$pri ?>" class="form-control" style="cursor:pointer; height: 10px;">
<div class="color-preview-box" style="background: hsl(var(--pri), 100%, 50%); margin-top: 0.5rem; font-size: 0.82rem;">
Preview Primary
</div>
</div>
<!-- Colore Secondario -->
<div class="form-group" style="margin-top: 1.5rem;">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:0.3rem;">
<label for="theme_sec">Secondary Color (HSL Hue)</label>
<span id="sec_val" style="font-weight:700; color:var(--secCol10);"><?= (int)$sec ?>°</span>
</div>
<input type="range" min="0" max="360" name="theme_sec" id="theme_sec" value="<?= (int)$sec ?>" class="form-control" style="cursor:pointer; height: 10px;">
<div class="color-preview-box" style="background: hsl(var(--sec), 100%, 50%); margin-top: 0.5rem; font-size: 0.82rem; color: #fff;">
Preview Secondary
</div>
</div>
<!-- Colore Terziario -->
<div class="form-group" style="margin-top: 1.5rem;">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:0.3rem;">
<label for="theme_thi">Tertiary Color (HSL Hue)</label>
<span id="thi_val" style="font-weight:700; color:var(--thiCol10);"><?= (int)$thi ?>°</span>
</div>
<input type="range" min="0" max="360" name="theme_thi" id="theme_thi" value="<?= (int)$thi ?>" class="form-control" style="cursor:pointer; height: 10px;">
<div class="color-preview-box" style="background: hsl(var(--thi), 100%, 50%); margin-top: 0.5rem; font-size: 0.82rem; color: #fff;">
Preview Tertiary
</div>
</div>
<button type="submit" class="btn btn-secondary" style="margin-top: 1.5rem; width: 100%; justify-content: center;">
<?= __('btn_save_colors') ?>
</button>
</form>
</div>
</div>
</main>