Actualiser admin_settings.php

This commit is contained in:
2026-05-22 12:34:23 +00:00
parent e6ee6c271e
commit 2b11ef8804

View File

@@ -5,12 +5,64 @@ if ($_SESSION['role'] !== 'Admin') {
header("Location: dashboard.php"); header("Location: dashboard.php");
exit(); exit();
} }
$settingsFile = 'settings.json.php';
$settings = file_exists($settingsFile) ? json_decode(file_get_contents($settingsFile), true) : [
'site_name' => 'Smart House',
'max_attempts' => 3,
'session_timeout' => 900,
'welcome_message' => 'Bienvenue sur votre tableau de bord Smart House.'
];
$success = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$settings['site_name'] = trim($_POST['site_name']);
$settings['max_attempts'] = (int)$_POST['max_attempts'];
$settings['session_timeout'] = (int)$_POST['session_timeout'] * 60;
$settings['welcome_message'] = trim($_POST['welcome_message']);
file_put_contents($settingsFile, json_encode($settings, JSON_PRETTY_PRINT));
$success = "Paramètres sauvegardés avec succès !";
}
include 'include/header.php'; include 'include/header.php';
?> ?>
<main> <main>
<div class="logs-container"> <div class="logs-container">
<h2>Paramètres</h2> <h2>⚙️ Paramètres du site</h2>
<p>Seul l'admin peut voir cette page.</p>
<?php if ($success): ?>
<p class="form-success" style="margin-top: 10px;"><?php echo htmlspecialchars($success); ?></p>
<?php endif; ?>
<form method="POST" action="admin_settings.php" style="margin-top: 20px;">
<label class="field-label" for="site_name">Nom du site</label>
<input type="text" id="site_name" name="site_name"
value="<?php echo htmlspecialchars($settings['site_name']); ?>"
style="width:100%; padding:10px; border-radius:8px; border:1px solid #444; background:#1e1e1e; color:#f0f0f0; margin-bottom:15px;">
<label class="field-label" for="max_attempts">Tentatives de connexion max</label>
<input type="number" id="max_attempts" name="max_attempts" min="1" max="10"
value="<?php echo $settings['max_attempts']; ?>"
style="width:100%; padding:10px; border-radius:8px; border:1px solid #444; background:#1e1e1e; color:#f0f0f0; margin-bottom:15px;">
<label class="field-label" for="session_timeout">Durée de session (en minutes)</label>
<input type="number" id="session_timeout" name="session_timeout" min="1" max="120"
value="<?php echo $settings['session_timeout'] / 60; ?>"
style="width:100%; padding:10px; border-radius:8px; border:1px solid #444; background:#1e1e1e; color:#f0f0f0; margin-bottom:15px;">
<label class="field-label" for="welcome_message">Message d'accueil</label>
<textarea id="welcome_message" name="welcome_message" rows="3"
style="width:100%; padding:10px; border-radius:8px; border:1px solid #444; background:#1e1e1e; color:#f0f0f0; margin-bottom:15px; resize:vertical;"><?php echo htmlspecialchars($settings['welcome_message']); ?></textarea>
<button type="submit"
style="padding:12px 30px; background-color:#3bc4e8; color:white; border:none; border-radius:25px; cursor:pointer; font-weight:bold; transition: background-color 0.3s;">
💾 Sauvegarder
</button>
</form>
</div> </div>
</main> </main>
<?php include 'include/footer.php'; ?> <?php include 'include/footer.php'; ?>