2025-02-15 19:13:31 +01:00
|
|
|
<?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();
|
|
|
|
|
2025-02-16 22:22:37 +01:00
|
|
|
// Mise à jour des valeurs textuelles du site
|
2025-02-15 19:13:31 +01:00
|
|
|
$config['site']['name'] = trim($_POST['site_name'] ?? '');
|
|
|
|
$config['site']['description'] = trim($_POST['site_description'] ?? '');
|
|
|
|
|
2025-02-16 22:22:37 +01:00
|
|
|
// Mise à jour des valeurs de la page À propos
|
|
|
|
$config['about']['title'] = trim($_POST['about_title'] ?? 'À propos');
|
|
|
|
$config['about']['content'] = $_POST['about_content'] ?? '';
|
|
|
|
|
2025-02-15 19:13:31 +01:00
|
|
|
// 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']);
|
|
|
|
}
|
2025-02-16 22:22:37 +01:00
|
|
|
|
|
|
|
// Gestion de l'upload du background de la page À propos
|
|
|
|
if (isset($_FILES['about_background']) && $_FILES['about_background']['error'] !== UPLOAD_ERR_NO_FILE) {
|
|
|
|
$uploadHandler = new SiteUploadHandler();
|
|
|
|
$config['about']['background'] = $uploadHandler->handleBackgroundUpload($_FILES['about_background']);
|
|
|
|
}
|
2025-02-15 19:13:31 +01:00
|
|
|
|
|
|
|
// 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>
|
2025-02-15 22:04:35 +01:00
|
|
|
<?php if (file_exists(__DIR__ . '/../assets/images/site/favicon.png')): ?>
|
|
|
|
<link rel="icon" type="image/png" href="../assets/images/site/favicon.png">
|
|
|
|
<?php endif; ?>
|
2025-02-15 19:13:31 +01:00
|
|
|
<link rel="stylesheet" href="../assets/css/main.css">
|
2025-02-16 22:22:37 +01:00
|
|
|
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
|
2025-02-15 19:13:31 +01:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<nav class="admin-nav">
|
|
|
|
<div class="nav-brand">
|
2025-02-16 22:22:37 +01:00
|
|
|
<?php if (!empty($config['site']['logo'])): ?>
|
2025-02-15 19:13:31 +01:00
|
|
|
<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; ?>
|
|
|
|
|
2025-02-16 22:22:37 +01:00
|
|
|
<div class="options-container">
|
|
|
|
<!-- Section Options du Site -->
|
|
|
|
<section class="options-section">
|
|
|
|
<h2>Options générales</h2>
|
|
|
|
<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>
|
|
|
|
|
|
|
|
<!-- Section À Propos -->
|
|
|
|
<h2>Page "À propos"</h2>
|
|
|
|
|
|
|
|
<div class="form-group">
|
|
|
|
<label for="about_title">Titre de la page</label>
|
|
|
|
<input type="text"
|
|
|
|
id="about_title"
|
|
|
|
name="about_title"
|
|
|
|
value="<?= htmlspecialchars($config['about']['title'] ?? 'À propos') ?>">
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-group">
|
|
|
|
<label for="about_background">Image de fond</label>
|
|
|
|
<?php if (!empty($config['about']['background'])): ?>
|
|
|
|
<div class="current-background">
|
|
|
|
<img src="<?= htmlspecialchars('../' . $config['about']['background']) ?>"
|
|
|
|
alt="Image de fond actuelle"
|
|
|
|
style="max-height: 100px; margin: 10px 0;">
|
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
|
|
<input type="file"
|
|
|
|
id="about_background"
|
|
|
|
name="about_background"
|
|
|
|
accept="image/*">
|
|
|
|
<small>Format recommandé : 1920x250px, JPG/PNG</small>
|
2025-02-15 19:13:31 +01:00
|
|
|
</div>
|
2025-02-16 22:22:37 +01:00
|
|
|
|
|
|
|
<div class="form-group">
|
|
|
|
<label for="about_content">Contenu de la page</label>
|
|
|
|
<input type="hidden" id="about_content" name="about_content">
|
|
|
|
<div id="aboutEditor"></div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<button type="submit" class="button">Enregistrer les modifications</button>
|
|
|
|
</form>
|
|
|
|
</section>
|
|
|
|
</div>
|
2025-02-15 19:13:31 +01:00
|
|
|
</main>
|
|
|
|
|
2025-02-16 22:22:37 +01:00
|
|
|
<script src="https://cdn.quilljs.com/1.3.6/quill.min.js"></script>
|
2025-02-15 19:13:31 +01:00
|
|
|
<script>
|
2025-02-16 22:22:37 +01:00
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Prévisualisation du background
|
|
|
|
document.getElementById('about_background').addEventListener('change', function(e) {
|
|
|
|
const file = e.target.files[0];
|
|
|
|
if (file) {
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.onload = function(e) {
|
|
|
|
let currentBackground = document.querySelector('.current-background');
|
|
|
|
if (!currentBackground) {
|
|
|
|
currentBackground = document.createElement('div');
|
|
|
|
currentBackground.className = 'current-background';
|
|
|
|
e.target.parentElement.insertBefore(currentBackground, e.target.nextSibling);
|
|
|
|
}
|
|
|
|
currentBackground.innerHTML = `
|
|
|
|
<img src="${e.target.result}"
|
|
|
|
alt="Aperçu du fond"
|
|
|
|
style="max-height: 100px; margin: 10px 0;">
|
|
|
|
`;
|
|
|
|
};
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Configuration de l'éditeur Quill
|
|
|
|
const aboutEditor = new Quill('#aboutEditor', {
|
|
|
|
theme: 'snow',
|
|
|
|
modules: {
|
|
|
|
toolbar: {
|
|
|
|
container: [
|
|
|
|
[{ 'header': [1, 2, 3, false] }],
|
|
|
|
['bold', 'italic', 'underline', 'strike'],
|
|
|
|
[{ 'color': [] }, { 'background': [] }],
|
|
|
|
[{ 'font': [] }],
|
|
|
|
[{ 'align': [] }],
|
|
|
|
['blockquote', 'code-block'],
|
|
|
|
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
|
|
|
|
[{ 'script': 'sub'}, { 'script': 'super' }],
|
|
|
|
[{ 'indent': '-1'}, { 'indent': '+1' }],
|
|
|
|
[{ 'direction': 'rtl' }],
|
|
|
|
['link', 'image', 'video'],
|
|
|
|
['clean']
|
|
|
|
],
|
|
|
|
handlers: {
|
|
|
|
image: function() {
|
|
|
|
const input = document.createElement('input');
|
|
|
|
input.setAttribute('type', 'file');
|
|
|
|
input.setAttribute('accept', 'image/*');
|
|
|
|
input.click();
|
|
|
|
|
|
|
|
input.onchange = async () => {
|
|
|
|
const file = input.files[0];
|
|
|
|
if (file) {
|
|
|
|
const formData = new FormData();
|
|
|
|
formData.append('image', file);
|
|
|
|
|
|
|
|
try {
|
|
|
|
const response = await fetch('api/upload-image.php', {
|
|
|
|
method: 'POST',
|
|
|
|
body: formData
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!response.ok) throw new Error('Upload failed');
|
|
|
|
|
|
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
|
|
const range = aboutEditor.getSelection(true);
|
|
|
|
aboutEditor.insertEmbed(range.index, 'image', result.url);
|
|
|
|
aboutEditor.setSelection(range.index + 1);
|
|
|
|
} else {
|
|
|
|
showNotification(result.error || 'Erreur lors de l\'upload', 'error');
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error:', error);
|
|
|
|
showNotification('Erreur lors de l\'upload de l\'image', 'error');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2025-02-15 19:13:31 +01:00
|
|
|
}
|
2025-02-16 22:22:37 +01:00
|
|
|
},
|
|
|
|
placeholder: 'Commencez à écrire le contenu de la page À propos...'
|
|
|
|
});
|
2025-02-15 19:13:31 +01:00
|
|
|
|
2025-02-16 22:22:37 +01:00
|
|
|
// Initialiser le contenu si existant
|
|
|
|
<?php if (!empty($config['about']['content'])): ?>
|
|
|
|
aboutEditor.root.innerHTML = <?= json_encode($config['about']['content']) ?>;
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
// Mise à jour du champ caché avant la soumission
|
|
|
|
document.querySelector('form').addEventListener('submit', function() {
|
|
|
|
document.querySelector('#about_content').value = aboutEditor.root.innerHTML;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Détection des changements non sauvegardés
|
2025-02-15 19:13:31 +01:00
|
|
|
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>
|
2025-02-16 22:22:37 +01:00
|
|
|
|
2025-02-16 13:11:50 +01:00
|
|
|
<link rel="stylesheet" href="../assets/css/dialog.css">
|
|
|
|
<script src="../assets/js/dialog.js"></script>
|
2025-02-15 19:13:31 +01:00
|
|
|
</body>
|
|
|
|
</html>
|