diff --git a/assets/less/classes/settings/account-log.less b/assets/less/classes/settings/account-log.less index 62f8e765..35a73387 100644 --- a/assets/less/classes/settings/account-log.less +++ b/assets/less/classes/settings/account-log.less @@ -71,4 +71,23 @@ padding: 1px 5px; } } + + &__user { + color: inherit; + text-decoration: none; + display: flex; + padding: 4px; + border-bottom: 1px solid var(--accent-colour); + margin-bottom: -4px; + + &__avatar { + width: 20px; + height: 20px; + } + + &__name { + color: var(--user-colour); + padding-left: 4px; + } + } } diff --git a/public/manage/index.php b/public/manage/index.php index f2a5c456..4dfcf50f 100644 --- a/public/manage/index.php +++ b/public/manage/index.php @@ -15,11 +15,26 @@ switch ($_GET['v'] ?? null) { break; } - tpl_var('log_dump', print_r(audit_log_list(0, 50), true)); - echo tpl_render('manage.general.logs'); + $logTake = 50; + $logOffset = (int)($_GET['o'] ?? 0); + $logCount = audit_log_count(); + $logs = audit_log_list($logOffset, $logTake); + + echo tpl_render('manage.general.logs', [ + 'global_logs' => $logs, + 'global_logs_take' => $logTake, + 'global_logs_offset' => $logOffset, + 'global_logs_count' => $logCount, + 'global_logs_strings' => MSZ_AUDIT_LOG_STRINGS, + ]); break; case 'quotes': + if (!perms_check($generalPerms, MSZ_PERM_GENERAL_VIEW_LOGS)) { + echo render_error(403); + break; + } + $setId = (int)($_GET['s'] ?? ''); $quoteId = (int)($_GET['q'] ?? ''); diff --git a/public/settings.php b/public/settings.php index 94c4dcff..147ca007 100644 --- a/public/settings.php +++ b/public/settings.php @@ -152,21 +152,7 @@ $logs = [ 'amount' => audit_log_count(user_session_current('user_id')), 'offset' => max(0, intval($_GET['logs']['offset'] ?? 0)), 'take' => clamp($_GET['logs']['take'] ?? 15, 5, 30), - 'strings' => [ - 'PERSONAL_EMAIL_CHANGE' => 'Changed e-mail address to %s.', - 'PERSONAL_PASSWORD_CHANGE' => 'Changed account password.', - 'PERSONAL_SESSION_DESTROY' => 'Ended session #%d.', - 'PERSONAL_SESSION_DESTROY_ALL' => 'Ended all personal sessions.', - 'PASSWORD_RESET' => 'Successfully used the password reset form to change password.', - 'CHANGELOG_ENTRY_CREATE' => 'Created a new changelog entry #%d.', - 'CHANGELOG_ENTRY_EDIT' => 'Edited changelog entry #%d.', - 'CHANGELOG_TAG_ADD' => 'Added tag #%2$d to changelog entry #%1$d.', - 'CHANGELOG_TAG_REMOVE' => 'Removed tag #%2$d from changelog entry #%1$d.', - 'CHANGELOG_TAG_CREATE' => 'Created new changelog tag #%d.', - 'CHANGELOG_TAG_EDIT' => 'Edited changelog tag #%d.', - 'CHANGELOG_ACTION_CREATE' => 'Created new changelog action #%d.', - 'CHANGELOG_ACTION_EDIT' => 'Edited changelog action #%d.', - ], + 'strings' => MSZ_AUDIT_LOG_STRINGS, ]; $sessions['list'] = user_session_list($sessions['offset'], $sessions['take'], user_session_current('user_id')); diff --git a/src/audit_log.php b/src/audit_log.php index 10220550..53ffaeca 100644 --- a/src/audit_log.php +++ b/src/audit_log.php @@ -1,4 +1,21 @@ 'Changed e-mail address to %s.', + 'PERSONAL_PASSWORD_CHANGE' => 'Changed account password.', + 'PERSONAL_SESSION_DESTROY' => 'Ended session #%d.', + 'PERSONAL_SESSION_DESTROY_ALL' => 'Ended all personal sessions.', + 'PASSWORD_RESET' => 'Successfully used the password reset form to change password.', + 'CHANGELOG_ENTRY_CREATE' => 'Created a new changelog entry #%d.', + 'CHANGELOG_ENTRY_EDIT' => 'Edited changelog entry #%d.', + 'CHANGELOG_TAG_ADD' => 'Added tag #%2$d to changelog entry #%1$d.', + 'CHANGELOG_TAG_REMOVE' => 'Removed tag #%2$d from changelog entry #%1$d.', + 'CHANGELOG_TAG_CREATE' => 'Created new changelog tag #%d.', + 'CHANGELOG_TAG_EDIT' => 'Edited changelog tag #%d.', + 'CHANGELOG_ACTION_CREATE' => 'Created new changelog action #%d.', + 'CHANGELOG_ACTION_EDIT' => 'Edited changelog action #%d.', +]); + function audit_log( string $action, int $userId = 0, @@ -32,8 +49,8 @@ function audit_log_count($userId = 0): int $getCount = db_prepare(sprintf(' SELECT COUNT(`log_id`) FROM `msz_audit_log` - WHERE %s - ', $userId < 1 ? '1' : '`user_id` = :user_id')); + %s + ', $userId < 1 ? '' : 'WHERE `user_id` = :user_id')); if ($userId >= 1) { $getCount->bindValue('user_id', $userId); @@ -46,24 +63,28 @@ function audit_log_list(int $offset, int $take, int $userId = 0): array { $offset = max(0, $offset); $take = max(1, $take); + $isGlobal = $userId < 1; - $getLogs = db_prepare(sprintf(' - SELECT - l.`log_id`, l.`log_action`, l.`log_params`, l.`log_created`, l.`log_country`, - u.`user_id`, u.`username`, - INET6_NTOA(l.`log_ip`) as `log_ip`, - COALESCE(u.`user_colour`, r.`role_colour`) 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')); + $getLogs = db_prepare(sprintf( + ' + SELECT + l.`log_id`, l.`log_action`, l.`log_params`, l.`log_created`, l.`log_country`, + INET6_NTOA(l.`log_ip`) as `log_ip` + %2$s + FROM `msz_audit_log` as l + %1$s + ORDER BY l.`log_id` DESC + LIMIT :offset, :take + ', + $isGlobal + ? '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 l.`user_id` = :user_id', + $isGlobal + ? ', u.`user_id`, u.`username`, COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`' + : '' + )); - if ($userId >= 1) { + if (!$isGlobal) { $getLogs->bindValue('user_id', $userId); } diff --git a/templates/manage/general/logs.twig b/templates/manage/general/logs.twig index 98e8f20e..3d49997a 100644 --- a/templates/manage/general/logs.twig +++ b/templates/manage/general/logs.twig @@ -1,7 +1,31 @@ {% extends 'manage/general/master.twig' %} +{% from 'macros.twig' import container_title, pagination %} +{% from 'user/macros.twig' import user_account_log %} {% block manage_content %} -
-    {{ log_dump }}
-
+
+ {{ container_title(' Global Log', '', true) }} + {% set glp = pagination( + global_logs_count, + global_logs_take, + global_logs_offset, + url_construct('/manage/index.php', { + 'v': 'logs', + }) + ) %} + +
+ + + {% for log in global_logs %} + {{ user_account_log(log, global_logs_strings) }} + {% endfor %} + + +
+
{% endblock %} diff --git a/templates/user/macros.twig b/templates/user/macros.twig index 2ef316ba..ed44d39d 100644 --- a/templates/user/macros.twig +++ b/templates/user/macros.twig @@ -179,6 +179,13 @@ {% macro user_account_log(data, strings) %}
+ {% if data.user_id is defined %} + + + + + {% endif %} +