Adds platform editing code

main
Yasen Pramatarov 2024-08-19 13:25:09 +03:00
parent 3abafe2de7
commit 1cda74cd50
6 changed files with 104 additions and 25 deletions

View File

@ -1,23 +1,37 @@
<?php <?php
// render config variables array // render config variables array
function renderConfig($config) { function renderConfig($config, $indent) {
echo "\n\t\t\t\t\t<ul>"; ?>
<div style="padding-left: <?= $indent ?>px; padding-bottom: 20px;">
<?php
foreach ($config as $config_item => $config_value) { foreach ($config as $config_item => $config_value) {
echo "\n\t\t\t\t\t\t<li>"; ?>
echo htmlspecialchars($config_item) . ': '; <div class="row mb-1" style="padding-left: <?= $indent ?>px;">
<div class="col-md-4 text-end">
<?= htmlspecialchars($config_item) ?>:
</div>
<?php
if (is_array($config_value)) { if (is_array($config_value)) {
?>
<?php
// here we render recursively nested arrays // here we render recursively nested arrays
renderConfig($config_value); $indent = $indent + 50;
renderConfig($config_value, $indent);
$indent = 0;
} else { } else {
// if it's not array, just display it // if it's not array, just display it
echo htmlspecialchars($config_value ?? ''); ?>
<div class="border col-md-8 text-start">
<?= htmlspecialchars($config_value ?? '')?>
</div>
<?php
} }
?>
echo '</li>'; </div>
<?php
} }
echo "\n\t\t\t\t\t</ul>"; echo '</div>';
} }
?> ?>

View File

@ -2,14 +2,45 @@
$action = $_REQUEST['action'] ?? ''; $action = $_REQUEST['action'] ?? '';
switch ($action) { // if a form is submitted, it's from the edit page
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
case 'edit': // load the config file and initialize a copy
include('../app/templates/config-edit-platform.php'); $content = file_get_contents($config_file);
break; $updatedContent = $content;
default: foreach ($_POST as $key => $value) {
include('../app/templates/config-list.php');
$config['platforms'][$platform_id][$key] = $value;
// search pattern for the old value
$oldValue = "/('$platform_id'\s*=>\s*\[\s*'$key'\s*=>\s*)'[^']*'/";
// new value
$newValue = "$1'$value'";
$updatedContent = preg_replace($oldValue, $newValue, $updatedContent);
}
if (file_put_contents($config_file, $updatedContent) !== false) {
// update successful
$_SESSION['notice'] = "Configuration for {$_POST['name']} is updated.";
} else {
// unsuccessful
$_SESSION['error'] = 'Error updating the config';
}
// FIXME the new file is not loaded on first page load
unset($config);
header("Location: $app_root?platform=$platform_id&page=config");
exit();
// no form submitted, show the templates
} else {
switch ($action) {
case 'edit':
include('../app/templates/config-edit-platform.php');
break;
default:
include('../app/templates/config-list.php');
}
} }
?> ?>

View File

@ -1,4 +1,24 @@
<?php
<!-- widget "config" -->
?> <div class="card text-center w-50 mx-auto">
<p class="h4 card-header">Jilo web configuration for Jitsi platform"<?= htmlspecialchars($platform_id) ?>"</p>
<div class="card-body">
<p class="card-text">edit the platform details:</p>
<form method="POST" action="<?= $app_root ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=config">
<?php foreach ($config['platforms'][$platform_id] as $config_item => $config_value) { ?>
<div class="row mb-3">
<div class="col-md-4 text-end">
<label for="<?= htmlspecialchars($config_item) ?>" class="form-label"><?= htmlspecialchars($config_item) ?></label>
<span class="text-danger" style="margin-right: -12px;">*</span>
</div>
<div class="col-md-8">
<input class="form-control" type="text" name="<?= htmlspecialchars($config_item) ?>" value="<?= htmlspecialchars($config_value ?? '')?>" required />
</div>
</div>
<?php } ?>
<br />&nbsp;<br />
<input type="submit" class="btn btn-primary" value="Save" />
</form>
</div>
</div>
<!-- /widget "config" -->

View File

@ -1,11 +1,14 @@
<!-- widget "config" --> <!-- widget "config" -->
<div> <div class="card text-center w-50 mx-lef">
<p>Jilo web configuration</p> <p class="h4 card-header">Jilo web configuration</p>
<div class="card-body">
<p class="card-text">platform variables</p>
<?php <?php
include '../app/helpers/render.php'; include '../app/helpers/render.php';
renderConfig($config); renderConfig($config, '0');
echo "\n"; echo "\n";
?> ?>
</div>
</div> </div>
<!-- /widget "config" --> <!-- /widget "config" -->

View File

@ -16,10 +16,14 @@
<li><a href="?page=participants">participants</a></li> <li><a href="?page=participants">participants</a></li>
<li><a href="?page=components">components</a></li--> <li><a href="?page=components">components</a></li-->
<li style="margin-right: 0px;"><a style="background-color: #111;" href="?platform=0&page=front">meet.example.com</a></li> <li style="margin-right: 0px;">
<a style="background-color: #111;" href="?platform=<?= htmlspecialchars(array_keys($config['platforms'])[$platform_id]) ?>&page=front">
<?= htmlspecialchars($config['platforms'][$platform_id]['name']) ?>
</a>
</li>
<li style="margin: 0px; padding: 0px;"> <li style="margin: 0px; padding: 0px;">
<a style="background-color: #555; padding-left: 3px; padding-right: 3px;" href="?platform=0&page=config&action=edit"> <a style="background-color: #555; padding-left: 3px; padding-right: 3px;" href="?platform=<?= htmlspecialchars(array_keys($config['platforms'])[$platform_id]) ?>&page=config&action=edit">
<i class="fas fa-wrench" data-toggle="tooltip" data-placement="right" data-offset="30.0" title="configure platform &quot;meet.example.com&quot;"></i> <i class="fas fa-wrench" data-toggle="tooltip" data-placement="right" data-offset="30.0" title="configure platform &quot;<?= htmlspecialchars($config['platforms'][$platform_id]['name']) ?>&quot;"></i>
</a> </a>
</li> </li>

View File

@ -11,6 +11,10 @@
* Version: 0.1.1 * Version: 0.1.1
*/ */
// we start output buffering and.
// flush it later only when there is no redirect
ob_start();
// error reporting, comment out in production // error reporting, comment out in production
ini_set('display_errors', 1); ini_set('display_errors', 1);
ini_set('display_startup_errors', 1); ini_set('display_startup_errors', 1);
@ -130,6 +134,9 @@ if (in_array($page, $allowed_urls)) {
} }
include '../app/templates/page-footer.php'; include '../app/templates/page-footer.php';
// flush the output buffer and show the page
ob_end_flush();
// clear errors and notices before next page just in case // clear errors and notices before next page just in case
unset($_SESSION['error']); unset($_SESSION['error']);
unset($_SESSION['notice']); unset($_SESSION['notice']);