Added ability to assign warnings (WIP).

This commit is contained in:
flash 2018-12-27 06:13:03 +01:00
parent 40042b95c0
commit a34a546ace
4 changed files with 74 additions and 0 deletions

View file

@ -111,6 +111,10 @@ switch ($_GET['v'] ?? null) {
tpl_var('permissions', $permissions = manage_perms_list(perms_get_user_raw($userId)));
}
if ($canManageWarnings) {
tpl_var('warning_types', $warnTypes = user_warning_get_types());
}
if ($isPostRequest) {
if (!csrf_verify('users_edit', $_POST['csrf'] ?? '')) {
echo 'csrf err';
@ -234,6 +238,18 @@ switch ($_GET['v'] ?? null) {
}
}
if (!empty($warnTypes) && !empty($_POST['warning']) && is_array($_POST['warning'])) {
user_warning_add(
$userId,
user_get_last_ip($userId),
user_session_current('user_id'),
ip_remote_address(),
$_POST['warning']['type'],
$_POST['warning']['note'],
$_POST['warning']['private']
);
}
header("Location: ?v=view&u={$manageUser['user_id']}");
break;
}

View file

@ -151,6 +151,17 @@ function user_bump_last_active(int $userId, string $ipAddress = null): void
$bumpUserLast->execute();
}
function user_get_last_ip(int $userId): string
{
$getAddress = db_prepare('
SELECT INET6_NTOA(`last_ip`)
FROM `msz_users`
WHERE `user_id` = :user_id
');
$getAddress->bindValue('user_id', $userId);
return $getAddress->execute() ? $getAddress->fetchColumn() : '';
}
define('MSZ_USER_ABOUT_MAX_LENGTH', 0xFFFF);
define('MSZ_USER_ABOUT_OK', 0);

View file

@ -8,6 +8,39 @@ define('MSZ_WARN_TYPES', [
MSZ_WARN_NOTE, MSZ_WARN_WARNING, MSZ_WARN_SILENCE, MSZ_WARN_BAN,
]);
define('MSZ_WARN_TYPES_PUBLIC', [
MSZ_WARN_WARNING,
MSZ_WARN_SILENCE,
MSZ_WARN_BAN,
]);
define('MSZ_WARN_TYPE_NAMES', [
MSZ_WARN_NOTE => 'Note',
MSZ_WARN_WARNING => 'Warning',
MSZ_WARN_SILENCE => 'Silence',
MSZ_WARN_BAN => 'Ban',
]);
function user_warning_type_is_valid(int $type): bool
{
return in_array($type, MSZ_WARN_TYPES, true);
}
function user_warning_type_get_name(int $type): string
{
return user_warning_type_is_valid($type) ? MSZ_WARN_TYPE_NAMES[$type] : '';
}
function user_warning_get_types(): array
{
return MSZ_WARN_TYPE_NAMES;
}
function user_warning_is_public(int $type): bool
{
return in_array($type, MSZ_WARN_TYPES_PUBLIC, true);
}
function user_warning_add(
int $userId,
string $userIp,

View file

@ -139,6 +139,20 @@
</form>
{% endif %}
{% if can_manage_warns %}
<form class="container" method="post" action="">
{{ container_title('Add Warning') }}
{{ input_csrf('users_edit') }}
{{ input_select('warning[type]', warning_types) }}
{{ input_text('warning[note]', '', '', 'text', 'Public note') }}
{{ input_text('warning[until]', '', ''|date('c'), 'datetime-local') }} (empty to set null)
<button class="input__button">Add</button><br>
<textarea class="input__textarea" name="warning[private]" placeholder="Private note"></textarea>
</form>
{% endif %}
{% if can_manage_users %}
{% if has_roles|length > 0 %}
<form method="post" action="" class="container">