Fixes adding, editing and deleting a platform
parent
1ba32d86f7
commit
666f3ca98b
|
@ -37,9 +37,8 @@ return [
|
|||
|
||||
'platforms' => [
|
||||
'0' => [
|
||||
'name' => 'meet.example.com',
|
||||
// database with logs from Jilo
|
||||
'jilo_database' => '../../jilo/jilo.db',
|
||||
'name' => 'meet.example.com',
|
||||
'jilo_database' => '../../jilo/jilo.db',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
// Function to format arrays with square brackets
|
||||
function formatArray(array $array, $indentLevel = 2) {
|
||||
$indent = str_repeat(' ', $indentLevel); // 4 spaces per indent level
|
||||
$output = "[\n";
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
$output .= $indent . "'" . $key . "'" . ' => ';
|
||||
|
||||
if (is_array($value)) {
|
||||
$output .= formatArray($value, $indentLevel + 1);
|
||||
} else {
|
||||
$output .= var_export($value, true);
|
||||
}
|
||||
|
||||
$output .= ",\n";
|
||||
}
|
||||
|
||||
$output .= str_repeat(' ', $indentLevel - 1) . ']';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,29 +1,36 @@
|
|||
<?php
|
||||
|
||||
// render config variables array
|
||||
function renderConfig($config, $indent, $platform=false) {
|
||||
function renderConfig($configPart, $indent, $platform=false, $parent='') {
|
||||
global $app_root;
|
||||
if (isset($platform) && $platform === true) {
|
||||
global $config;
|
||||
if ($parent === 'platforms') {
|
||||
?>
|
||||
<div class="col-md-8 text-start">
|
||||
<a class="btn btn-secondary" style="padding: 0px;" href="<?= $app_root ?>?page=config&action=add">add</a>
|
||||
</div>
|
||||
<div class="border bg-light" style="padding-left: <?= $indent ?>px; padding-bottom: 20px; padding-top: 20px;">
|
||||
<?php } else {
|
||||
?>
|
||||
<div style="padding-left: <?= $indent ?>px; padding-bottom: 20px;">
|
||||
<?php
|
||||
}
|
||||
foreach ($config as $config_item => $config_value) {
|
||||
foreach ($configPart as $config_item => $config_value) {
|
||||
if ($parent === 'platforms') {
|
||||
$indent = 0;
|
||||
}
|
||||
?>
|
||||
<div class="row mb-1" style="padding-left: <?= $indent ?>px;">
|
||||
<div class="col-md-4 text-end">
|
||||
<?= htmlspecialchars($config_item) ?>:
|
||||
</div>
|
||||
<?php
|
||||
if (isset($platform) && $platform === true) { ?>
|
||||
if ($parent === 'platforms') { ?>
|
||||
<div class="col-md-8 text-start">
|
||||
<a class="btn btn-secondary" style="padding: 2px;" href="<?= $app_root ?>?platform=<?= htmlspecialchars($config_item) ?>&page=config&action=edit">edit</a>
|
||||
<?php
|
||||
// we don't delete the last platform
|
||||
if (count($config) <= 1) { ?>
|
||||
if (count($configPart) <= 1) { ?>
|
||||
<span class="btn btn-light" style="padding: 2px;" href="#" data-toggle="tooltip" data-placement="right" data-offset="30.0" title="can't delete the last platform">delete</span>
|
||||
<?php } else { ?>
|
||||
<a class="btn btn-danger" style="padding: 2px;" href="<?= $app_root ?>?platform=<?= htmlspecialchars($config_item) ?>&page=config&action=delete">delete</a>
|
||||
|
@ -32,14 +39,16 @@ function renderConfig($config, $indent, $platform=false) {
|
|||
<?php }
|
||||
|
||||
if (is_array($config_value)) {
|
||||
if ($config_item === 'platforms') {
|
||||
$platform = true;
|
||||
} else {
|
||||
$platform = false;
|
||||
}
|
||||
// here we render recursively nested arrays
|
||||
$indent = $indent + 50;
|
||||
renderConfig($config_value, $indent, $platform);
|
||||
if ($parent === 'platforms') {
|
||||
$indent = 100;
|
||||
}
|
||||
if ($config_item === 'platforms') {
|
||||
renderConfig($config_value, $indent, $platform, 'platforms');
|
||||
} else {
|
||||
renderConfig($config_value, $indent, $platform);
|
||||
}
|
||||
$indent = 0;
|
||||
} else {
|
||||
// if it's not array, just display it
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
$action = $_REQUEST['action'] ?? '';
|
||||
require '../app/helpers/errors.php';
|
||||
require '../app/helpers/config.php';
|
||||
|
||||
// if a form is submitted, it's from the edit page
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
|
@ -10,16 +11,66 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|||
$content = file_get_contents($config_file);
|
||||
$updatedContent = $content;
|
||||
|
||||
foreach ($_POST as $key => $value) {
|
||||
// Create a regex pattern to match the key-value pair for the specified platform ID
|
||||
$pattern = "/((?:'[^']+'\s*=>\s*'[^']+'\s*,?\s*)*)('{$key}'\s*=>\s*)'[^']*'/s";
|
||||
// Replace using a callback to handle the match and replacement
|
||||
$updatedContent = preg_replace_callback($pattern, function($matches) use ($value) {
|
||||
return $matches[1] . $matches[2] . "'{$value}'";
|
||||
}, $updatedContent
|
||||
// new platform adding
|
||||
if (isset($_POST['new']) && $_POST['new'] === 'true') {
|
||||
$newPlatform = [
|
||||
'name' => $_POST['name'],
|
||||
'jilo_database' => $_POST['jilo_database'],
|
||||
];
|
||||
|
||||
// Determine the next available index for the new platform
|
||||
$nextIndex = count($config['platforms']);
|
||||
|
||||
// Add the new platform to the platforms array
|
||||
$config['platforms'][$nextIndex] = $newPlatform;
|
||||
|
||||
// Rebuild the PHP array syntax for the platforms
|
||||
$platformsArray = formatArray($config['platforms']);
|
||||
|
||||
// Replace the platforms section in the config file
|
||||
$updatedContent = preg_replace(
|
||||
'/\'platforms\'\s*=>\s*\[[\s\S]+?\],/s',
|
||||
"'platforms' => {$platformsArray}",
|
||||
$content
|
||||
);
|
||||
$updatedContent = preg_replace('/\s*\]\n/s', "\n", $updatedContent);
|
||||
|
||||
// deleting a platform
|
||||
} elseif (isset($_POST['delete']) && $_POST['delete'] === 'true') {
|
||||
$platform = $_POST['platform'];
|
||||
|
||||
$config['platforms'][$platform]['name'] = $_POST['name'];
|
||||
$config['platforms'][$platform]['jilo_database'] = $_POST['jilo_database'];
|
||||
|
||||
$platformsArray = formatArray($config['platforms'][$platform], 3);
|
||||
|
||||
$updatedContent = preg_replace(
|
||||
"/\s*'$platform'\s*=>\s*\[\s*'name'\s*=>\s*'[^']*',\s*'jilo_database'\s*=>\s*'[^']*',\s*\],/s",
|
||||
"",
|
||||
$content
|
||||
);
|
||||
|
||||
|
||||
// an update to an existing platform
|
||||
} else {
|
||||
|
||||
$platform = $_POST['platform'];
|
||||
|
||||
$config['platforms'][$platform]['name'] = $_POST['name'];
|
||||
$config['platforms'][$platform]['jilo_database'] = $_POST['jilo_database'];
|
||||
|
||||
$platformsArray = formatArray($config['platforms'][$platform], 3);
|
||||
|
||||
$updatedContent = preg_replace(
|
||||
"/\s*'$platform'\s*=>\s*\[\s*'name'\s*=>\s*'[^']*',\s*'jilo_database'\s*=>\s*'[^']*',\s*\],/s",
|
||||
"\n '{$platform}' => {$platformsArray},",
|
||||
$content
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// check if file is writable
|
||||
if (!is_writable($config_file)) {
|
||||
$_SESSION['error'] = getError('Configuration file is not writable.');
|
||||
|
@ -45,9 +96,15 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|||
// no form submitted, show the templates
|
||||
} else {
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
include('../app/templates/config-add-platform.php');
|
||||
break;
|
||||
case 'edit':
|
||||
include('../app/templates/config-edit-platform.php');
|
||||
break;
|
||||
case 'delete':
|
||||
include('../app/templates/config-delete-platform.php');
|
||||
break;
|
||||
default:
|
||||
include('../app/templates/config-list.php');
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
|
||||
<!-- widget "config" -->
|
||||
<div class="card text-center w-50 mx-auto">
|
||||
<p class="h4 card-header">Add new Jitsi platform</p>
|
||||
<div class="card-body">
|
||||
<!--p class="card-text">add new platform:</p-->
|
||||
<form method="POST" action="<?= $app_root ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=config">
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-4 text-end">
|
||||
<label for="name" class="form-label">name</label>
|
||||
<span class="text-danger" style="margin-right: -12px;">*</span>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<input class="form-control" type="text" name="name" value="" required />
|
||||
<p class="text-start"><small>descriptive name for the platform</small></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-4 text-end">
|
||||
<label for="name" class="form-label">jilo_database</label>
|
||||
<span class="text-danger" style="margin-right: -12px;">*</span>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<input class="form-control" type="text" name="jilo_database" value="" required />
|
||||
<p class="text-start"><small>path to the database file (relative to the app root)</small></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="new" value="true" />
|
||||
|
||||
<br />
|
||||
<a class="btn btn-secondary" href="<?= $app_root ?>?page=config" />Cancel</a>
|
||||
<input type="submit" class="btn btn-primary" value="Save" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /widget "config" -->
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
<!-- 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">delete a platform:</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>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="text-start"><?= htmlspecialchars($config_value ?? '')?></div>
|
||||
<input type="hidden" name="<?= htmlspecialchars($config_item) ?>" value="<?= htmlspecialchars($config_value ?? '')?>" />
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<br />
|
||||
<input type="hidden" name="platform" value="<?= htmlspecialchars($platform_id) ?>" />
|
||||
<input type="hidden" name="delete" value="true" />
|
||||
<p class="h5 text-danger">Are you sure you want to delete this platform?</p>
|
||||
<br />
|
||||
<a class="btn btn-secondary" href="<?= $app_root ?>?page=config" />Cancel</a>
|
||||
<input type="submit" class="btn btn-danger" value="Delete" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /widget "config" -->
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
<!-- 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>
|
||||
<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">
|
||||
|
@ -13,11 +13,17 @@
|
|||
</div>
|
||||
<div class="col-md-8">
|
||||
<input class="form-control" type="text" name="<?= htmlspecialchars($config_item) ?>" value="<?= htmlspecialchars($config_value ?? '')?>" required />
|
||||
<?php if ($config_item === 'name') { ?>
|
||||
<p class="text-start"><small>descriptive name for the platform</small></p>
|
||||
<?php } elseif ($config_item === 'jilo_database') { ?>
|
||||
<p class="text-start"><small>path to the database file (relative to the app root)</small></p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<br /> <br />
|
||||
<a class="btn btn-secondary" href="<?= $app_root ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=config" />Cancel</a>
|
||||
<br />
|
||||
<input type="hidden" name="platform" value="<?= htmlspecialchars($platform_id) ?>" />
|
||||
<a class="btn btn-secondary" href="<?= $app_root ?>?page=config" />Cancel</a>
|
||||
<input type="submit" class="btn btn-primary" value="Save" />
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -12,11 +12,13 @@
|
|||
|
||||
<?php if ( isset($_SESSION['username']) ) { ?>
|
||||
|
||||
<?php foreach ($config['platforms'] as $index => $platform) { ?>
|
||||
<li style="margin-right: 3px;">
|
||||
<a style="background-color: #111;" href="?platform=<?= htmlspecialchars(array_keys($config['platforms'])[$platform_id]) ?>&page=front">
|
||||
<?= htmlspecialchars($config['platforms'][$platform_id]['name']) ?>
|
||||
<a style="background-color: #111;" href="?platform=<?= htmlspecialchars($index) ?>&page=front">
|
||||
<?= htmlspecialchars($platform['name']) ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
|
||||
<?php } ?>
|
||||
</ul>
|
||||
|
|
Loading…
Reference in New Issue