Files
breadcrumb-the-shire/pages/admin/settings/index(default).phtml
2026-02-23 16:00:04 +01:00

517 lines
26 KiB
PHTML

<?php
/**
* @var array $tenants
* @var array $roles
* @var array $departments
* @var array $values
* @var array $settings
*/
use MintyPHP\Session;
use MintyPHP\Service\Branding\BrandingServicesFactory;
$values = $values ?? [];
$settings = $settings ?? [];
$defaultTenantId = (int) ($values['default_tenant_id'] ?? 0);
$defaultRoleId = (int) ($values['default_role_id'] ?? 0);
$defaultDepartmentId = (int) ($values['default_department_id'] ?? 0);
$appTitle = (string) ($values['app_title'] ?? '');
$appLocale = (string) ($values['app_locale'] ?? '');
$appTheme = (string) ($values['app_theme'] ?? '');
$appThemeUser = !empty($values['app_theme_user']);
$appRegistration = !empty($values['app_registration']);
$apiTokenDefaultTtlDays = (int) ($values['api_token_default_ttl_days'] ?? 90);
$apiTokenMaxTtlDays = (int) ($values['api_token_max_ttl_days'] ?? 365);
$userInactivityDeactivateDays = (int) ($values['user_inactivity_deactivate_days'] ?? 180);
$userInactivityDeleteDays = (int) ($values['user_inactivity_delete_days'] ?? 365);
$apiCorsAllowedOrigins = (string) ($values['api_cors_allowed_origins'] ?? '');
$appPrimaryColor = (string) ($values['app_primary_color'] ?? '');
$microsoftSharedClientId = (string) ($values['microsoft_shared_client_id'] ?? '');
$microsoftAuthority = (string) ($values['microsoft_authority'] ?? '');
$themes = appThemes();
$smtpHost = (string) ($values['smtp_host'] ?? '');
$smtpPort = (string) ($values['smtp_port'] ?? '');
$smtpUser = (string) ($values['smtp_user'] ?? '');
$smtpSecure = (string) ($values['smtp_secure'] ?? '');
$smtpFrom = (string) ($values['smtp_from'] ?? '');
$smtpFromName = (string) ($values['smtp_from_name'] ?? '');
$activeLoginTokens = (int) ($activeLoginTokens ?? 0);
$activeApiTokens = (int) ($activeApiTokens ?? 0);
$defaultTenantDesc = $settings['default_tenant']['description'] ?? 'setting.default_tenant';
$defaultRoleDesc = $settings['default_role']['description'] ?? 'setting.default_role';
$defaultDepartmentDesc = $settings['default_department']['description'] ?? 'setting.default_department';
$appTitleDesc = $settings['app_title']['description'] ?? 'setting.app_title';
$appLocaleDesc = $settings['app_locale']['description'] ?? 'setting.app_locale';
$appThemeDesc = $settings['app_theme']['description'] ?? 'setting.app_theme';
$appThemeUserDesc = $settings['app_theme_user']['description'] ?? 'setting.app_theme_user';
$appRegistrationDesc = $settings['app_registration']['description'] ?? 'setting.app_registration';
$apiTokenDefaultTtlDaysDesc = $settings['api_token_default_ttl_days']['description'] ?? 'setting.api_token_default_ttl_days';
$apiTokenMaxTtlDaysDesc = $settings['api_token_max_ttl_days']['description'] ?? 'setting.api_token_max_ttl_days';
$userInactivityDeactivateDaysDesc = $settings['user_inactivity_deactivate_days']['description'] ?? 'setting.user_inactivity_deactivate_days';
$userInactivityDeleteDaysDesc = $settings['user_inactivity_delete_days']['description'] ?? 'setting.user_inactivity_delete_days';
$apiCorsAllowedOriginsDesc = $settings['api_cors_allowed_origins']['description'] ?? 'setting.api_cors_allowed_origins';
$appPrimaryColorDesc = $settings['app_primary_color']['description'] ?? 'setting.app_primary_color';
$microsoftSharedClientIdDesc = $settings['microsoft_shared_client_id']['description'] ?? 'setting.microsoft_shared_client_id';
$microsoftSharedClientSecretDesc = $settings['microsoft_shared_client_secret_enc']['description'] ?? 'setting.microsoft_shared_client_secret_enc';
$microsoftAuthorityDesc = $settings['microsoft_authority']['description'] ?? 'setting.microsoft_authority';
$smtpHostDesc = $settings['smtp_host']['description'] ?? 'setting.smtp_host';
$smtpPortDesc = $settings['smtp_port']['description'] ?? 'setting.smtp_port';
$smtpUserDesc = $settings['smtp_user']['description'] ?? 'setting.smtp_user';
$smtpPasswordDesc = $settings['smtp_password']['description'] ?? 'setting.smtp_password';
$smtpSecureDesc = $settings['smtp_secure']['description'] ?? 'setting.smtp_secure';
$smtpFromDesc = $settings['smtp_from']['description'] ?? 'setting.smtp_from';
$smtpFromNameDesc = $settings['smtp_from_name']['description'] ?? 'setting.smtp_from_name';
$locales = defined('APP_LOCALES') ? APP_LOCALES : [];
$brandingServicesFactory = new BrandingServicesFactory();
$hasLogo = $brandingServicesFactory->createBrandingLogoService()->hasLogo();
$hasFavicon = $brandingServicesFactory->createBrandingFaviconService()->hasFavicon();
$canUpdateSettings = can('settings.update');
$isReadOnly = !$canUpdateSettings;
$readonlyAttr = $isReadOnly ? 'readonly' : '';
$disabledAttr = $isReadOnly ? 'disabled' : '';
?>
<div class="app-details-container">
<section>
<?php
$breadcrumbs = [
['label' => t('Home'), 'path' => 'admin'],
['label' => t('Settings')],
];
require templatePath('partials/app-breadcrumb.phtml');
?>
<div class="app-details-titlebar">
<h1>
<?php e(t('Settings')); ?>
</h1>
<div class="app-details-titlebar-actions">
<?php if ($canUpdateSettings): ?>
<button type="submit" form="settings-form" class="primary">
<?php e(t('Save')); ?>
</button>
<?php endif; ?>
</div>
</div>
<form id="settings-form" method="post" data-details-storage="settings-main-details-v1">
<input type="hidden" name="settings_submit" value="1">
<div class="app-tabs" data-tabs data-tabs-param="tab" data-tabs-storage-key="admin-settings-tabs-v1">
<div class="app-tabs-nav">
<button type="button" data-tab="master-data" data-tab-default><?php e(t('Master data')); ?></button>
<button type="button" data-tab="appearance"><?php e(t('Appearance')); ?></button>
<button type="button" data-tab="security"><?php e(t('Security')); ?></button>
<button type="button" data-tab="email"><?php e(t('Email')); ?></button>
<button type="button" data-tab="api"><?php e(t('API')); ?></button>
<button type="button" data-tab="integrations"><?php e(t('Microsoft SSO')); ?></button>
<?php if ($canUpdateSettings): ?>
<button type="button" data-tab="danger"><?php e(t('Danger zone')); ?></button>
<?php endif; ?>
</div>
<div data-tab-panel="master-data">
<label class="app-field">
<span><?php e(t('App title')); ?> <span class="badge" data-variant="info"><?php e(t('Cached')); ?></span></span>
<input type="text" name="app_title" value="<?php e($appTitle); ?>" placeholder="<?php e(appTitle()); ?>" <?php e($readonlyAttr); ?>>
<small><?php e(t($appTitleDesc)); ?></small>
</label>
<hr>
<details name="internationalization" data-details-key="internationalization">
<summary><?php e(t('Internationalization')); ?></summary>
<hr>
<label class="app-field">
<span><?php e(t('Default language')); ?> <span class="badge" data-variant="info"><?php e(t('Cached')); ?></span></span>
<select name="app_locale" <?php e($disabledAttr); ?>>
<option value=""><?php e(t('None')); ?></option>
<?php foreach ($locales as $locale): ?>
<?php
$label = strtoupper($locale);
if ($locale === 'de') {
$label = t('German');
} elseif ($locale === 'en') {
$label = t('English');
}
?>
<option value="<?php e($locale); ?>" <?php e($appLocale === $locale ? 'selected' : ''); ?>>
<?php e($label); ?>
</option>
<?php endforeach; ?>
</select>
<small><?php e(t($appLocaleDesc)); ?></small>
</label>
</details>
<hr>
<details name="user-creation" data-details-key="user-creation">
<summary><?php e(t('User creation rules')); ?></summary>
<hr>
<div class="grid">
<label class="app-field">
<span>
<?php e(t('Default tenant')); ?>
</span>
<select name="default_tenant_id" <?php e($disabledAttr); ?>>
<option value="">
<?php e(t('None')); ?>
</option>
<?php foreach ($tenants ?? [] as $tenant): ?>
<?php $tenantId = (int) ($tenant['id'] ?? 0); ?>
<?php if ($tenantId > 0): ?>
<option value="<?php e((string) $tenantId); ?>" <?php e($tenantId === $defaultTenantId ? 'selected' : ''); ?>>
<?php e($tenant['description'] ?? ''); ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
<small>
<?php e(t($defaultTenantDesc)); ?>
</small>
</label>
<label class="app-field">
<span>
<?php e(t('Default department')); ?>
</span>
<select name="default_department_id" <?php e($disabledAttr); ?>>
<option value="">
<?php e(t('None')); ?>
</option>
<?php foreach ($departments ?? [] as $department): ?>
<?php $departmentId = (int) ($department['id'] ?? 0); ?>
<?php if ($departmentId > 0): ?>
<option value="<?php e((string) $departmentId); ?>" <?php e($departmentId === $defaultDepartmentId ? 'selected' : ''); ?>>
<?php e($department['description'] ?? ''); ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
<small>
<?php e(t($defaultDepartmentDesc)); ?>
</small>
</label>
</div>
<label class="app-field">
<span><?php e(t('Default role')); ?></span>
<select name="default_role_id" <?php e($disabledAttr); ?>>
<option value=""><?php e(t('None')); ?></option>
<?php foreach ($roles ?? [] as $role): ?>
<?php $roleId = (int) ($role['id'] ?? 0); ?>
<?php if ($roleId > 0): ?>
<option value="<?php e((string) $roleId); ?>" <?php e($roleId === $defaultRoleId ? 'selected' : ''); ?>>
<?php e($role['description'] ?? ''); ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
<small><?php e(t($defaultRoleDesc)); ?></small>
</label>
</details>
</div>
<div data-tab-panel="appearance">
<blockquote data-variant="info">
<?php e(t('Tenants can override color and theme behavior in their appearance settings.')); ?>
</blockquote>
<hr>
<div class="grid">
<fieldset>
<legend><small><?php e(t('Default theme')); ?> <span class="badge" data-variant="info"><?php e(t('Cached')); ?></span></small></legend>
<select name="app_theme" <?php e($disabledAttr); ?>>
<option value=""><?php e(t('None')); ?></option>
<?php foreach ($themes as $key => $label): ?>
<option value="<?php e($key); ?>" <?php e($appTheme === $key ? 'selected' : ''); ?>>
<?php e(t($label)); ?>
</option>
<?php endforeach; ?>
</select>
<small><?php e(t($appThemeDesc)); ?></small>
</fieldset>
<fieldset>
<legend><small><?php e(t('Primary color')); ?> <span class="badge" data-variant="info"><?php e(t('Cached')); ?></span></small></legend>
<label class="app-field">
<input type="color" name="app_primary_color"
value="<?php e($appPrimaryColor !== '' ? $appPrimaryColor : '#2fa4a4'); ?>" <?php e($disabledAttr); ?>>
<div>
<div>
<?php e(t('Choose color')); ?>
</div>
</div>
</label>
<small class="muted"><?php e(t($appPrimaryColorDesc)); ?></small>
</fieldset>
</div>
<fieldset>
<legend>
<small>
<?php e(t($appThemeUserDesc)); ?>
</small>
</legend>
<label class="app-field">
<input type="checkbox" name="app_theme_user" value="1" <?php e($appThemeUser ? 'checked' : ''); ?> <?php e($disabledAttr); ?>>
<span><?php e(t('Allow user theme')); ?> <span class="badge" data-variant="info"><?php e(t('Cached')); ?></span></span>
</label>
</fieldset>
</div>
<div data-tab-panel="security">
<fieldset>
<legend>
<small>
<?php e(t($appRegistrationDesc)); ?>
</small>
</legend>
<label class="app-field">
<input type="checkbox" name="app_registration" value="1" <?php e($appRegistration ? 'checked' : ''); ?>
<?php e($disabledAttr); ?>>
<span><?php e(t('Allow registration')); ?> <span class="badge" data-variant="info"><?php e(t('Cached')); ?></span></span>
</label>
</fieldset>
<hr>
<fieldset>
<legend><small><?php e(t('User lifecycle policy')); ?></small></legend>
<div class="grid">
<label class="app-field">
<span><?php e(t('Deactivate users after inactivity (days)')); ?></span>
<input type="number" name="user_inactivity_deactivate_days"
value="<?php e((string) $userInactivityDeactivateDays); ?>" min="0" max="3650" step="1"
<?php e($readonlyAttr); ?>>
<small><?php e(t($userInactivityDeactivateDaysDesc)); ?></small>
</label>
<label class="app-field">
<span><?php e(t('Delete inactive users after (days)')); ?></span>
<input type="number" name="user_inactivity_delete_days"
value="<?php e((string) $userInactivityDeleteDays); ?>" min="0" max="3650" step="1"
<?php e($readonlyAttr); ?>>
<small><?php e(t($userInactivityDeleteDaysDesc)); ?></small>
</label>
</div>
<small class="muted"><?php e(t('0 disables this rule')); ?></small>
<small class="muted"><?php e(t('Deletion starts after user was set inactive')); ?></small>
<small class="muted"><?php e(t('Privileged admins are excluded from automatic lifecycle actions')); ?></small>
<?php if ($canUpdateSettings): ?>
<hr>
<button type="submit" class="outline warning" formnovalidate
formaction="admin/settings/run-user-lifecycle"
formmethod="post"
onclick="return confirm('<?php e(t('Run user lifecycle now?')); ?>');">
<?php e(t('Run user lifecycle now')); ?>
</button>
<?php endif; ?>
</fieldset>
</div>
<div data-tab-panel="email">
<div class="grid">
<label class="app-field">
<span><?php e(t('SMTP host')); ?></span>
<input type="text" name="smtp_host" value="<?php e($smtpHost); ?>" <?php e($readonlyAttr); ?>>
<small><?php e(t($smtpHostDesc)); ?></small>
</label>
<label class="app-field">
<span><?php e(t('SMTP port')); ?></span>
<input type="number" name="smtp_port" value="<?php e($smtpPort); ?>" min="1" max="65535" <?php e($readonlyAttr); ?>>
<small><?php e(t($smtpPortDesc)); ?></small>
</label>
</div>
<div class="grid">
<label class="app-field">
<span><?php e(t('SMTP user')); ?></span>
<input type="text" name="smtp_user" value="<?php e($smtpUser); ?>" autocomplete="username" <?php e($readonlyAttr); ?>>
<small><?php e(t($smtpUserDesc)); ?></small>
</label>
<label class="app-field">
<span><?php e(t('SMTP password')); ?></span>
<input type="password" name="smtp_password" value="" autocomplete="new-password" <?php e($readonlyAttr); ?>>
<small><?php e(t($smtpPasswordDesc)); ?></small>
</label>
</div>
<div class="grid">
<label class="app-field">
<span><?php e(t('SMTP security')); ?></span>
<select name="smtp_secure" <?php e($disabledAttr); ?>>
<option value=""><?php e(t('None')); ?></option>
<option value="tls" <?php e($smtpSecure === 'tls' ? 'selected' : ''); ?>>TLS</option>
<option value="ssl" <?php e($smtpSecure === 'ssl' ? 'selected' : ''); ?>>SSL</option>
</select>
<small><?php e(t($smtpSecureDesc)); ?></small>
</label>
<label class="app-field">
<span><?php e(t('SMTP from address')); ?></span>
<input type="email" name="smtp_from" value="<?php e($smtpFrom); ?>" <?php e($readonlyAttr); ?>>
<small><?php e(t($smtpFromDesc)); ?></small>
</label>
</div>
<label class="app-field">
<span><?php e(t('SMTP from name')); ?></span>
<input type="text" name="smtp_from_name" value="<?php e($smtpFromName); ?>" <?php e($readonlyAttr); ?>>
<small><?php e(t($smtpFromNameDesc)); ?></small>
</label>
</div>
<div data-tab-panel="api">
<p class="muted"><?php e(t('API tokens and default lifetimes are managed here.')); ?></p>
<div class="grid">
<label class="app-field">
<span><?php e(t('API token default lifetime (days)')); ?> <span class="badge" data-variant="info"><?php e(t('Cached')); ?></span></span>
<input type="number" name="api_token_default_ttl_days" value="<?php e((string) $apiTokenDefaultTtlDays); ?>"
min="1" max="3650" step="1" <?php e($readonlyAttr); ?>>
<small><?php e(t($apiTokenDefaultTtlDaysDesc)); ?></small>
</label>
<label class="app-field">
<span><?php e(t('API token maximum lifetime (days)')); ?> <span class="badge" data-variant="info"><?php e(t('Cached')); ?></span></span>
<input type="number" name="api_token_max_ttl_days" value="<?php e((string) $apiTokenMaxTtlDays); ?>"
min="1" max="3650" step="1" <?php e($readonlyAttr); ?>>
<small><?php e(t($apiTokenMaxTtlDaysDesc)); ?></small>
</label>
</div>
<label class="app-field">
<span><?php e(t('Allowed CORS origins')); ?> <span class="badge" data-variant="info"><?php e(t('Cached')); ?></span></span>
<textarea name="api_cors_allowed_origins" rows="4" placeholder="https://app.example.com&#10;https://admin.example.com" <?php e($readonlyAttr); ?>><?php e($apiCorsAllowedOrigins); ?></textarea>
<small><?php e(t($apiCorsAllowedOriginsDesc)); ?></small>
</label>
<small class="muted"><?php e(t('One origin per line, e.g. https://app.example.com')); ?></small>
<?php if ($canUpdateSettings): ?>
<fieldset>
<legend><small><?php e(t('API tokens')); ?></small></legend>
<p class="muted"><?php e(t('All API tokens will be revoked immediately.')); ?></p>
<p class="muted"><?php e(sprintf(t('%d active API tokens'), $activeApiTokens)); ?></p>
<button type="submit" class="danger" formnovalidate
formaction="admin/settings/revoke-api-tokens"
formmethod="post"
onclick="return confirm('<?php e(t('Revoke all API tokens?')); ?>');">
<?php e(t('Revoke all API tokens')); ?>
</button>
</fieldset>
<?php endif; ?>
</div>
<div data-tab-panel="integrations">
<blockquote data-variant="info">
<?php e(t('Shared Microsoft app credentials are used by tenants that enable "Use shared app credentials".')); ?>
</blockquote>
<label class="app-field">
<span><?php e(t('Shared client ID')); ?></span>
<input type="text" name="microsoft_shared_client_id" value="<?php e($microsoftSharedClientId); ?>" <?php e($readonlyAttr); ?>>
<small><?php e(t($microsoftSharedClientIdDesc)); ?></small>
</label>
<label class="app-field">
<span><?php e(t('Shared client secret')); ?></span>
<input type="password" name="microsoft_shared_client_secret" value="" autocomplete="new-password" <?php e($readonlyAttr); ?>>
<small><?php e(t($microsoftSharedClientSecretDesc)); ?></small>
</label>
<label class="app-field">
<span><?php e(t('Authority URL')); ?></span>
<input type="url" name="microsoft_authority" value="<?php e($microsoftAuthority); ?>" placeholder="https://login.microsoftonline.com/common/v2.0" <?php e($readonlyAttr); ?>>
<small><?php e(t($microsoftAuthorityDesc)); ?></small>
</label>
</div>
<?php if ($canUpdateSettings): ?>
<div data-tab-panel="danger">
<fieldset>
<legend><small><?php e(t('Login tokens')); ?></small></legend>
<p class="muted">
<?php e(t('This will mark all remember-me tokens as expired. Users will need to sign in again.')); ?>
</p>
<p class="muted">
<?php e(sprintf(t('%d active login tokens'), $activeLoginTokens)); ?>
</p>
<form method="post" action="admin/settings/expire-remember-tokens"
onsubmit="return confirm('<?php e(t('Expire all login tokens?')); ?>');">
<button type="submit" class="danger">
<?php e(t('Expire all login tokens')); ?>
</button>
<?php Session::getCsrfInput(); ?>
</form>
</fieldset>
</div>
<?php endif; ?>
</div>
<?php Session::getCsrfInput(); ?>
</form>
</section>
<aside id="app-details-aside-section">
<div class="app-details-aside-section">
<div class="entity-avatar-block avatar-square avatar-ratio-16-9 avatar-borderless">
<a data-fslightbox="app-logo" href="<?php e(appLogoUrl(256)); ?>">
<img class="entity-avatar-image" src="<?php e(appLogoUrl(256)); ?>" alt="<?php e(t('App logo')); ?>">
</a>
</div>
<hgroup>
<h2><?php e(appTitle()); ?></h2>
<p><?php e(t('Settings')); ?></p>
</hgroup>
<hr>
<?php if ($canUpdateSettings): ?>
<details name="app-logo">
<summary>
<?php e(t('Upload logo')); ?>
</summary>
<hr>
<small>
<?php e(t('Allowed file types: SVG, PNG, JPG, WEBP')); ?>
</small>
<hr>
<form class="user-avatar-form" method="post" action="admin/settings/logo" enctype="multipart/form-data">
<label class="user-avatar-upload">
<input type="file" name="logo" accept="image/svg+xml,image/png,image/jpeg,image/webp">
</label>
<div class="grid">
<button type="submit" class="primary">
<?php e(t('Save')); ?>
</button>
<?php if ($hasLogo): ?>
<button type="submit" class="danger" formaction="admin/settings/logo-delete" formmethod="post">
<?php e(t('Remove logo')); ?>
</button>
<?php endif; ?>
</div>
<?php Session::getCsrfInput(); ?>
</form>
</details>
<?php endif; ?>
<hr>
<?php if ($canUpdateSettings): ?>
<details name="app-favicon">
<summary>
<?php e(t('Upload favicon')); ?>
</summary>
<hr>
<?php if ($hasFavicon): ?>
<div class="entity-avatar-block avatar-square avatar-borderless" style="--avatar-size: 48px;">
<img class="entity-avatar-image" src="<?php e(asset('favicon/favicon-32x32.png')); ?>"
alt="<?php e(t('Favicon')); ?>">
</div>
<small><?php e(t('Favicon preview')); ?></small>
<hr>
<?php endif; ?>
<small><?php e(t('Allowed file types: PNG')); ?></small>
<small><?php e(t('Square images are recommended (icons are center-cropped).')); ?></small>
<hr>
<form class="user-avatar-form" method="post" action="admin/settings/favicon" enctype="multipart/form-data">
<label class="user-avatar-upload">
<input type="file" name="favicon" accept="image/png">
</label>
<div class="grid">
<button type="submit" class="primary">
<?php e(t('Save')); ?>
</button>
<?php if ($hasFavicon): ?>
<button type="submit" class="danger" formaction="admin/settings/favicon-delete" formmethod="post">
<?php e(t('Remove favicon')); ?>
</button>
<?php endif; ?>
</div>
<?php Session::getCsrfInput(); ?>
</form>
</details>
<?php endif; ?>
<hr>
<blockquote data-variant="info">
<?php e(t('Global settings are stored in the database. config/settings.php is only a runtime cache for selected app settings.')); ?>
</blockquote>
</div>
</aside>
</div>