2024-08-12 11:12:24 +00:00
|
|
|
<?php
|
|
|
|
|
2024-08-18 19:12:45 +00:00
|
|
|
$action = $_REQUEST['action'] ?? '';
|
|
|
|
|
2024-08-19 10:25:09 +00:00
|
|
|
// if a form is submitted, it's from the edit page
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
2024-08-18 19:12:45 +00:00
|
|
|
|
2024-08-19 10:25:09 +00:00
|
|
|
// load the config file and initialize a copy
|
|
|
|
$content = file_get_contents($config_file);
|
|
|
|
$updatedContent = $content;
|
2024-08-18 19:12:45 +00:00
|
|
|
|
2024-08-19 10:25:09 +00:00
|
|
|
foreach ($_POST as $key => $value) {
|
|
|
|
|
|
|
|
$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');
|
|
|
|
}
|
2024-08-18 19:12:45 +00:00
|
|
|
}
|
2024-08-12 11:12:24 +00:00
|
|
|
|
|
|
|
?>
|