Adds config file edit page

main
Yasen Pramatarov 2024-10-29 13:38:22 +02:00
parent 20c36f9d02
commit 82962e0449
3 changed files with 74 additions and 3 deletions

View File

@ -36,4 +36,48 @@ function renderConfig($configPart, $indent, $platform=false, $parent='') {
</div> </div>
<?php <?php
} }
// render config variables array
function editConfig($configPart, $indent, $platform=false, $parent='') {
global $app_root;
global $config;
?>
<div style="padding-left: <?= $indent ?>px; padding-bottom: 20px;">
<?php foreach ($configPart as $config_item => $config_value) { ?>
<div class="row mb-1" style="padding-left: <?= $indent ?>px;">
<div class="col-md-4 text-end">
<?= htmlspecialchars($config_item) ?>:
<label for="<?= htmlspecialchars($config_item) ?>" class="form-label"><?= htmlspecialchars($config_item) ?></label>
<span class="text-danger" style="margin-right: -12px;">*</span>
</div>
<?php
if (is_array($config_value)) {
// here we render recursively nested arrays
$indent = $indent + 50;
if ($parent === 'platforms') {
$indent = 100;
}
if ($config_item === 'platforms') {
editConfig($config_value, $indent, $platform, 'platforms');
} else {
editConfig($config_value, $indent, $platform);
}
$indent = 0;
} else {
// if it's not array, just display it
?>
<div class="border col-md-8 text-start">
<?= htmlspecialchars($config_value ?? '')?>
<input class="form-control" type="text" name="<?= htmlspecialchars($config_value) ?>" value="<?= htmlspecialchars($config_value ?? '') ?>" required autofocus />
</div>
<?php } ?>
</div>
<?php } ?>
</div>
<?php
}
?> ?>

View File

@ -129,10 +129,14 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
include '../app/templates/config-list-interfaceconfigjs.php'; include '../app/templates/config-list-interfaceconfigjs.php';
break; break;
case 'config_file': case 'config_file':
if ($userObject->hasRight($user_id, 'view config file')) { if (isset($action) && $action === 'edit') {
include '../app/templates/config-configfile.php'; include '../app/templates/config-configfile-edit.php';
} else { } else {
include '../app/templates/error-unauthorized.php'; if ($userObject->hasRight($user_id, 'view config file')) {
include '../app/templates/config-configfile.php';
} else {
include '../app/templates/error-unauthorized.php';
}
} }
break; break;

View File

@ -0,0 +1,23 @@
<!-- widget "config" -->
<div class="card text-center w-75 mx-lef">
<p class="h4 card-header">Jilo configuration file</p>
<div class="card-body">
<p class="card-text">edit the Jilo Server configuration file:</p>
<form method="POST" action="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=config&item=config_file">
<?php
include '../app/helpers/render.php';
editConfig($config, '0');
echo "\n";
?>
<br />
<a class="btn btn-secondary" href="<?= htmlspecialchars($app_root) ?>?page=config#platform<?= htmlspecialchars($platform_id) ?>" />Cancel</a>
<input type="submit" class="btn btn-primary" value="Save" />
</form>
</div>
</div>
<!-- /widget "config" -->