feat: sélecteur de langue dans settings.php — persisté par compte en BDD
Deploy to Pacha Family / deploy (push) Failing after 3s
Deploy to Pacha Family / deploy (push) Failing after 3s
- Sélecteur FR/EN/CA déplacé du header vers settings.php - Colonne lang ajoutée à users (meta DB) — langue sauvegardée par compte - Login charge automatiquement la langue préférée de l'utilisateur - Header nettoyé du sélecteur de langue Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
94d85dc8da
commit
6acda4ab25
@@ -20,6 +20,7 @@ CREATE TABLE IF NOT EXISTS users (
|
|||||||
family_id INT DEFAULT NULL,
|
family_id INT DEFAULT NULL,
|
||||||
is_admin TINYINT(1) DEFAULT 0,
|
is_admin TINYINT(1) DEFAULT 0,
|
||||||
is_active TINYINT(1) DEFAULT 1,
|
is_active TINYINT(1) DEFAULT 1,
|
||||||
|
lang VARCHAR(5) DEFAULT 'fr',
|
||||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
FOREIGN KEY (family_id) REFERENCES families(id)
|
FOREIGN KEY (family_id) REFERENCES families(id)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|||||||
@@ -54,13 +54,6 @@ $currentLang = $_SESSION['app_lang'] ?? 'fr';
|
|||||||
|
|
||||||
<div class="pf-header-right">
|
<div class="pf-header-right">
|
||||||
|
|
||||||
<div style="display: flex; align-items: center; gap: 8px;">
|
|
||||||
<a href="<?= getLangUrl('fr') ?>" style="text-decoration:none; font-weight:bold; font-size:1rem; color: <?= $currentLang === 'fr' ? '#2563eb' : '#94a3b8' ?>;" title="Français">FR</a>
|
|
||||||
<span style="color: #cbd5e1;">|</span>
|
|
||||||
<a href="<?= getLangUrl('ca') ?>" style="text-decoration:none; font-weight:bold; font-size:1rem; color: <?= $currentLang === 'ca' ? '#f59e0b' : '#94a3b8' ?>;" title="Català">CA</a>
|
|
||||||
<span style="color: #cbd5e1;">|</span>
|
|
||||||
<a href="<?= getLangUrl('en') ?>" style="text-decoration:none; font-weight:bold; font-size:1rem; color: <?= $currentLang === 'en' ? '#16a34a' : '#94a3b8' ?>;" title="English">EN</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php if (isset($_SESSION['user'])): ?>
|
<?php if (isset($_SESSION['user'])): ?>
|
||||||
<div class="pf-desktop-actions" style="display: flex; align-items: center; gap: 10px; border-left: 1px solid #cbd5e1; padding-left: 15px;">
|
<div class="pf-desktop-actions" style="display: flex; align-items: center; gap: 10px; border-left: 1px solid #cbd5e1; padding-left: 15px;">
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$error = tr('error_missing_fields');
|
$error = tr('error_missing_fields');
|
||||||
} else {
|
} else {
|
||||||
$stmt = $meta_pdo->prepare("
|
$stmt = $meta_pdo->prepare("
|
||||||
SELECT u.id, u.username, u.password_hash, u.display_name, u.family_id, u.is_admin, u.is_active, f.db_name, f.is_active as family_active
|
SELECT u.id, u.username, u.password_hash, u.display_name, u.family_id, u.is_admin, u.is_active, u.lang, f.db_name, f.is_active as family_active
|
||||||
FROM users u
|
FROM users u
|
||||||
LEFT JOIN families f ON f.id = u.family_id
|
LEFT JOIN families f ON f.id = u.family_id
|
||||||
WHERE u.username = ?
|
WHERE u.username = ?
|
||||||
@@ -43,6 +43,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
'is_admin' => (bool)$user['is_admin'],
|
'is_admin' => (bool)$user['is_admin'],
|
||||||
];
|
];
|
||||||
$_SESSION['family_db'] = $user['db_name'];
|
$_SESSION['family_db'] = $user['db_name'];
|
||||||
|
$_SESSION['app_lang'] = $user['lang'] ?? 'fr';
|
||||||
$redirectTo = $_GET['redirect'] ?? '/index.php';
|
$redirectTo = $_GET['redirect'] ?? '/index.php';
|
||||||
header('Location: ' . $redirectTo);
|
header('Location: ' . $redirectTo);
|
||||||
exit;
|
exit;
|
||||||
|
|||||||
@@ -14,6 +14,16 @@ $success = null;
|
|||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$action = $_POST['action'] ?? '';
|
$action = $_POST['action'] ?? '';
|
||||||
|
|
||||||
|
if ($action === 'set_lang') {
|
||||||
|
$lang = $_POST['lang'] ?? 'fr';
|
||||||
|
if (in_array($lang, ['fr', 'ca', 'en'])) {
|
||||||
|
$_SESSION['app_lang'] = $lang;
|
||||||
|
$meta_pdo->prepare("UPDATE users SET lang = ? WHERE id = ?")
|
||||||
|
->execute([$lang, $user_id]);
|
||||||
|
$success = "Language updated.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($action === 'update_profile') {
|
if ($action === 'update_profile') {
|
||||||
$display_name = trim($_POST['display_name'] ?? '');
|
$display_name = trim($_POST['display_name'] ?? '');
|
||||||
if (!$display_name) {
|
if (!$display_name) {
|
||||||
@@ -98,6 +108,25 @@ require __DIR__ . '/header.php';
|
|||||||
<div style="background:#fee2e2;border:1px solid #fca5a5;border-radius:8px;padding:12px 16px;margin-bottom:24px;color:#991b1b">✗ <?= htmlspecialchars($error) ?></div>
|
<div style="background:#fee2e2;border:1px solid #fca5a5;border-radius:8px;padding:12px 16px;margin-bottom:24px;color:#991b1b">✗ <?= htmlspecialchars($error) ?></div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<!-- ── Langue ─────────────────────────────────────────────────────────── -->
|
||||||
|
<section style="background:white;border:1px solid #e2e8f0;border-radius:12px;padding:24px;margin-bottom:24px">
|
||||||
|
<h2 style="font-size:1rem;font-weight:700;margin-bottom:20px">🌐 Langue / Language</h2>
|
||||||
|
<form method="post" style="display:flex;gap:10px;flex-wrap:wrap">
|
||||||
|
<input type="hidden" name="action" value="set_lang">
|
||||||
|
<?php
|
||||||
|
$langs = ['fr' => '🇫🇷 Français', 'en' => '🇬🇧 English', 'ca' => '🏴 Català'];
|
||||||
|
$currentLang = $_SESSION['app_lang'] ?? 'fr';
|
||||||
|
foreach ($langs as $code => $label):
|
||||||
|
?>
|
||||||
|
<button type="submit" name="lang" value="<?= $code ?>"
|
||||||
|
class="pf-btn <?= $currentLang === $code ? '' : 'btn-secondary' ?>"
|
||||||
|
style="<?= $currentLang === $code ? 'pointer-events:none' : '' ?>">
|
||||||
|
<?= $label ?>
|
||||||
|
</button>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
<!-- ── Profil ──────────────────────────────────────────────────────────── -->
|
<!-- ── Profil ──────────────────────────────────────────────────────────── -->
|
||||||
<section style="background:white;border:1px solid #e2e8f0;border-radius:12px;padding:24px;margin-bottom:24px">
|
<section style="background:white;border:1px solid #e2e8f0;border-radius:12px;padding:24px;margin-bottom:24px">
|
||||||
<h2 style="font-size:1rem;font-weight:700;margin-bottom:20px">👤 Mon profil</h2>
|
<h2 style="font-size:1rem;font-weight:700;margin-bottom:20px">👤 Mon profil</h2>
|
||||||
|
|||||||
Reference in New Issue
Block a user