Portfolio_pero/admin/settings.php
2026-09-03 13:27:06 +02:00

129 lines
6 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* BackOffice — Paramètres globaux
* Portfolio Tony AVERTY
*/
require_once __DIR__ . '/../includes/Security.php';
Security::bootstrap(true, ['no_store' => true]);
Security::requireAdmin();
require_once __DIR__ . '/../config/database.php';
$db = getDatabase();
$feedback = '';
$feedbackType = '';
// ── Sauvegarde ────────────────────────────────────────────
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
Security::verifyCsrf($_POST['csrf_token'] ?? '');
$saved = 0;
foreach ($_POST as $key => $value) {
if (str_starts_with($key, 'setting_')) {
$settingKey = substr($key, 8);
$db->prepare('UPDATE site_settings SET setting_value = :val WHERE setting_key = :key')
->execute(['val' => trim($value), 'key' => $settingKey]);
$saved++;
}
}
$feedback = "{$saved} paramètre(s) enregistré(s).";
$feedbackType = 'success';
}
// ── Chargement ────────────────────────────────────────────
$settings = [];
foreach ($db->query('SELECT * FROM site_settings ORDER BY id ASC')->fetchAll() as $row) {
$settings[$row['setting_key']] = $row;
}
$settingGroups = [
'Identité' => ['site_name', 'owner_name', 'owner_email', 'site_url'],
'Notifications' => ['notify_email'],
'Comportement' => ['availability', 'maintenance_mode'],
'Intégrations' => ['google_analytics_id'],
];
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="noindex, nofollow">
<title>Paramètres — BackOffice Tony AVERTY</title>
<link rel="stylesheet" href="assets/admin.css">
</head>
<body>
<div class="admin-page">
<?php require __DIR__ . '/includes/nav.php'; ?>
<main class="admin-content">
<div class="admin-topbar">
<h1 class="admin-page-title">Paramètres globaux</h1>
</div>
<?php if ($feedback): ?>
<div class="admin-alert admin-alert--<?= $feedbackType ?>"><?= htmlspecialchars($feedback, ENT_QUOTES, 'UTF-8') ?></div>
<?php endif; ?>
<form method="post">
<?= Security::csrfInput() ?>
<?php foreach ($settingGroups as $groupLabel => $keys): ?>
<div class="admin-form" style="margin-bottom:1.5rem;">
<h2 class="form-section-title"><?= $groupLabel ?></h2>
<?php foreach ($keys as $key): ?>
<?php if (!isset($settings[$key])) continue; ?>
<?php $s = $settings[$key]; ?>
<div class="admin-form__group">
<label class="admin-form__label" for="setting_<?= htmlspecialchars($key, ENT_QUOTES, 'UTF-8') ?>">
<?= htmlspecialchars($s['label'], ENT_QUOTES, 'UTF-8') ?>
<span class="admin-form__hint">· <?= htmlspecialchars($key, ENT_QUOTES, 'UTF-8') ?></span>
</label>
<?php if (in_array($key, ['availability', 'maintenance_mode'])): ?>
<select name="setting_<?= htmlspecialchars($key, ENT_QUOTES, 'UTF-8') ?>"
class="admin-form__select"
id="setting_<?= htmlspecialchars($key, ENT_QUOTES, 'UTF-8') ?>">
<?php if ($key === 'availability'): ?>
<option value="1" <?= $s['setting_value'] === '1' ? 'selected' : '' ?>>Disponible</option>
<option value="0" <?= $s['setting_value'] === '0' ? 'selected' : '' ?>>Non disponible</option>
<?php else: ?>
<option value="0" <?= $s['setting_value'] === '0' ? 'selected' : '' ?>>Désactivé</option>
<option value="1" <?= $s['setting_value'] === '1' ? 'selected' : '' ?>>Activé</option>
<?php endif; ?>
</select>
<?php else: ?>
<input type="<?= $key === 'owner_email' || $key === 'notify_email' ? 'email' : 'text' ?>"
id="setting_<?= htmlspecialchars($key, ENT_QUOTES, 'UTF-8') ?>"
name="setting_<?= htmlspecialchars($key, ENT_QUOTES, 'UTF-8') ?>"
class="admin-form__input"
value="<?= htmlspecialchars($s['setting_value'] ?? '', ENT_QUOTES, 'UTF-8') ?>">
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
<div style="position:sticky;bottom:1.5rem;z-index:10;text-align:right;">
<button type="submit" class="admin-btn admin-btn--primary" style="box-shadow:0 4px 20px rgba(99,102,241,0.4);">
💾 Enregistrer les paramètres
</button>
</div>
</form>
<!-- ── Infos système ─────────────────────────────── -->
<div class="admin-form" style="margin-top:2rem;">
<h2 class="form-section-title">ℹ️ Infos système</h2>
<table class="admin-table" style="margin-top:1rem;">
<tbody>
<tr><td style="color:var(--admin-text-secondary);">PHP</td><td><strong><?= phpversion() ?></strong></td></tr>
<tr><td style="color:var(--admin-text-secondary);">Serveur</td><td><strong><?= htmlspecialchars($_SERVER['SERVER_SOFTWARE'] ?? 'PHP built-in', ENT_QUOTES, 'UTF-8') ?></strong></td></tr>
<tr><td style="color:var(--admin-text-secondary);">Date serveur</td><td><strong><?= date('d/m/Y H:i:s') ?></strong></td></tr>
<tr><td style="color:var(--admin-text-secondary);">Timezone</td><td><strong><?= date_default_timezone_get() ?></strong></td></tr>
<tr><td style="color:var(--admin-text-secondary);">Backoffice version</td><td><strong>1.0.0</strong></td></tr>
</tbody>
</table>
</div>
</main>
</div>
</body>
</html>