2022-09-13 13:14:49 +00:00
|
|
|
<?php
|
|
|
|
namespace Misuzu;
|
|
|
|
|
2023-07-22 15:02:41 +00:00
|
|
|
use RuntimeException;
|
2022-09-13 13:14:49 +00:00
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
if(!$msz->authInfo->isLoggedIn)
|
2023-08-31 15:59:53 +00:00
|
|
|
Template::throwError(403);
|
2023-08-02 22:12:47 +00:00
|
|
|
|
|
|
|
// TODO: restore forum-topics and forum-posts orderings
|
|
|
|
|
2023-07-27 23:26:05 +00:00
|
|
|
$roleId = filter_has_var(INPUT_GET, 'r') ? (string)filter_input(INPUT_GET, 'r') : null;
|
|
|
|
$orderBy = strtolower((string)filter_input(INPUT_GET, 'ss'));
|
|
|
|
$orderDir = strtolower((string)filter_input(INPUT_GET, 'sd'));
|
2022-09-13 13:14:49 +00:00
|
|
|
|
|
|
|
$orderDirs = [
|
2023-08-02 22:12:47 +00:00
|
|
|
'asc' => 'In Order',
|
|
|
|
'desc' => 'Reverse Order',
|
2022-09-13 13:14:49 +00:00
|
|
|
];
|
|
|
|
|
2023-08-02 22:12:47 +00:00
|
|
|
$defaultOrder = 'active';
|
2022-09-13 13:14:49 +00:00
|
|
|
$orderFields = [
|
|
|
|
'id' => [
|
|
|
|
'title' => 'User ID',
|
|
|
|
],
|
|
|
|
'name' => [
|
|
|
|
'title' => 'Username',
|
|
|
|
],
|
|
|
|
'country' => [
|
|
|
|
'title' => 'Country',
|
|
|
|
],
|
2023-08-02 22:12:47 +00:00
|
|
|
'created' => [
|
2022-09-13 13:14:49 +00:00
|
|
|
'title' => 'Registration Date',
|
|
|
|
],
|
2023-08-02 22:12:47 +00:00
|
|
|
'active' => [
|
2022-09-13 13:14:49 +00:00
|
|
|
'title' => 'Last Online',
|
|
|
|
],
|
2023-08-02 22:12:47 +00:00
|
|
|
'registered' => [
|
|
|
|
'alt' => 'created',
|
|
|
|
'title' => 'Registration Date',
|
2022-09-13 13:14:49 +00:00
|
|
|
],
|
2023-08-02 22:12:47 +00:00
|
|
|
'last-online' => [
|
|
|
|
'alt' => 'active',
|
|
|
|
'title' => 'Last Online',
|
2022-09-13 13:14:49 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
if(empty($orderBy)) {
|
|
|
|
$orderBy = $defaultOrder;
|
|
|
|
} elseif(!array_key_exists($orderBy, $orderFields)) {
|
2023-08-31 15:59:53 +00:00
|
|
|
Template::throwError(400);
|
2022-09-13 13:14:49 +00:00
|
|
|
}
|
|
|
|
|
2023-08-02 22:12:47 +00:00
|
|
|
if(array_key_exists('alt', $orderFields[$orderBy]))
|
|
|
|
$orderBy = $orderFields[$orderBy]['alt'];
|
|
|
|
|
2022-09-13 13:14:49 +00:00
|
|
|
if(empty($orderDir)) {
|
2023-08-02 22:12:47 +00:00
|
|
|
$orderDir = 'asc';
|
2022-09-13 13:14:49 +00:00
|
|
|
} elseif(!array_key_exists($orderDir, $orderDirs)) {
|
2023-08-31 15:59:53 +00:00
|
|
|
Template::throwError(400);
|
2022-09-13 13:14:49 +00:00
|
|
|
}
|
|
|
|
|
2023-07-27 23:26:05 +00:00
|
|
|
if($roleId === null) {
|
2024-11-30 04:09:29 +00:00
|
|
|
$roleInfo = $msz->usersCtx->roles->getDefaultRole();
|
2023-07-27 23:26:05 +00:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
$roleInfo = $roles->getRole($roleId);
|
|
|
|
} catch(RuntimeException $ex) {
|
2023-08-31 15:59:53 +00:00
|
|
|
Template::throwError(404);
|
2023-07-27 23:26:05 +00:00
|
|
|
}
|
2022-09-13 13:14:49 +00:00
|
|
|
}
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
$canManageUsers = $msz->authInfo->getPerms('user')->check(Perm::U_USERS_MANAGE);
|
2023-08-02 22:12:47 +00:00
|
|
|
$deleted = $canManageUsers ? null : false;
|
2022-09-13 13:14:49 +00:00
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
$rolesAll = $msz->usersCtx->roles->getRoles(hidden: false);
|
|
|
|
$pagination = new Pagination($msz->usersCtx->users->countUsers(roleInfo: $roleInfo, deleted: $deleted), 15);
|
2023-08-02 22:12:47 +00:00
|
|
|
|
|
|
|
$userList = [];
|
2024-11-30 04:09:29 +00:00
|
|
|
$userInfos = $msz->usersCtx->users->getUsers(
|
2023-08-02 22:12:47 +00:00
|
|
|
roleInfo: $roleInfo,
|
|
|
|
deleted: $deleted,
|
|
|
|
orderBy: $orderBy,
|
|
|
|
reverseOrder: $orderDir !== 'asc',
|
|
|
|
pagination: $pagination,
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach($userInfos as $userInfo)
|
|
|
|
$userList[] = [
|
|
|
|
'info' => $userInfo,
|
2024-11-30 04:09:29 +00:00
|
|
|
'colour' => $msz->usersCtx->getUserColour($userInfo),
|
|
|
|
'ftopics' => $msz->forumCtx->countTotalUserTopics($userInfo),
|
|
|
|
'fposts' => $msz->forumCtx->countTotalUserPosts($userInfo),
|
2023-08-02 22:12:47 +00:00
|
|
|
];
|
2022-09-13 13:14:49 +00:00
|
|
|
|
2023-08-02 22:12:47 +00:00
|
|
|
if(empty($userList))
|
2022-09-13 13:14:49 +00:00
|
|
|
http_response_code(404);
|
|
|
|
|
|
|
|
Template::render('user.listing', [
|
2023-07-27 23:26:05 +00:00
|
|
|
'roles' => $rolesAll,
|
2022-09-13 13:14:49 +00:00
|
|
|
'role' => $roleInfo,
|
2023-08-02 22:12:47 +00:00
|
|
|
'users' => $userList,
|
2022-09-13 13:14:49 +00:00
|
|
|
'order_fields' => $orderFields,
|
|
|
|
'order_directions' => $orderDirs,
|
|
|
|
'order_field' => $orderBy,
|
|
|
|
'order_direction' => $orderDir,
|
|
|
|
'order_default' => $defaultOrder,
|
|
|
|
'can_manage_users' => $canManageUsers,
|
|
|
|
'users_pagination' => $pagination,
|
|
|
|
]);
|