192 lines
6.5 KiB
PHP
192 lines
6.5 KiB
PHP
<?php
|
|
require_once '../includes/config.php';
|
|
require_once '../includes/auth.php';
|
|
require_once '../includes/stories.php';
|
|
|
|
// Vérification de l'authentification
|
|
if (!Auth::check()) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
// Récupération des messages de l'import s'ils existent
|
|
$success = '';
|
|
$error = '';
|
|
|
|
if (isset($_SESSION['import_result'])) {
|
|
if (!empty($_SESSION['import_result']['success'])) {
|
|
$success = $_SESSION['import_result']['success'];
|
|
}
|
|
if (!empty($_SESSION['import_result']['error'])) {
|
|
$error = $_SESSION['import_result']['error'];
|
|
}
|
|
unset($_SESSION['import_result']);
|
|
}
|
|
|
|
$stories = Stories::getAll();
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Import/Export des romans - Administration</title>
|
|
<?php if (file_exists(__DIR__ . '/../assets/images/site/favicon.png')): ?>
|
|
<link rel="icon" type="image/png" href="../assets/images/site/favicon.png">
|
|
<?php endif; ?>
|
|
<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>Import/Export des romans</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; ?>
|
|
|
|
<!-- Section Export -->
|
|
<section class="export-section">
|
|
<h2>Exporter des romans</h2>
|
|
<form id="exportForm" action="api/export-stories.php" method="POST">
|
|
<div class="stories-selection">
|
|
<?php foreach ($stories as $story): ?>
|
|
<div class="story-checkbox">
|
|
<label>
|
|
<input type="checkbox" name="stories[]" value="<?= htmlspecialchars($story['id']) ?>">
|
|
<?= htmlspecialchars($story['title']) ?>
|
|
</label>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<div class="form-actions">
|
|
<button type="button" class="button select-all">Tout sélectionner</button>
|
|
<button type="submit" class="button">Exporter la sélection</button>
|
|
</div>
|
|
</form>
|
|
</section>
|
|
|
|
<!-- Section Import -->
|
|
<section class="import-section">
|
|
<h2>Importer des romans</h2>
|
|
<form id="importForm" action="api/import-stories.php" method="POST" enctype="multipart/form-data">
|
|
<div class="form-group">
|
|
<label for="importFile">Sélectionner une archive ZIP</label>
|
|
<input type="file" id="importFile" name="importFile" accept=".zip" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label>
|
|
<input type="checkbox" name="overwrite" value="1">
|
|
Écraser les romans existants
|
|
</label>
|
|
</div>
|
|
|
|
<button type="submit" class="button">Importer</button>
|
|
</form>
|
|
</section>
|
|
</main>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Gestion de la sélection/désélection de tous les romans
|
|
const selectAllBtn = document.querySelector('.select-all');
|
|
const checkboxes = document.querySelectorAll('input[name="stories[]"]');
|
|
|
|
selectAllBtn.addEventListener('click', function() {
|
|
const allChecked = Array.from(checkboxes).every(cb => cb.checked);
|
|
checkboxes.forEach(cb => cb.checked = !allChecked);
|
|
this.textContent = allChecked ? 'Tout sélectionner' : 'Tout désélectionner';
|
|
});
|
|
|
|
// Validation du formulaire d'export
|
|
document.getElementById('exportForm').addEventListener('submit', function(e) {
|
|
const selected = document.querySelectorAll('input[name="stories[]"]:checked');
|
|
if (selected.length === 0) {
|
|
e.preventDefault();
|
|
alert('Veuillez sélectionner au moins un roman à exporter.');
|
|
}
|
|
});
|
|
|
|
// Validation de l'import
|
|
document.getElementById('importForm').addEventListener('submit', function(e) {
|
|
const file = document.getElementById('importFile').files[0];
|
|
if (!file) {
|
|
e.preventDefault();
|
|
alert('Veuillez sélectionner un fichier ZIP à importer.');
|
|
return;
|
|
}
|
|
|
|
if (!file.name.toLowerCase().endsWith('.zip')) {
|
|
e.preventDefault();
|
|
alert('Seuls les fichiers ZIP sont acceptés.');
|
|
return;
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<style>
|
|
.export-section,
|
|
.import-section {
|
|
background: var(--bg-tertiary);
|
|
padding: var(--spacing-lg);
|
|
border-radius: var(--radius-md);
|
|
margin-bottom: var(--spacing-xl);
|
|
border: 1px solid var(--border-color);
|
|
}
|
|
|
|
.stories-selection {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
|
gap: var(--spacing-md);
|
|
margin: var(--spacing-lg) 0;
|
|
}
|
|
|
|
.story-checkbox {
|
|
padding: var(--spacing-sm);
|
|
background: var(--bg-secondary);
|
|
border-radius: var(--radius-sm);
|
|
}
|
|
|
|
.story-checkbox label {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: var(--spacing-sm);
|
|
cursor: pointer;
|
|
}
|
|
|
|
.form-actions {
|
|
display: flex;
|
|
gap: var(--spacing-md);
|
|
margin-top: var(--spacing-lg);
|
|
}
|
|
|
|
.import-section .form-group {
|
|
margin-bottom: var(--spacing-md);
|
|
}
|
|
</style>
|
|
<link rel="stylesheet" href="../assets/css/dialog.css">
|
|
<script src="../assets/js/dialog.js"></script>
|
|
</body>
|
|
</html>
|