179 lines
7.3 KiB
PHP
179 lines
7.3 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>
|
|
<div class="nav-menu">
|
|
<a href="../index.php" target="_blank" class="button tooltip" data-tooltip="Visiter le site">
|
|
<i class="fa-solid fa-house"></i>
|
|
</a>
|
|
<a href="profile.php" class="button tooltip" data-tooltip="Profil">
|
|
<i class="fas fa-user"></i>
|
|
</a>
|
|
<?php if (Auth::isAdmin() || Auth::hasAdminRole()): ?>
|
|
<a href="users.php" class="button tooltip" data-tooltip="Utilisateurs">
|
|
<i class="fas fa-users"></i>
|
|
</a>
|
|
<?php endif; ?>
|
|
<a href="story-edit.php" class="button tooltip" data-tooltip="Nouveau roman">
|
|
<i class="fa-solid fa-book"></i>
|
|
</a>
|
|
<a href="options.php" class="button tooltip" data-tooltip="Options">
|
|
<i class="fas fa-cog"></i>
|
|
</a>
|
|
<a href="export-import.php" class="button tooltip" data-tooltip="Import/Export">
|
|
<i class="fa-solid fa-upload"></i>
|
|
</a>
|
|
<form method="POST" action="logout.php" class="logout-form">
|
|
<button type="submit" class="tooltip" data-tooltip="Déconnexion">
|
|
<i class="fas fa-sign-out-alt"></i>
|
|
</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 tooltip" data-tooltip="Modifier">
|
|
<i class="fas fa-edit"></i>
|
|
</a>
|
|
<?php if (Auth::isAdmin() || Auth::hasAdminRole()): ?>
|
|
<button type="button" class="button tooltip manage-access" data-tooltip="Accès" data-id="<?= htmlspecialchars($story['id']) ?>">
|
|
<i class="fas fa-users-cog"></i>
|
|
</button>
|
|
<?php endif; ?>
|
|
<button type="button" class="button tooltip delete-story" data-tooltip="Supprimer" data-id="<?= htmlspecialchars($story['id']) ?>">
|
|
<i class="fas fa-trash-alt"></i>
|
|
</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">
|
|
<i class="fas fa-times"></i>
|
|
<span class="button-text">Annuler</span>
|
|
</button>
|
|
<button type="button" class="button" id="saveAccess">
|
|
<i class="fas fa-save"></i>
|
|
<span class="button-text">Enregistrer</span>
|
|
</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>
|