From eb06ff5ed005cd6ccad8f87eb8b5b77470468bf3 Mon Sep 17 00:00:00 2001 From: Esenjin Date: Thu, 9 Jan 2025 12:21:06 +0100 Subject: [PATCH] =?UTF-8?q?int=C3=A9gration=20de=20la=20base=20de=20la=20g?= =?UTF-8?q?estion=20des=20logs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin.php | 17 +++++ fonctions.php | 28 +++++++ logs.php | 187 +++++++++++++++++++++++++++++++++++++++++++++++ styles-admin.css | 35 +++++++++ 4 files changed, 267 insertions(+) create mode 100644 logs.php diff --git a/admin.php b/admin.php index d7b64e7..298f800 100644 --- a/admin.php +++ b/admin.php @@ -159,6 +159,23 @@ function showAdminInterface() {

Personnalisez le titre et la description de votre galerie.

+ + + + + + changes(); } +/** + * Enregistre une action d'administrateur dans les logs + */ +function logAdminAction($adminId, $actionType, $description, $targetPath = null) { + $db = new SQLite3('database.sqlite'); + $stmt = $db->prepare('INSERT INTO admin_logs (admin_id, action_type, action_description, target_path) + VALUES (:admin_id, :action_type, :description, :target_path)'); + $stmt->bindValue(':admin_id', $adminId, SQLITE3_INTEGER); + $stmt->bindValue(':action_type', $actionType, SQLITE3_TEXT); + $stmt->bindValue(':description', $description, SQLITE3_TEXT); + $stmt->bindValue(':target_path', $targetPath, SQLITE3_TEXT); + return $stmt->execute(); +} + +/** + * Récupère le nom d'utilisateur d'un admin + */ +function getAdminUsername($adminId) { + $db = new SQLite3('database.sqlite'); + $stmt = $db->prepare('SELECT username FROM admins WHERE id = :id'); + $stmt->bindValue(':id', $adminId, SQLITE3_INTEGER); + $result = $stmt->execute(); + if ($row = $result->fetchArray()) { + return $row['username']; + } + return 'Inconnu'; +} + /** * Récupère la version actuelle du projet * @return string La version du projet diff --git a/logs.php b/logs.php new file mode 100644 index 0000000..ce68eeb --- /dev/null +++ b/logs.php @@ -0,0 +1,187 @@ +prepare('SELECT MIN(id) as first_id FROM admins'); +$result = $stmt->execute(); +$firstId = $result->fetchArray()['first_id']; + +if ($_SESSION['admin_id'] != $firstId) { + $_SESSION['error_message'] = "Accès non autorisé. Seul le premier administrateur peut consulter les logs."; + header('Location: admin.php'); + exit; +} + +// Pagination +$page = isset($_GET['page']) ? max(1, intval($_GET['page'])) : 1; +$perPage = 50; +$offset = ($page - 1) * $perPage; + +// Filtres +$actionType = isset($_GET['action_type']) ? $_GET['action_type'] : ''; +$adminFilter = isset($_GET['admin']) ? intval($_GET['admin']) : 0; + +// Construction de la requête +$whereClause = []; +$params = []; + +if ($actionType) { + $whereClause[] = 'action_type = :action_type'; + $params[':action_type'] = $actionType; +} + +if ($adminFilter) { + $whereClause[] = 'admin_id = :admin_id'; + $params[':admin_id'] = $adminFilter; +} + +$whereSQL = !empty($whereClause) ? 'WHERE ' . implode(' AND ', $whereClause) : ''; + +// Récupérer le nombre total de logs +$countQuery = "SELECT COUNT(*) as total FROM admin_logs $whereSQL"; +$stmt = $db->prepare($countQuery); +foreach ($params as $key => $value) { + $stmt->bindValue($key, $value); +} +$total = $stmt->execute()->fetchArray()['total']; +$totalPages = ceil($total / $perPage); + +// Récupérer les logs +$query = "SELECT l.*, a.username + FROM admin_logs l + LEFT JOIN admins a ON l.admin_id = a.id + $whereSQL + ORDER BY l.created_at DESC + LIMIT :limit OFFSET :offset"; + +$stmt = $db->prepare($query); +$stmt->bindValue(':limit', $perPage, SQLITE3_INTEGER); +$stmt->bindValue(':offset', $offset, SQLITE3_INTEGER); +foreach ($params as $key => $value) { + $stmt->bindValue($key, $value); +} + +$logs = []; +$result = $stmt->execute(); +while ($row = $result->fetchArray(SQLITE3_ASSOC)) { + $logs[] = $row; +} + +// Récupérer la liste des admins pour le filtre +$admins = []; +$result = $db->query('SELECT id, username FROM admins ORDER BY username'); +while ($row = $result->fetchArray(SQLITE3_ASSOC)) { + $admins[] = $row; +} + +// Récupérer les types d'actions uniques pour le filtre +$actionTypes = []; +$result = $db->query('SELECT DISTINCT action_type FROM admin_logs ORDER BY action_type'); +while ($row = $result->fetchArray(SQLITE3_ASSOC)) { + $actionTypes[] = $row['action_type']; +} + +$config = getSiteConfig(); +?> + + + + + + + Logs administrateurs - <?php echo htmlspecialchars($config['site_title']); ?> + + + + + +
+

Logs administrateurs

+
+ Retour +
+
+ +
+ +
+
+
+ + +
+ +
+ + +
+ + +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + +
DateAdministrateurActionDescriptionChemin
+
+ + + 1): ?> + + +
+ + + + \ No newline at end of file diff --git a/styles-admin.css b/styles-admin.css index dd97751..b1123fb 100644 --- a/styles-admin.css +++ b/styles-admin.css @@ -1019,6 +1019,41 @@ body[data-page="carrousel"] .admin-header { display: none; } +/* Styles pour les logs */ +.filter-form { + display: flex; + gap: 1rem; + align-items: flex-end; +} + +.pagination { + margin-top: 2rem; + display: flex; + justify-content: center; + gap: 0.5rem; +} + +.pagination-link { + padding: 0.5rem 1rem; + background-color: #2a2a2a; + color: white; + text-decoration: none; + border-radius: 0.25rem; + transition: all 0.3s ease; +} + +.pagination-link:hover { + background-color: #3a3a3a; +} + +.pagination-link.active { + background-color: #2196f3; +} + +.logs-list { + margin-top: 2rem; +} + /* Media Queries */ @media (max-width: 768px) { .admin-page {