113 lines
2.8 KiB
PHP
113 lines
2.8 KiB
PHP
<?php
|
|
namespace Misuzu;
|
|
|
|
use RuntimeException;
|
|
|
|
if(!$msz->isLoggedIn())
|
|
Template::throwError(403);
|
|
|
|
// TODO: restore forum-topics and forum-posts orderings
|
|
|
|
$users = $msz->getUsers();
|
|
$roles = $msz->getRoles();
|
|
$forum = $msz->getForum();
|
|
|
|
$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'));
|
|
|
|
$orderDirs = [
|
|
'asc' => 'In Order',
|
|
'desc' => 'Reverse Order',
|
|
];
|
|
|
|
$defaultOrder = 'active';
|
|
$orderFields = [
|
|
'id' => [
|
|
'title' => 'User ID',
|
|
],
|
|
'name' => [
|
|
'title' => 'Username',
|
|
],
|
|
'country' => [
|
|
'title' => 'Country',
|
|
],
|
|
'created' => [
|
|
'title' => 'Registration Date',
|
|
],
|
|
'active' => [
|
|
'title' => 'Last Online',
|
|
],
|
|
'registered' => [
|
|
'alt' => 'created',
|
|
'title' => 'Registration Date',
|
|
],
|
|
'last-online' => [
|
|
'alt' => 'active',
|
|
'title' => 'Last Online',
|
|
],
|
|
];
|
|
|
|
if(empty($orderBy)) {
|
|
$orderBy = $defaultOrder;
|
|
} elseif(!array_key_exists($orderBy, $orderFields)) {
|
|
Template::throwError(400);
|
|
}
|
|
|
|
if(array_key_exists('alt', $orderFields[$orderBy]))
|
|
$orderBy = $orderFields[$orderBy]['alt'];
|
|
|
|
if(empty($orderDir)) {
|
|
$orderDir = 'asc';
|
|
} elseif(!array_key_exists($orderDir, $orderDirs)) {
|
|
Template::throwError(400);
|
|
}
|
|
|
|
if($roleId === null) {
|
|
$roleInfo = $roles->getDefaultRole();
|
|
} else {
|
|
try {
|
|
$roleInfo = $roles->getRole($roleId);
|
|
} catch(RuntimeException $ex) {
|
|
Template::throwError(404);
|
|
}
|
|
}
|
|
|
|
$canManageUsers = $msz->getAuthInfo()->getPerms('user')->check(Perm::U_USERS_MANAGE);
|
|
$deleted = $canManageUsers ? null : false;
|
|
|
|
$rolesAll = $roles->getRoles(hidden: false);
|
|
$pagination = new Pagination($users->countUsers(roleInfo: $roleInfo, deleted: $deleted), 15);
|
|
|
|
$userList = [];
|
|
$userInfos = $users->getUsers(
|
|
roleInfo: $roleInfo,
|
|
deleted: $deleted,
|
|
orderBy: $orderBy,
|
|
reverseOrder: $orderDir !== 'asc',
|
|
pagination: $pagination,
|
|
);
|
|
|
|
foreach($userInfos as $userInfo)
|
|
$userList[] = [
|
|
'info' => $userInfo,
|
|
'colour' => $users->getUserColour($userInfo),
|
|
'ftopics' => $forum->countTopics(userInfo: $userInfo, deleted: false),
|
|
'fposts' => $forum->countPosts(userInfo: $userInfo, deleted: false),
|
|
];
|
|
|
|
if(empty($userList))
|
|
http_response_code(404);
|
|
|
|
Template::render('user.listing', [
|
|
'roles' => $rolesAll,
|
|
'role' => $roleInfo,
|
|
'users' => $userList,
|
|
'order_fields' => $orderFields,
|
|
'order_directions' => $orderDirs,
|
|
'order_field' => $orderBy,
|
|
'order_direction' => $orderDir,
|
|
'order_default' => $defaultOrder,
|
|
'can_manage_users' => $canManageUsers,
|
|
'users_pagination' => $pagination,
|
|
]);
|