Files
breadcrumb-the-shire/templates/partials/app-aside.phtml
2026-02-04 23:31:53 +01:00

400 lines
20 KiB
PHTML

<?php
use MintyPHP\Service\TenantAvatarService;
$canViewTenants = can('tenants.view');
$canViewDepartments = can('departments.view');
$canViewUsers = can('users.view');
$canViewRoles = can('roles.view');
$canViewPermissions = can('permissions.view');
$canViewSettings = can('settings.view');
$canViewMailLog = can('mail_log.view');
$canViewStats = can('stats.view');
$canViewAddressBook = can('address_book.view');
$hasOrganization = $canViewTenants || $canViewDepartments || $canViewUsers;
$hasUsersSection = $canViewRoles || $canViewPermissions || $canViewSettings;
$hasSystemSection = $canViewStats || $canViewMailLog || $canViewSettings;
$hasAdminPanel = $hasOrganization || $hasUsersSection || $hasSystemSection;
// Declarative nav config for admin panel
$navSections = [
[
'label' => '',
'visible' => $hasOrganization,
'items' => [
[
'label' => t('Tenants'),
'path' => 'admin/tenants',
'active' => navActive('admin/tenants', true),
'visible' => $canViewTenants,
'withTenant' => false,
],
[
'label' => t('Departments'),
'path' => 'admin/departments',
'active' => navActive('admin/departments', true),
'visible' => $canViewDepartments,
'withTenant' => true,
],
[
'label' => t('Users'),
'path' => 'admin/users',
'active' => navActive('admin/users', true),
'visible' => $canViewUsers,
'withTenant' => true,
],
],
],
[
'label' => t('Roles & permissions'),
'visible' => $hasUsersSection,
'items' => [
[
'label' => t('Roles'),
'path' => 'admin/roles',
'active' => navActive('admin/roles', true),
'visible' => $canViewRoles,
'withTenant' => false,
],
[
'label' => t('Permissions'),
'path' => 'admin/permissions',
'active' => navActive('admin/permissions', true),
'visible' => $canViewPermissions,
'withTenant' => false,
],
],
],
[
'label' => t('System'),
'visible' => $hasSystemSection,
'items' => [
[
'label' => t('Statistics'),
'path' => 'admin/stats',
'active' => navActive('admin/stats', true),
'visible' => $canViewStats,
'withTenant' => false,
],
[
'label' => t('Mail logs'),
'path' => 'admin/mail-log',
'active' => navActive('admin/mail-log', true),
'visible' => $canViewMailLog,
'withTenant' => false,
],
[
'label' => t('Settings'),
'path' => 'admin/settings',
'active' => navActive('admin/settings', true),
'visible' => $canViewSettings,
'withTenant' => false,
],
],
],
];
// Render helper for admin sections
$renderNavSection = static function (array $section, string $tenantQueryParam): void {
if (empty($section['visible'])) {
return;
}
$items = $section['items'] ?? [];
$items = array_values(array_filter($items, static fn ($item) => !empty($item['visible'])));
if (!$items) {
return;
}
?>
<?php if (!empty($section['label'])): ?>
<small><?php e($section['label']); ?></small>
<?php endif; ?>
<?php foreach ($items as $item): ?>
<?php
$href = $item['path'] ?? '';
if ($href !== '' && !empty($item['withTenant'])) {
$href .= $tenantQueryParam;
}
$active = $item['active'] ?? ['class' => '', 'aria' => ''];
?>
<li>
<a href="<?php e($href); ?>" class="<?php e($active['class'] ?? ''); ?>" <?php echo $active['aria'] ?? ''; ?>>
<?php e($item['label'] ?? ''); ?>
</a>
</li>
<?php endforeach; ?>
<?php
};
// Load tenant context from session (no DB calls allowed in templates)
$currentTenant = $_SESSION['current_tenant'] ?? null;
$currentTenantId = $currentTenant['id'] ?? null;
$availableTenants = $_SESSION['available_tenants'] ?? [];
// Add tenant filter to links when user has multiple tenants
$tenantQueryParam = '';
if (count($availableTenants) > 1 && !empty($currentTenant['uuid'])) {
$tenantQueryParam = '?tenant=' . urlencode($currentTenant['uuid']);
}
// Tenant logo display (without switcher - switcher is now in topbar)
$tenantUuid = $currentTenant['uuid'] ?? '';
$tenantName = $currentTenant['description'] ?? '';
$hasTenantAvatar = $tenantUuid && TenantAvatarService::hasAvatar($tenantUuid);
$addressBookUrl = lurl('address-book');
$activeAddressTenants = array_filter(array_map('trim', explode(',', (string) ($_GET['tenants'] ?? ''))));
$activeAddressDepartments = array_filter(array_map('intval', explode(',', (string) ($_GET['departments'] ?? ''))));
$peopleGroups = $_SESSION['available_departments_by_tenant'] ?? [];
?>
<aside class="app-sidebar" id="app-sidebar">
<?php if ($currentTenant): ?>
<div class="app-sidebar-tenant-logo">
<a href="/">
<?php if ($hasTenantAvatar): ?>
<img src="admin/tenants/avatar-file?uuid=<?php e($tenantUuid); ?>&size=128" alt="<?php e($tenantName); ?>"
title="<?php e($tenantName); ?>">
<?php else: ?>
<div class="app-sidebar-tenant-name">
<i class="bi bi-buildings"></i> <?php e($tenantName); ?>
</div>
<?php endif; ?>
</a>
</div>
<?php endif; ?>
<div class="app-sidebar-titlebar">
<div class="app-sidebar-title" data-aside-title-default="<?php e(t('Explorer')); ?>">
<?php e(t('Explorer')); ?>
</div>
<div class="app-sidebar-tools" data-aside-tools></div>
</div>
<div id="app-sidebar-panels" class="app-sidebar-panels">
<nav id="aside-panel-explorer" class="app-sidebar-panel" data-aside-panel="explorer"
data-aside-title="<?php e(t('Explorer')); ?>" role="tabpanel" aria-labelledby="aside-tab-explorer"
aria-label="<?php e(t('Primary navigation')); ?>">
<ul>
<li>
<?php $home = navActive(['', 'admin'], false); ?>
<a href="<?php e(lurl('')); ?>" class="<?php e($home['class']); ?>" <?php echo $home['aria']; ?>>
<?php e(t('Home')); ?>
</a>
</li>
</ul>
<div class="app-sidebar-panel-tools" data-aside-panel-tools hidden>
<!-- <button type="button" class="icon-button" aria-label="<?php e(t('Add')); ?>">
<i class="bi bi-plus-lg"></i>
</button> -->
</div>
</nav>
<?php if ($hasAdminPanel): ?>
<nav id="aside-panel-admin" class="app-sidebar-panel" data-aside-panel="admin"
data-aside-title="<?php e(t('Admin')); ?>" role="tabpanel" aria-labelledby="aside-tab-admin" hidden>
<ul>
<?php foreach ($navSections as $section): ?>
<?php $renderNavSection($section, $tenantQueryParam); ?>
<?php endforeach; ?>
</ul>
<div class="app-sidebar-panel-tools" data-aside-panel-tools hidden></div>
</nav>
<?php endif; ?>
<?php if ($canViewAddressBook): ?>
<?php $addressBookActive = navActive('address-book', true); ?>
<nav id="aside-panel-people" class="app-sidebar-panel" data-aside-panel="people"
data-aside-details-storage="aside-people-tenant"
data-aside-title="<?php e(t('Address book')); ?>" role="tabpanel" aria-labelledby="aside-tab-people" hidden>
<ul>
<?php if (!$peopleGroups): ?>
<li>
<a href="<?php e($addressBookUrl); ?>" class="<?php e($addressBookActive['class'] ?? ''); ?>"
<?php echo $addressBookActive['aria'] ?? ''; ?>>
<?php e(t('Address book')); ?>
</a>
</li>
<?php else: ?>
<?php
$allPeopleActive = $addressBookActive['isActive'] && !$activeAddressTenants && !$activeAddressDepartments;
?>
<?php foreach ($peopleGroups as $index => $group): ?>
<?php
$tenant = $group['tenant'] ?? [];
$departments = $group['departments'] ?? [];
$tenantUuid = (string) ($tenant['uuid'] ?? '');
$tenantName = (string) ($tenant['description'] ?? '');
if ($tenantUuid === '') {
continue;
}
$baseHref = $addressBookUrl . '?tenants=' . urlencode($tenantUuid);
$isActiveTenant = $addressBookActive['isActive']
&& !$activeAddressDepartments
&& count($activeAddressTenants) === 1
&& $activeAddressTenants[0] === $tenantUuid;
?>
<li class="app-sidebar-group">
<details data-details-key="<?php e($tenantUuid); ?>" <?php echo $index === 0 ? 'open' : ''; ?>>
<summary>
<span>
<?php e($tenantName); ?>
</span>
</summary>
<ul>
<li>
<a href="<?php e($baseHref); ?>" class="<?php e($isActiveTenant ? 'active' : ''); ?>"
<?php echo $isActiveTenant ? 'aria-current="page"' : ''; ?>>
<small><?php e(t('All people')); ?></small>
</a>
</li>
<?php foreach ($departments as $department): ?>
<?php
$departmentId = (int) ($department['id'] ?? 0);
if ($departmentId <= 0) {
continue;
}
$departmentName = (string) ($department['description'] ?? '');
$href = $baseHref . '&departments=' . $departmentId;
$isActive = $addressBookActive['isActive']
&& in_array($tenantUuid, $activeAddressTenants, true)
&& in_array($departmentId, $activeAddressDepartments, true);
?>
<li>
<a href="<?php e($href); ?>" class="<?php e($isActive ? 'active' : ''); ?>"
<?php echo $isActive ? 'aria-current="page"' : ''; ?>>
<small>
<?php e($departmentName); ?>
</small>
</a>
</li>
<?php endforeach; ?>
</ul>
</details>
<hr>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
<div class="app-sidebar-panel-tools" data-aside-panel-tools hidden></div>
</nav>
<?php endif; ?>
<div id="aside-panel-search" class="app-sidebar-panel" data-aside-panel="search"
data-aside-title="<?php e(t('Search')); ?>" role="tabpanel" aria-labelledby="aside-tab-search" hidden>
<form class="app-search">
<input type="search" name="side-search" id="side-search" placeholder="<?php e(t('Search...')); ?>"
aria-label="<?php e(t('Search')); ?>">
</form>
<nav id="global-search">
<ul class="app-search-results" data-global-search-results>
<?php if (can('users.view')): ?>
<?php $usersSearch = navActive('admin/users', true); ?>
<li data-search-key="users" data-search-base="<?php e(lurl('admin/users')); ?>">
<a href="<?php e(lurl('admin/users')); ?>" class="<?php e($usersSearch['class']); ?>" <?php echo $usersSearch['aria']; ?>>
<span><?php e(t('Users')); ?></span>
<span class="badge" data-search-count>0</span>
</a>
<ul class="app-search-preview" data-search-preview></ul>
</li>
<?php endif; ?>
<?php if ($canViewAddressBook): ?>
<?php $addressBookSearch = navActive('address-book', true); ?>
<li data-search-key="address-book" data-search-base="<?php e(lurl('address-book')); ?>">
<a href="<?php e(lurl('address-book')); ?>" class="<?php e($addressBookSearch['class'] ?? ''); ?>"
<?php echo $addressBookSearch['aria'] ?? ''; ?>>
<span><?php e(t('Address book')); ?></span>
<span class="badge" data-search-count>0</span>
</a>
<ul class="app-search-preview" data-search-preview></ul>
</li>
<?php endif; ?>
<?php if (can('tenants.view')): ?>
<?php $tenantsSearch = navActive('admin/tenants', true); ?>
<li data-search-key="tenants" data-search-base="<?php e(lurl('admin/tenants')); ?>">
<a href="<?php e(lurl('admin/tenants')); ?>" class="<?php e($tenantsSearch['class']); ?>" <?php echo $tenantsSearch['aria']; ?>>
<span><?php e(t('Tenants')); ?></span>
<span class="badge" data-search-count>0</span>
</a>
<ul class="app-search-preview" data-search-preview></ul>
</li>
<?php endif; ?>
<?php if (can('departments.view')): ?>
<?php $departmentsSearch = navActive('admin/departments', true); ?>
<li data-search-key="departments" data-search-base="<?php e(lurl('admin/departments')); ?>">
<a href="<?php e(lurl('admin/departments')); ?>"
class="<?php e($departmentsSearch['class']); ?>" <?php echo $departmentsSearch['aria']; ?>>
<span><?php e(t('Departments')); ?></span>
<span class="badge" data-search-count>0</span>
</a>
<ul class="app-search-preview" data-search-preview></ul>
</li>
<?php endif; ?>
<?php if (can('roles.view')): ?>
<?php $rolesSearch = navActive('admin/roles', true); ?>
<li data-search-key="roles" data-search-base="<?php e(lurl('admin/roles')); ?>">
<a href="<?php e(lurl('admin/roles')); ?>" class="<?php e($rolesSearch['class']); ?>" <?php echo $rolesSearch['aria']; ?>>
<span><?php e(t('Roles')); ?></span>
<span class="badge" data-search-count>0</span>
</a>
<ul class="app-search-preview" data-search-preview></ul>
</li>
<?php endif; ?>
<?php if (can('permissions.view')): ?>
<?php $permissionsSearch = navActive('admin/permissions', true); ?>
<li data-search-key="permissions" data-search-base="<?php e(lurl('admin/permissions')); ?>">
<a href="<?php e(lurl('admin/permissions')); ?>"
class="<?php e($permissionsSearch['class']); ?>" <?php echo $permissionsSearch['aria']; ?>>
<span><?php e(t('Permissions')); ?></span>
<span class="badge" data-search-count>0</span>
</a>
<ul class="app-search-preview" data-search-preview></ul>
</li>
<?php endif; ?>
<?php
$pagesSearch = navActivePublicPages();
?>
<li data-search-key="pages" data-search-base="<?php e(lurl('')); ?>">
<a href="<?php e(lurl('')); ?>" class="<?php e($pagesSearch['class']); ?>" <?php echo $pagesSearch['aria']; ?>>
<span><?php e(t('Pages')); ?></span>
<span class="badge" data-search-count>0</span>
</a>
<ul class="app-search-preview" data-search-preview></ul>
</li>
<?php if (can('settings.view')): ?>
<?php $settingsSearch = navActive('admin/settings', true); ?>
<li data-search-key="settings" data-search-base="<?php e(lurl('admin/settings')); ?>">
<a href="<?php e(lurl('admin/settings')); ?>" class="<?php e($settingsSearch['class']); ?>"
<?php echo $settingsSearch['aria']; ?>>
<span><?php e(t('Settings')); ?></span>
<span class="badge" data-search-count>0</span>
</a>
</li>
<?php endif; ?>
</ul>
</nav>
<div class="app-sidebar-panel-tools" data-aside-panel-tools hidden>
<button type="button" class="icon-button" data-tooltip="<?php e(t('Toggle search details')); ?>"
data-tooltip-pos="bottom" aria-label="<?php e(t('Toggle search details')); ?>"
data-search-details-toggle>
<i class="bi bi-dash-square" data-search-details-icon></i>
</button>
</div>
</div>
<nav id="aside-panel-files" class="app-sidebar-panel" data-aside-panel="files"
data-aside-title="<?php e(t('Files')); ?>" role="tabpanel" aria-labelledby="aside-tab-files" hidden>
<ul>
<li>
<a href="#"><?php e(t('All files')); ?></a>
</li>
<li>
<a href="#"><?php e(t('My files')); ?></a>
</li>
<li>
<a href="#"><?php e(t('Shared with me')); ?></a>
</li>
</ul>
<div class="app-sidebar-panel-tools" data-aside-panel-tools hidden>
<button type="button" class="icon-button" aria-label="<?php e(t('New folder')); ?>">
<i class="bi bi-folder-plus"></i>
</button>
</div>
</nav>
</div>
</aside>