156 lines
5.4 KiB
PHP
156 lines
5.4 KiB
PHP
<?php
|
|
require_once '../includes/config.php';
|
|
require_once '../includes/auth.php';
|
|
require_once '../includes/site-upload.php';
|
|
|
|
// Vérification de l'authentification
|
|
if (!Auth::check()) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$success = '';
|
|
$error = '';
|
|
|
|
// Traitement du formulaire
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
try {
|
|
$config = Config::load();
|
|
|
|
// Mise à jour des valeurs textuelles
|
|
$config['site']['name'] = trim($_POST['site_name'] ?? '');
|
|
$config['site']['description'] = trim($_POST['site_description'] ?? '');
|
|
|
|
// Validation
|
|
if (empty($config['site']['name'])) {
|
|
throw new Exception('Le nom du site est requis');
|
|
}
|
|
|
|
// Gestion de l'upload du logo
|
|
if (isset($_FILES['site_logo']) && $_FILES['site_logo']['error'] !== UPLOAD_ERR_NO_FILE) {
|
|
$uploadHandler = new SiteUploadHandler();
|
|
$config['site']['logo'] = $uploadHandler->handleLogoUpload($_FILES['site_logo']);
|
|
}
|
|
|
|
// Sauvegarde
|
|
Config::save($config);
|
|
$success = 'Configuration mise à jour avec succès';
|
|
|
|
} catch (Exception $e) {
|
|
$error = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
// Chargement de la configuration actuelle
|
|
$config = Config::load();
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Options du site - Administration</title>
|
|
<link rel="stylesheet" href="../assets/css/main.css">
|
|
</head>
|
|
<body>
|
|
<nav class="admin-nav">
|
|
<div class="nav-brand">
|
|
<?php
|
|
$config = Config::load();
|
|
if (!empty($config['site']['logo'])): ?>
|
|
<img src="<?= htmlspecialchars('../' . $config['site']['logo']) ?>"
|
|
alt="<?= htmlspecialchars($config['site']['name']) ?>">
|
|
<?php endif; ?>
|
|
<span>Administration</span>
|
|
</div>
|
|
<div class="nav-menu">
|
|
<a href="index.php" class="button">Retour</a>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="admin-main">
|
|
<h1>Options du site</h1>
|
|
|
|
<?php if ($success): ?>
|
|
<div class="success-message"><?= htmlspecialchars($success) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="error-message"><?= htmlspecialchars($error) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST" class="options-form" enctype="multipart/form-data">
|
|
<div class="form-group">
|
|
<label for="site_name">Nom du site</label>
|
|
<input type="text"
|
|
id="site_name"
|
|
name="site_name"
|
|
value="<?= htmlspecialchars($config['site']['name']) ?>"
|
|
required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="site_description">Description du site</label>
|
|
<textarea id="site_description"
|
|
name="site_description"
|
|
rows="4"><?= htmlspecialchars($config['site']['description']) ?></textarea>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="site_logo">Logo du site</label>
|
|
<?php if (!empty($config['site']['logo'])): ?>
|
|
<div class="current-logo">
|
|
<img src="<?= htmlspecialchars('../' . $config['site']['logo']) ?>"
|
|
alt="Logo actuel"
|
|
style="max-height: 100px; margin: 10px 0;">
|
|
</div>
|
|
<?php endif; ?>
|
|
<input type="file"
|
|
id="site_logo"
|
|
name="site_logo"
|
|
accept="image/jpeg,image/png,image/gif,image/svg+xml">
|
|
<small>Formats acceptés : JPG, PNG, GIF, SVG. Taille maximum : 2MB</small>
|
|
</div>
|
|
|
|
<button type="submit" class="button">Enregistrer les modifications</button>
|
|
</form>
|
|
</main>
|
|
|
|
<script>
|
|
// Prévisualisation du logo
|
|
document.getElementById('site_logo').addEventListener('change', function(e) {
|
|
const file = e.target.files[0];
|
|
if (file) {
|
|
const reader = new FileReader();
|
|
reader.onload = function(e) {
|
|
let currentLogo = document.querySelector('.current-logo');
|
|
if (!currentLogo) {
|
|
currentLogo = document.createElement('div');
|
|
currentLogo.className = 'current-logo';
|
|
e.target.parentElement.insertBefore(currentLogo, e.target.nextSibling);
|
|
}
|
|
currentLogo.innerHTML = `
|
|
<img src="${e.target.result}"
|
|
alt="Aperçu du logo"
|
|
style="max-height: 100px; margin: 10px 0;">
|
|
`;
|
|
};
|
|
reader.readAsDataURL(file);
|
|
}
|
|
});
|
|
|
|
// Détection des changements non sauvegardés
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const form = document.querySelector('form');
|
|
const initialState = new FormData(form).toString();
|
|
|
|
window.addEventListener('beforeunload', (e) => {
|
|
if (new FormData(form).toString() !== initialState) {
|
|
e.preventDefault();
|
|
e.returnValue = '';
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|