misuzu/public-legacy/members.php

119 lines
2.8 KiB
PHP
Raw Permalink Normal View History

2022-09-13 13:14:49 +00:00
<?php
namespace Misuzu;
use RuntimeException;
2022-09-13 13:14:49 +00:00
if(!$msz->isLoggedIn()) {
echo render_error(403);
return;
}
// TODO: restore forum-topics and forum-posts orderings
$users = $msz->getUsers();
2023-07-27 23:26:05 +00:00
$roles = $msz->getRoles();
2023-08-28 01:17:34 +00:00
$forum = $msz->getForum();
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 = [
'asc' => 'In Order',
'desc' => 'Reverse Order',
2022-09-13 13:14:49 +00:00
];
$defaultOrder = 'active';
2022-09-13 13:14:49 +00:00
$orderFields = [
'id' => [
'title' => 'User ID',
],
'name' => [
'title' => 'Username',
],
'country' => [
'title' => 'Country',
],
'created' => [
2022-09-13 13:14:49 +00:00
'title' => 'Registration Date',
],
'active' => [
2022-09-13 13:14:49 +00:00
'title' => 'Last Online',
],
'registered' => [
'alt' => 'created',
'title' => 'Registration Date',
2022-09-13 13:14:49 +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)) {
echo render_error(400);
return;
}
if(array_key_exists('alt', $orderFields[$orderBy]))
$orderBy = $orderFields[$orderBy]['alt'];
2022-09-13 13:14:49 +00:00
if(empty($orderDir)) {
$orderDir = 'asc';
2022-09-13 13:14:49 +00:00
} elseif(!array_key_exists($orderDir, $orderDirs)) {
echo render_error(400);
return;
}
2023-07-27 23:26:05 +00:00
if($roleId === null) {
$roleInfo = $roles->getDefaultRole();
} else {
try {
$roleInfo = $roles->getRole($roleId);
} catch(RuntimeException $ex) {
echo render_error(404);
return;
}
2022-09-13 13:14:49 +00:00
}
2023-08-30 22:37:21 +00:00
$canManageUsers = $msz->getAuthInfo()->getPerms('user')->check(Perm::U_USERS_MANAGE);
$deleted = $canManageUsers ? null : false;
2022-09-13 13:14:49 +00:00
2023-07-27 23:26:05 +00:00
$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),
2023-08-28 01:17:34 +00:00
'ftopics' => $forum->countTopics(userInfo: $userInfo, deleted: false),
'fposts' => $forum->countPosts(userInfo: $userInfo, deleted: false),
];
2022-09-13 13:14:49 +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,
'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,
]);