$errors
* @var array $form
* @var array $user
*/
use MintyPHP\Session;
$values = $form;
$avatarUuid = (string) ($values['uuid'] ?? '');
$userAvatarService = app(\MintyPHP\Service\User\UserAvatarService::class);
$hasAvatar = $avatarUuid !== '' && $userAvatarService->hasAvatar($avatarUuid);
$currentUserId = (int) ($_SESSION['user']['id'] ?? 0);
$isOwnAccount = $currentUserId > 0 && $currentUserId === (int) ($values['id'] ?? 0);
$canEditUser = !empty($canEditUser);
$titleText = $isOwnAccount ? t('My account') : ($canEditUser ? t('Edit user') : t('View user'));
$canViewUsers = !empty($canViewUsers);
$canViewUserMeta = !empty($canViewUserMeta);
$canViewUserAudit = !empty($canViewUserAudit);
$canAccessPdf = !empty($canAccessPdf);
$canViewSecurityArtifacts = !empty($canViewSecurityArtifacts);
$canViewPermissionsTable = !empty($canViewPermissionsTable);
$canEditUser = !empty($canEditUser);
$canDeleteUser = !empty($canDeleteUser);
$hideNavigation = $isOwnAccount && !$canViewUsers;
$lastLoginProvider = strtolower((string) ($values['last_login_provider'] ?? ($user['last_login_provider'] ?? '')));
$lastLoginAt = (string) ($values['last_login_at'] ?? ($user['last_login_at'] ?? ''));
$lastLoginProviderLabel = '-';
$lastLoginProviderVariant = 'neutral';
if ($lastLoginAt !== '') {
if ($lastLoginProvider === 'microsoft') {
$lastLoginProviderLabel = t('Microsoft');
$lastLoginProviderVariant = 'primary';
} elseif ($lastLoginProvider === 'local') {
$lastLoginProviderLabel = t('Local');
$lastLoginProviderVariant = 'secondary';
} else {
$lastLoginProviderLabel = t('Unknown');
$lastLoginProviderVariant = 'warning';
}
}
?>
(string) ($values['id'] ?? ''),
'{user_uuid}' => (string) ($values['uuid'] ?? ''),
];
foreach ($moduleAsideActionSlots as $slotAction) {
if (!is_array($slotAction)) {
continue;
}
$slotPermission = trim((string) ($slotAction['permission'] ?? ''));
if ($slotPermission !== '' && empty($layoutAuth[$slotPermission])) {
continue;
}
$slotLabel = trim((string) ($slotAction['label'] ?? ''));
if ($slotLabel === '') {
continue;
}
$slotType = trim((string) ($slotAction['type'] ?? 'link'));
if ($slotType === 'form') {
$slotFormAction = trim((string) ($slotAction['action'] ?? ''));
if ($slotFormAction === '') {
continue;
}
$slotFormAction = strtr($slotFormAction, $slotContextMap);
if (!str_starts_with($slotFormAction, '/') && !str_starts_with($slotFormAction, 'http://') && !str_starts_with($slotFormAction, 'https://')) {
$slotFormAction = lurl($slotFormAction);
}
$asideActions[] = [
'type' => 'form',
'method' => strtoupper(trim((string) ($slotAction['method'] ?? 'POST'))),
'action' => $slotFormAction,
'label' => t($slotLabel),
];
continue;
}
$slotHref = trim((string) ($slotAction['href'] ?? ''));
if ($slotHref === '') {
continue;
}
$slotHref = strtr($slotHref, $slotContextMap);
if (!str_starts_with($slotHref, '/') && !str_starts_with($slotHref, 'http://') && !str_starts_with($slotHref, 'https://')) {
$slotHref = lurl($slotHref);
}
$asideActions[] = [
'type' => 'link',
'href' => $slotHref,
'label' => t($slotLabel),
];
}
if ($canEditUser) {
$asideActions[] = [
'type' => 'form',
'method' => 'post',
'action' => 'admin/users/send-access/' . ($values['uuid'] ?? ''),
'confirm' => t('Send access email to this user?'),
'label' => t('Send access'),
];
}
if ($canAccessPdf) {
$asideActions[] = [
'type' => 'form',
'method' => 'post',
'action' => 'admin/users/access-pdf',
'label' => t('Access PDF'),
'target' => '_blank',
'fields' => [
'uuid' => (string) ($values['uuid'] ?? ''),
],
];
}
$titlebarActions = [];
if ($canEditUser) {
$titlebarActions[] = [
'form' => 'user-form',
'name' => 'action',
'value' => 'save',
'class' => 'secondary outline',
'label' => t('Save'),
];
if (!$hideNavigation) {
$titlebarActions[] = [
'form' => 'user-form',
'name' => 'action',
'value' => 'save_close',
'class' => 'primary',
'label' => t('Save & close'),
];
}
}
$titlebar = [
'title' => $titleText,
'backHref' => $hideNavigation ? '' : 'admin/users',
'backTitle' => t('Cancel'),
'actions' => $titlebarActions,
];
require templatePath('partials/app-details-titlebar.phtml');
?>