bindValue('action', $action); $addLog->bindValue('user', $userId < 1 ? null : $userId); $addLog->bindValue('params', json_encode($params)); $addLog->bindValue('log_ip', $ipAddress->getRaw()); $addLog->execute(); } function audit_log_list(int $offset, int $take, int $userId = 0): array { $offset = max(0, $offset); $take = max(1, $take); $getLogs = Database::prepare(sprintf(' SELECT l.`log_id`, l.`log_action`, l.`log_params`, l.`log_created`, u.`user_id`, u.`username`, INET6_NTOA(l.`log_ip`) as `log_ip`, COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `user_colour` FROM `msz_audit_log` as l LEFT JOIN `msz_users` as u ON u.`user_id` = l.`user_id` LEFT JOIN `msz_roles` as r ON r.`role_id` = u.`display_role` WHERE %s ORDER BY l.`log_id` DESC LIMIT :offset, :take ', $userId < 1 ? '1' : 'l.`user_id` = :user_id')); if ($userId >= 1) { $getLogs->bindValue('user_id'); } $getLogs->bindValue('offset', $offset); $getLogs->bindValue('take', $take); return $getLogs->execute() ? $getLogs->fetchAll(PDO::FETCH_ASSOC) : []; }