164 lines
4.5 KiB
PHP
164 lines
4.5 KiB
PHP
<?php
|
|
global $c;
|
|
|
|
UserAuth::require("is_admin");
|
|
|
|
$varUser = UserAuth::getUser();
|
|
$varRows = Settings::get();
|
|
|
|
$strInput = file_get_contents("php://input");
|
|
|
|
if (strlen($strInput) > 0)
|
|
{
|
|
$a = json_decode($strInput, true);
|
|
$output = [];
|
|
|
|
foreach ($a as $r)
|
|
{
|
|
$strSetting = $r["setting"];
|
|
$strValue = $r["value"];
|
|
Settings::set($strSetting, $strValue);
|
|
}
|
|
|
|
Respond::json(["message" => "success", "output" => $output]);
|
|
}
|
|
?>
|
|
|
|
<div class="navbar navbar-expand bg-body-tertiary d-flex px-3 sticky-top">
|
|
|
|
<div class="container justify-content-between">
|
|
<div class="navbar-nav d-inline-flex">
|
|
<span class="navbar-brand">Options</span>
|
|
<a class="btn btn-outline-success" onclick="fnSave();"><i class="fa fa-fw fa-save"></i> Save</a>
|
|
</div>
|
|
|
|
<div class="navbar-nav d-inline-flex">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<style>
|
|
/* https://github.com/twbs/bootstrap/issues/37184 */
|
|
.dropdown-menu {
|
|
z-index: 1040 !important;
|
|
}
|
|
|
|
/*
|
|
th:first-child,
|
|
th:last-child {
|
|
width: 7.5%;
|
|
background: #F00 !important;
|
|
}*/
|
|
|
|
.w-1 { width: 1%; }
|
|
|
|
.table-responsive {
|
|
overflow-x: scroll;
|
|
}
|
|
|
|
.w-input {
|
|
width: 15em !important;
|
|
}
|
|
|
|
tr td:first-child input[type="text"]
|
|
{
|
|
width: 5em !important;
|
|
}
|
|
</style>
|
|
|
|
|
|
<div class="container">
|
|
<div class="row my-5">
|
|
<div class="col-lg-12">
|
|
<?php if (count($varRows) > 0): ?>
|
|
<div class="table-responsive">
|
|
<table class="table table-borderless">
|
|
<thead>
|
|
<tr>
|
|
<th>Setting</th>
|
|
<th>Value<th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody>
|
|
<?php foreach ($varRows as $k => $v): ?>
|
|
<tr>
|
|
<td>
|
|
<div class="input-group">
|
|
<input type="text" class="form-control w-input" name="setting" value="<?= $k; ?>" />
|
|
</div>
|
|
</td>
|
|
|
|
<td>
|
|
<?php
|
|
$strClass = "";
|
|
if (preg_match("/\n/", $v))
|
|
$strClass = "disabled readonly";
|
|
?>
|
|
|
|
<div class="input-group">
|
|
<input type="text" class="form-control w-input <?= $strClass; ?>" name="value" value="<?= $v; ?>" <?= $strClass; ?> />
|
|
</div>
|
|
|
|
<div>
|
|
<small>
|
|
<a class="link-underline link-underline-opacity-0" href="/edit/setting/<?= $k; ?>">Edit in multi-line editor</a>
|
|
</small>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
$(function() {
|
|
$("[name='setting']").each(function(i, x) {
|
|
x = $(x);
|
|
x.attr("readonly", 1);
|
|
});
|
|
|
|
fnSerialize = function() {
|
|
var a = [];
|
|
$("table tbody tr").each(function(i, x) {
|
|
x = $(x);
|
|
|
|
var valueInput = x.find("[name='value']").first();
|
|
var o = {};
|
|
|
|
o["setting"] = x.find("[name='setting']").first().val().trim();
|
|
o["value"] = valueInput.val();
|
|
|
|
if (valueInput.attr("disabled"))
|
|
return;
|
|
|
|
a.push(o);
|
|
});
|
|
|
|
console.log(a);
|
|
return a;
|
|
};
|
|
|
|
fnSave = function()
|
|
{
|
|
var data = fnSerialize();
|
|
|
|
$.ajax({
|
|
url: "",
|
|
method: "post",
|
|
data: JSON.stringify(data),
|
|
success: function(r)
|
|
{
|
|
console.log(r);
|
|
window.location.href = window.location.href;
|
|
}
|
|
});
|
|
};
|
|
});
|
|
</script>
|