Settings Save Mechanism an few fixes

This commit is contained in:
Václav Španinger 2020-12-23 15:57:12 +01:00
parent 464f229a16
commit daa0e0a2c5
4 changed files with 38 additions and 17 deletions

View File

@ -28,6 +28,17 @@ if (isset($_POST) && !empty($_POST)){
die();
} else if (isset ($_POST['userPermission']) && !empty ($_POST['userID'])) {
$userManager->setUserDataAdmin("permission", $_POST['userPermission'], $_POST['userID']);
header('Location: ' . BASEURL . 'setting');
die();
} else {
foreach ($_POST as $key => $value) {
if ($key == 'submit') continue;
$settingMng = new SettingsManager();
if ($settingMng->getByName($key)) {
$settingMng->update($key, $value);
}
}
header('Location: ' . BASEURL . 'setting');
die();
}

View File

@ -14,6 +14,7 @@ class SettingsManager{
}
public static function create ($name, $value, $type = '') {
if (!self::getByName($name)){
$setting = array (
'name' => $name,
'value' => $value,
@ -26,9 +27,10 @@ class SettingsManager{
die();
}
}
}
public static function update ($name, $value, $type = '') {
if (self::getByName($name)){
if (!self::getByName($name)){
self::create($name, $value, $type);
} else {
try {

View File

@ -9,6 +9,14 @@ class AirQuality extends VirtualDeviceManager
function make()
{
//Register the settings
$settingMng = new SettingsManager();
if (!($settingField = $settingMng->getByName("airquality"))) {
$settingMng->create("token", "", "airquality");
} else {
$app_id = $settingField['value'];
}
try {
if (DeviceManager::registeret($this->virtual_device_name)) {
$deviceId = DeviceManager::getDeviceByToken($this->virtual_device_name)['device_id'];

View File

@ -210,7 +210,7 @@ $partial = new Partial('head');
<?php foreach ($pluginSeting['settings'] as $key => $pluginSetingField) { ?>
<div class="field">
<div class="label"><?php echo $pluginSetingField['name'] ?>:</div>
<input type="text" class="input" name="roomName" value="<?php echo $pluginSetingField['value'] ?>">
<input type="text" class="input" name="<?php echo $pluginSetingField['name'] ?>" value="<?php echo $pluginSetingField['value'] ?>">
</div>
<?php } ?>
<div class="field">