Fixes boolean fields in conf editing

main
Yasen Pramatarov 2024-11-01 20:01:43 +02:00
parent 5220ab7fcd
commit e90f4ca020
2 changed files with 11 additions and 2 deletions

View File

@ -17,8 +17,16 @@ class Config {
// value is without quotes, because it could be true/false
$pattern = "/(['\"]{$key}['\"]\s*=>\s*)([^,]+),/";
// prepare the value and replace it
// prepare the value, treating booleans as 'true' or 'false'
if ($newValue === 1) {
$replacementValue = 'true';
} elseif ($newValue === 0) {
$replacementValue = 'false';
} else {
$replacementValue = var_export($newValue, true);
}
// value replacing
$config_contents = preg_replace($pattern, "$1{$replacementValue},", $config_contents);
}

View File

@ -57,6 +57,7 @@ function editConfig($configPart, $indent, $platform=false, $parent='') {
?>
<div class="col-md-8 text-start">
<?php if ($config_item === 'registration_enabled') { ?>
<input type="hidden" name="<?= htmlspecialchars($config_item) ?>" value="0" />
<input class="form-check-input" type="checkbox" role="switch" name="<?= htmlspecialchars($config_item) ?>" value="<?= htmlspecialchars($config_value ?? 0) ?>" <?= ($config_value === 1 || $config_value === true) ? 'checked' : '' ?> />
<?php } elseif ($config_item === 'environment') { ?>
<select class="form-control" type="text" name="<?= htmlspecialchars($config_item) ?>">