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(); ?>