diff --git a/public/manage/users.php b/public/manage/users.php index d4a74be6..017e03bc 100644 --- a/public/manage/users.php +++ b/public/manage/users.php @@ -9,6 +9,7 @@ tpl_vars([ 'can_manage_users' => $canManageUsers = perms_check($userPerms, MSZ_PERM_USER_MANAGE_USERS), 'can_manage_roles' => $canManageRoles = perms_check($userPerms, MSZ_PERM_USER_MANAGE_ROLES), 'can_manage_perms' => $canManagePerms = perms_check($userPerms, MSZ_PERM_USER_MANAGE_PERMS), + 'can_manage_warns' => $canManageWarnings = perms_check($userPerms, MSZ_PERM_USER_MANAGE_WARNINGS), ]); switch ($_GET['v'] ?? null) { @@ -461,4 +462,25 @@ switch ($_GET['v'] ?? null) { echo tpl_render('manage.users.role'); break; + + case 'warnings': + if (!$canManageWarnings) { + echo render_error(403); + break; + } + + $warningsCount = user_warning_global_count(); + $warningsTake = 50; + $warningsOffset = max(0, (int)($_GET['o'] ?? 0)); + $warningsList = user_warning_global_fetch($warningsOffset, $warningsTake); + + echo tpl_render('manage.users.warnings', [ + 'warnings' => [ + 'count' => $warningsCount, + 'take' => $warningsTake, + 'offset' => $warningsOffset, + 'list' => $warningsList, + ], + ]); + break; } diff --git a/src/Users/user.php b/src/Users/user.php index 48915b37..843e99a3 100644 --- a/src/Users/user.php +++ b/src/Users/user.php @@ -12,7 +12,7 @@ define('MSZ_PERM_USER_MANAGE_USERS', 1 << 20); define('MSZ_PERM_USER_MANAGE_ROLES', 1 << 21); define('MSZ_PERM_USER_MANAGE_PERMS', 1 << 22); define('MSZ_PERM_USER_MANAGE_REPORTS', 1 << 23); -define('MSZ_PERM_USER_MANAGE_RESTRICTIONS', 1 << 24); +define('MSZ_PERM_USER_MANAGE_WARNINGS', 1 << 24); //define('MSZ_PERM_USER_MANAGE_BLACKLISTS', 1 << 25); // Replaced with MSZ_PERM_GENERAL_MANAGE_BLACKLIST define( diff --git a/src/Users/warning.php b/src/Users/warning.php index ecbc9b62..8bf749d5 100644 --- a/src/Users/warning.php +++ b/src/Users/warning.php @@ -88,6 +88,7 @@ function user_warning_fetch( ON iu.`user_id` = uw.`issuer_id` WHERE uw.`user_id` = :user_id %s + ORDER BY uw.`warning_id` DESC ', $days !== null ? 'AND uw.`warning_created` >= NOW() - INTERVAL :days DAY' : '' )); @@ -100,3 +101,35 @@ function user_warning_fetch( $warnings = $fetchWarnings->execute() ? $fetchWarnings->fetchAll(PDO::FETCH_ASSOC) : false; return $warnings ? $warnings : []; } + +function user_warning_global_count(): int +{ + $countWarnings = db_query(' + SELECT COUNT(`warning_id`) + FROM `msz_user_warnings` + '); + return (int)$countWarnings->fetchColumn(); +} + +function user_warning_global_fetch(int $offset, int $take): array +{ + $fetchWarnings = db_prepare(' + SELECT + uw.`warning_id`, uw.`warning_created`, uw.`warning_type`, uw.`warning_note`, + uw.`warning_note_private`, uw.`user_id`, uw.`issuer_id`, uw.`warning_duration`, + TIMESTAMPDIFF(SECOND, uw.`warning_created`, uw.`warning_duration`) AS `warning_duration_secs`, + INET6_NTOA(uw.`user_ip`) AS `user_ip`, INET6_NTOA(uw.`issuer_ip`) AS `issuer_ip`, + iu.`username` AS `issuer_username`, wu.`username` AS `username` + FROM `msz_user_warnings` AS uw + LEFT JOIN `msz_users` AS iu + ON iu.`user_id` = uw.`issuer_id` + LEFT JOIN `msz_users` AS wu + ON wu.`user_id` = uw.`user_id` + ORDER BY uw.`warning_id` DESC + LIMIT :offset, :take + '); + $fetchWarnings->bindValue('offset', $offset); + $fetchWarnings->bindValue('take', $take); + $warnings = $fetchWarnings->execute() ? $fetchWarnings->fetchAll(PDO::FETCH_ASSOC) : false; + return $warnings ? $warnings : []; +} diff --git a/src/manage.php b/src/manage.php index 0aaff7c5..43a88666 100644 --- a/src/manage.php +++ b/src/manage.php @@ -43,8 +43,8 @@ function manage_get_menu(int $userId): array $menu['Users']['Reports'] = '/manage/users.php?v=reports'; } - if (perms_check($perms['user'], MSZ_PERM_USER_MANAGE_RESTRICTIONS)) { - $menu['Users']['Restrictions'] = '/manage/users.php?v=restrictions'; + if (perms_check($perms['user'], MSZ_PERM_USER_MANAGE_WARNINGS)) { + $menu['Users']['Warnings'] = '/manage/users.php?v=warnings'; } if (perms_check($perms['news'], MSZ_PERM_NEWS_MANAGE_POSTS)) { @@ -251,9 +251,9 @@ function manage_perms_list(array $rawPerms): array 'perm' => MSZ_PERM_USER_MANAGE_REPORTS, ], [ - 'section' => 'manage-restrictions', - 'title' => 'Can manage restrictions.', - 'perm' => MSZ_PERM_USER_MANAGE_RESTRICTIONS, + 'section' => 'manage-warnings', + 'title' => 'Can manage warnings, silences and bans.', + 'perm' => MSZ_PERM_USER_MANAGE_WARNINGS, ], ], ], diff --git a/templates/manage/users/warnings.twig b/templates/manage/users/warnings.twig new file mode 100644 index 00000000..56fa473a --- /dev/null +++ b/templates/manage/users/warnings.twig @@ -0,0 +1,64 @@ +{% extends 'manage/users/master.twig' %} +{% from 'macros.twig' import pagination, container_title %} +{% from 'user/macros.twig' import user_profile_warning %} + +{% block manage_content %} +
+ {{ container_title(' Warnings', '', true) }} + {% set warnpag = pagination(warnings.count, warnings.take, warnings.offset, '/manage/users.php?v=warnings') %} + + {{ warnpag }} + +
+
+
+ +
+
+ Type +
+ +
+ Created +
+ +
+ Expires +
+ +
+ Note +
+
+
+ + {% for warning in warnings.list %} + {{ user_profile_warning(warning) }} + {% endfor %} + +
+
+ +
+
+ Type +
+ +
+ Created +
+ +
+ Expires +
+ +
+ Note +
+
+
+
+ + {{ warnpag }} +
+{% endblock %} diff --git a/templates/user/macros.twig b/templates/user/macros.twig index ed44d39d..d9b5bbf9 100644 --- a/templates/user/macros.twig +++ b/templates/user/macros.twig @@ -221,3 +221,51 @@ {% endmacro %} + +{% macro user_profile_warning(warning, show_private_note) %} + {% if warning.warning_type == constant('MSZ_WARN_SILENCE') %} + {% set warning_text = 'Silence' %} + {% set warning_class = 'silence' %} + {% elseif warning.warning_type == constant('MSZ_WARN_BAN') %} + {% set warning_text = 'Ban' %} + {% set warning_class = 'ban' %} + {% elseif warning.warning_type == constant('MSZ_WARN_WARNING') %} + {% set warning_text = 'Warning' %} + {% set warning_class = 'warning' %} + {% else %} + {% set warning_text = 'Note' %} + {% set warning_class = 'note' %} + {% endif %} + +
+
+ +
+
+ {{ warning_text }} +
+ + + + {% if warning.warning_duration_secs > 0 %} + + {% else %} +
+ {% endif %} + +
+ {{ warning.warning_note }} + + {% if show_private_note and warning.warning_note_private|length > 0 %} +
+ {{ warning.warning_note_private|nl2br }} +
+ {% endif %} +
+
+
+{% endmacro %} diff --git a/templates/user/profile.twig b/templates/user/profile.twig index 2b163604..96c31594 100644 --- a/templates/user/profile.twig +++ b/templates/user/profile.twig @@ -1,5 +1,6 @@ {% extends 'user/master.twig' %} {% from 'macros.twig' import container_title %} +{% from 'user/macros.twig' import user_profile_warning %} {% from '_layout/input.twig' import input_hidden, input_csrf, input_text, input_checkbox, input_file, input_file_raw, input_select %} {% set image = '/profile.php?u=' ~ profile.user_id ~ '&m=avatar' %} @@ -202,51 +203,7 @@ {% for warning in warnings %} - {% if warning.warning_type == constant('MSZ_WARN_SILENCE') %} - {% set warning_text = 'Silence' %} - {% set warning_class = 'silence' %} - {% elseif warning.warning_type == constant('MSZ_WARN_BAN') %} - {% set warning_text = 'Ban' %} - {% set warning_class = 'ban' %} - {% elseif warning.warning_type == constant('MSZ_WARN_WARNING') %} - {% set warning_text = 'Warning' %} - {% set warning_class = 'warning' %} - {% else %} - {% set warning_text = 'Note' %} - {% set warning_class = 'note' %} - {% endif %} - -
-
- -
-
- {{ warning_text }} -
- - - - {% if warning.warning_duration_secs > 0 %} - - {% else %} -
- {% endif %} - -
- {{ warning.warning_note }} - - {% if can_view_private_note and warning.warning_note_private|length > 0 %} -
- {{ warning.warning_note_private|nl2br }} -
- {% endif %} -
-
-
+ {{ user_profile_warning(warning, can_view_private_note) }} {% endfor %} {% endif %}