129 lines
6 KiB
PHP
129 lines
6 KiB
PHP
<?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>
|