misuzu/public-legacy/members.php

113 lines
2.9 KiB
PHP
Raw Normal View History

2018-05-28 01:24:16 +02:00
<?php
2019-09-29 00:38:39 +02:00
namespace Misuzu;
use RuntimeException;
2020-05-25 19:58:06 +00:00
2024-12-02 02:28:08 +00:00
if(!isset($msz) || !($msz instanceof \Misuzu\MisuzuContext))
die('Script must be called through the Misuzu route dispatcher.');
if(!$msz->authInfo->isLoggedIn)
Template::throwError(403);
// 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'));
2018-05-28 01:24:16 +02:00
$orderDirs = [
'asc' => 'In Order',
'desc' => 'Reverse Order',
2018-05-28 01:24:16 +02:00
];
$defaultOrder = 'active';
2018-05-28 01:24:16 +02:00
$orderFields = [
'id' => [
'title' => 'User ID',
],
'name' => [
'title' => 'Username',
],
'country' => [
'title' => 'Country',
],
'created' => [
2018-05-28 01:24:16 +02:00
'title' => 'Registration Date',
],
'active' => [
2018-05-28 01:24:16 +02:00
'title' => 'Last Online',
],
'registered' => [
'alt' => 'created',
'title' => 'Registration Date',
2019-02-28 22:06:30 +01:00
],
'last-online' => [
'alt' => 'active',
'title' => 'Last Online',
2019-02-28 22:06:30 +01:00
],
2018-05-28 01:24:16 +02:00
];
2019-06-10 19:04:53 +02:00
if(empty($orderBy)) {
2018-07-11 22:03:43 +02:00
$orderBy = $defaultOrder;
2019-06-10 19:04:53 +02:00
} elseif(!array_key_exists($orderBy, $orderFields)) {
Template::throwError(400);
2018-05-28 01:24:16 +02:00
}
if(array_key_exists('alt', $orderFields[$orderBy]))
$orderBy = $orderFields[$orderBy]['alt'];
2019-06-10 19:04:53 +02:00
if(empty($orderDir)) {
$orderDir = 'asc';
2019-06-10 19:04:53 +02:00
} elseif(!array_key_exists($orderDir, $orderDirs)) {
Template::throwError(400);
2018-05-28 01:24:16 +02:00
}
2023-07-27 23:26:05 +00:00
if($roleId === null) {
$roleInfo = $msz->usersCtx->roles->getDefaultRole();
2023-07-27 23:26:05 +00:00
} else {
try {
2024-12-02 00:34:00 +00:00
$roleInfo = $msz->usersCtx->roles->getRole($roleId);
2023-07-27 23:26:05 +00:00
} catch(RuntimeException $ex) {
Template::throwError(404);
2023-07-27 23:26:05 +00:00
}
2018-05-28 01:24:16 +02:00
}
$canManageUsers = $msz->authInfo->getPerms('user')->check(Perm::U_USERS_MANAGE);
$deleted = $canManageUsers ? null : false;
2019-01-03 01:33:02 +01:00
$rolesAll = $msz->usersCtx->roles->getRoles(hidden: false);
2024-12-19 01:22:26 +00:00
$pagination = Pagination::fromInput($msz->usersCtx->users->countUsers(roleInfo: $roleInfo, deleted: $deleted), 15);
$userList = [];
$userInfos = $msz->usersCtx->users->getUsers(
roleInfo: $roleInfo,
deleted: $deleted,
orderBy: $orderBy,
reverseOrder: $orderDir !== 'asc',
pagination: $pagination,
);
foreach($userInfos as $userInfo)
$userList[] = [
'info' => $userInfo,
'colour' => $msz->usersCtx->getUserColour($userInfo),
'ftopics' => $msz->forumCtx->countTotalUserTopics($userInfo),
'fposts' => $msz->forumCtx->countTotalUserPosts($userInfo),
];
2018-05-28 01:24:16 +02:00
if(empty($userList))
http_response_code(404);
Template::render('user.listing', [
2023-07-27 23:26:05 +00:00
'roles' => $rolesAll,
2020-06-04 18:48:01 +00:00
'role' => $roleInfo,
'users' => $userList,
2018-05-28 01:24:16 +02:00
'order_fields' => $orderFields,
'order_directions' => $orderDirs,
'order_field' => $orderBy,
'order_direction' => $orderDir,
2018-07-11 22:03:43 +02:00
'order_default' => $defaultOrder,
'can_manage_users' => $canManageUsers,
2020-06-04 18:48:01 +00:00
'users_pagination' => $pagination,
2018-05-28 01:24:16 +02:00
]);