Files
itflow/admin/post/settings_module.php

59 lines
2.3 KiB
PHP

<?php
/*
* Admin > Settings > Modules (admin/settings_module.php):
* edit_module_settings saves which modules are in use, and the white-label
* key. A key that isn't one is refused rather than saved; the key already in
* use, run out, can stay while the modules are saved - it is just not in
* force. Empty, white-labelling is off. On a managed instance whose manager
* sets the key, the key is left as the manager set it.
*/
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
if (isset($_POST['edit_module_settings'])) {
validateCSRFToken();
$modules = ['config_module_enable_itdoc', 'config_module_enable_ticketing', 'config_module_enable_accounting', 'config_client_portal_enable'];
if (isset($config_module_enable_calendar)) {
// Database 3.9.4's five
array_push($modules, 'config_module_enable_dispatch', 'config_module_enable_bookkeeping', 'config_module_enable_purchasing', 'config_module_enable_trips', 'config_module_enable_calendar');
}
if (isset($config_module_enable_kb)) {
// Database 3.9.5's Knowledge Base
$modules[] = 'config_module_enable_kb';
}
$before = settingsCurrent(array_merge($modules, ['config_whitelabel_enabled', 'config_whitelabel_key']));
$after = [];
foreach ($modules as $module) {
$after[$module] = empty($_POST[$module]) ? 0 : 1;
}
$key = trim((string) ($_POST['config_whitelabel_key'] ?? ''));
$errors = [];
if (managedLocks()['white_label']) {
// Set by the manager of this managed instance - not this page's to change (functions/managed.php)
} elseif ($key === '') {
$after['config_whitelabel_key'] = '';
$after['config_whitelabel_enabled'] = 0;
} elseif (validateWhitelabelKey($key)) {
$after['config_whitelabel_key'] = $key;
$after['config_whitelabel_enabled'] = 1;
} elseif ($key === (string) $before['config_whitelabel_key']) {
// The one already in use, run out - kept, not in force
$after['config_whitelabel_enabled'] = 0;
} else {
$errors['config_whitelabel_key'] = 'That isn\'t a white-label key, or it has run out.';
}
if ($errors) {
settingsRefuse('module', $errors);
}
settingsSave('module', $before, $after);
redirect();
}