154 lines
6.2 KiB
PHP
154 lines
6.2 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;
|
|
}
|
|
|
|
$stories = Stories::getAll();
|
|
|
|
// Filtrer les histoires auxquelles l'utilisateur a accès
|
|
if (!Auth::isAdmin()) {
|
|
$stories = array_filter($stories, function($story) {
|
|
return Auth::canAccessStory($story['id']);
|
|
});
|
|
}
|
|
|
|
// Obtenir la liste des utilisateurs pour la modale d'accès
|
|
$users = Auth::getAllUsers(false);
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>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">
|
|
<style>
|
|
.version-banner {
|
|
position: fixed;
|
|
bottom: 0;
|
|
left: 0;
|
|
right: 0;
|
|
padding: 8px;
|
|
background-color: var(--bg-tertiary);
|
|
color: var(--text-secondary);
|
|
text-align: center;
|
|
font-size: 0.8rem;
|
|
border-top: 1px solid var(--border-color);
|
|
z-index: 100;
|
|
}
|
|
</style>
|
|
</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>
|
|
<!-- Le bouton hamburger sera inséré par JS -->
|
|
<div class="nav-menu">
|
|
<a href="../index.php" target="_blank" class="button">Visiter le site</a>
|
|
<a href="profile.php" class="button">Profil</a>
|
|
<?php if (Auth::isAdmin() || Auth::hasAdminRole()): ?>
|
|
<a href="users.php" class="button">Utilisateurs</a>
|
|
<?php endif; ?>
|
|
<a href="story-edit.php" class="button">Nouveau roman</a>
|
|
<a href="options.php" class="button">Options</a>
|
|
<a href="export-import.php" class="button">Import/Export</a>
|
|
<form method="POST" action="logout.php" class="logout-form">
|
|
<button type="submit">Déconnexion</button>
|
|
</form>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="admin-main">
|
|
<h1>Gestion des romans</h1>
|
|
|
|
<div class="stories-list">
|
|
<?php foreach ($stories as $story): ?>
|
|
<div class="story-item">
|
|
<img src="<?= htmlspecialchars('../' . $story['cover']) ?>"
|
|
alt="Couverture de <?= htmlspecialchars($story['title']) ?>"
|
|
class="story-cover"
|
|
loading="lazy">
|
|
<div class="story-info">
|
|
<h2><?= htmlspecialchars($story['title']) ?></h2>
|
|
<p>
|
|
<?= count($story['chapters'] ?? []) ?> chapitre<?= count($story['chapters'] ?? []) > 1 ? 's' : '' ?><br>
|
|
Dernière modification : <?= htmlspecialchars(Stories::formatDate($story['updated'])) ?>
|
|
</p>
|
|
</div>
|
|
<div class="story-actions">
|
|
<a href="story-edit.php?id=<?= htmlspecialchars($story['id']) ?>" class="button">Modifier</a>
|
|
<?php if (Auth::isAdmin() || Auth::hasAdminRole()): ?>
|
|
<button type="button" class="button manage-access" data-id="<?= htmlspecialchars($story['id']) ?>">Accès</button>
|
|
<?php endif; ?>
|
|
<button type="button" class="button delete-story" data-id="<?= htmlspecialchars($story['id']) ?>">Supprimer</button>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</main>
|
|
|
|
<!-- Modale de gestion des accès -->
|
|
<?php if (Auth::isAdmin() || Auth::hasAdminRole()): ?>
|
|
<div id="accessModal" class="modal">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h2>Gérer les accès</h2>
|
|
<p id="modalStoryTitle"></p>
|
|
</div>
|
|
<div class="modal-body">
|
|
<p>Sélectionnez les utilisateurs qui auront accès à ce roman :</p>
|
|
<div class="users-access-list">
|
|
<?php foreach ($users as $user): ?>
|
|
<div class="user-access-item">
|
|
<label>
|
|
<input type="checkbox" name="user_access[]" value="<?= htmlspecialchars($user['id']) ?>"
|
|
<?= $user['isAdmin'] ? 'checked disabled' : '' ?>>
|
|
<?= htmlspecialchars($user['id']) ?>
|
|
<?php if ($user['role'] === 'admin'): ?>
|
|
<span class="user-role-badge admin">Admin</span>
|
|
<?php else: ?>
|
|
<span class="user-role-badge editor">Éditeur</span>
|
|
<?php endif; ?>
|
|
</label>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="button dark" id="cancelAccess">Annuler</button>
|
|
<button type="button" class="button" id="saveAccess">Enregistrer</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<script src="../assets/js/admin.js"></script>
|
|
<link rel="stylesheet" href="../assets/css/dialog.css">
|
|
<script src="../assets/js/dialog.js"></script>
|
|
|
|
<?php
|
|
$version = file_exists(__DIR__ . '/../version.txt')
|
|
? trim(file_get_contents(__DIR__ . '/../version.txt'))
|
|
: 'version inconnue';
|
|
?>
|
|
<div class="version-banner">
|
|
Lectures d'Esenjin - <a href="https://git.crystalyx.net/Esenjin_Asakha/Lectures" target="_blank" style="color: inherit; text-decoration: underline;">v.<?= htmlspecialchars($version) ?></a>
|
|
</div>
|
|
</body>
|
|
</html>
|