Files
breadcrumb-the-shire/pages/address-book/index().php
2026-02-04 23:31:53 +01:00

53 lines
1.8 KiB
PHP

<?php
use MintyPHP\Buffer;
use MintyPHP\Support\Guard;
use MintyPHP\Session;
use MintyPHP\Service\PermissionService;
use MintyPHP\Service\TenantScopeService;
use MintyPHP\Service\TenantService;
use MintyPHP\Service\DepartmentService;
use MintyPHP\Service\RoleService;
Guard::requireLogin();
Guard::requirePermissionOrForbidden(PermissionService::ADDRESS_BOOK_VIEW);
$currentUserId = (int) ($_SESSION['user']['id'] ?? 0);
$activeTenants = array_filter(array_map('trim', explode(',', (string) ($_GET['tenants'] ?? ''))));
$activeRoles = array_filter(array_map('trim', explode(',', (string) ($_GET['roles'] ?? ''))));
$activeDepartments = array_filter(array_map('trim', explode(',', (string) ($_GET['departments'] ?? ''))));
$tenantIds = TenantScopeService::getUserTenantIds($currentUserId);
$tenants = TenantService::list();
if ($tenantIds) {
$tenants = array_values(array_filter($tenants, static function (array $tenant) use ($tenantIds): bool {
$id = (int) ($tenant['id'] ?? 0);
return $id > 0 && in_array($id, $tenantIds, true);
}));
} elseif (TenantScopeService::isStrict()) {
$tenants = [];
}
$tenantItems = array_map(
static fn (array $tenant): array => [
'id' => (string) ($tenant['uuid'] ?? ''),
'description' => $tenant['description'] ?? '',
],
$tenants
);
$departments = $tenantIds
? DepartmentService::listByTenantIds($tenantIds)
: (TenantScopeService::isStrict() ? [] : DepartmentService::list());
$roles = RoleService::list();
$csrfKey = Session::$csrfSessionKey;
$csrfToken = $_SESSION[$csrfKey] ?? '';
Buffer::set('title', t('Address book'));
Buffer::set('grid_lang', json_encode(gridLang(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
Buffer::set(
'grid_csrf',
json_encode(['key' => $csrfKey, 'token' => $csrfToken], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
);