Cleanup unused parameters when saving configuration files

This commit is contained in:
bergware
2017-03-25 14:58:15 +01:00
parent 4d5f103312
commit cf20be4a74
4 changed files with 28 additions and 14 deletions
+6 -5
View File
@@ -1,6 +1,6 @@
<?PHP
/* Copyright 2005-2016, Lime Technology
* Copyright 2012-2016, Bergware International.
/* Copyright 2005-2017, Lime Technology
* Copyright 2012-2017, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
@@ -20,8 +20,9 @@ foreach ($_POST as $field => $value) {
$keys[$section][$key] = $value;
}
foreach ($keys as $section => $block) {
$text .= "[$section]\n";
foreach ($block as $key => $value) $text .= "$key=\"$value\"\n";
$pairs = "";
foreach ($block as $key => $value) if (strlen($value) && $value != -1) $pairs .= "$key=\"$value\"\n";
if ($pairs) $text .= "[$section]\n".$pairs;
}
file_put_contents($_POST['#cfg'], $text);
if ($text) file_put_contents($_POST['#cfg'], $text); else @unlink($_POST['#cfg']);
?>