add edit to automatization

This commit is contained in:
unknown 2019-09-19 20:05:32 +02:00
parent e2be9e57ee
commit 03ea63e839
3 changed files with 45 additions and 9 deletions

View File

@ -13,7 +13,7 @@ class AutomationManager{
return Db::command ('UPDATE automation SET active = ? WHERE automation_id=?', array ($flipedValue,$automationId));
}
public function create ($name, $onDays, $doCode, $ifCode) {
public function create ($name, $onDays, $doCode, $ifCode, $automationId = "") {
$scene = array (
'name' => $name,
'on_days' => $onDays,
@ -21,7 +21,11 @@ class AutomationManager{
'do_something' => $doCode,
);
try {
if ($automationId == "") {
Db::add ('automation', $scene);
} else {
Db::edit ('automation', $scene, 'WHERE automation_id = ?', array ($automationId));
}
} catch(PDOException $error) {
echo $error->getMessage();
die();

View File

@ -10,6 +10,34 @@ if (isset($_POST) && !empty($_POST)){
AutomationManager::create('name', $onDays, $doCode, $ifCode);
header('Location: /vasek/home/' . strtolower(basename(__FILE__, '.php')), TRUE);
die();
} else if (isset($_POST['modalFinal']) && $_POST['modalFinal'] == "Upravit") {
$doCode = json_encode($_POST['device'], JSON_PRETTY_PRINT);
if (isset ($_POST['atDeviceValue'])) {
$subDeviceId = $_POST['atDeviceValue'];
$subDeviceValue = $_POST['atDeviceValueInt'];
$subDevice = SubDeviceManager::getSubDevice($subDeviceId);
$subDeviceMaster = SubDeviceManager::getSubDeviceMaster($subDeviceId,$subDevice['type']);
$json = json_encode([
'deviceID' => $subDeviceMaster['device_id'],
'type'=> htmlspecialchars($subDevice['type']),
'value'=> $subDeviceValue,
]);
}
$_POST['atSelectorValue'] = (isset($_POST['atTime']) ? $_POST['atTime'] : (isset($_POST['atDeviceValue']) ? $json : $_POST['atSelector']));
$ifCode = json_encode([
"type" => $_POST['atSelector'],
"value" => $_POST['atSelectorValue'],
], JSON_PRETTY_PRINT);
$onDays = ($_POST['day'] != '' ? json_encode($_POST['day']) : '');
AutomationManager::create('name', $onDays, $doCode, $ifCode, (isset ($_POST['automation_id']) ? $_POST['automation_id'] : ""));
header('Location: /vasek/home/' . strtolower(basename(__FILE__, '.php')), TRUE);
die();
}

View File

@ -5,17 +5,21 @@
</div>
<h4 class="mb-4"><?php echo $LANG['t_createAutomation']?></h4>
<form method="post">
<input name="automation_id" type="hidden" value="<?php echo $AUTOMATIONID; ?>">
<div class="field">
<div class="label"><?php echo $LANG['l_runAt']?></div>
<div class="field">
<?php //TODO Dodělat identifikaci pro Selctor události a selector času zařízení hodnoty ?>
<select class="input" name="atSelector" id="valueSelector" required>
<option value="sunSet" <?php ECHO ($AUTOMATION['ifSomething'] == "sunSet" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_sunSet']?></option>
<option value="sunRise" <?php ECHO ($AUTOMATION['ifSomething'] == "sunRise" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_sunRice']?></option>
<option value="inHome" <?php ECHO ($AUTOMATION['ifSomething'] == "inHome" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_inHome']?></option>
<option value="outHome" <?php ECHO ($AUTOMATION['ifSomething'] == "outHome" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_outHome']?></option>
<option value="time" <?php ECHO ($AUTOMATION['ifSomething'] == "time" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_time']?></option>
<option value="atDeviceValue" <?php ECHO ($AUTOMATION['ifSomething'] == "atDeviceValue" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_deviceValue']?></option>
<option value="sunSet" <?php ECHO (json_decode($AUTOMATION['ifSomething'], true)['type'] == "sunSet" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_sunSet']?></option>
<option value="sunRise" <?php ECHO (json_decode($AUTOMATION['ifSomething'], true)['type'] == "sunRise" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_sunRice']?></option>
<option value="inHome" <?php ECHO (json_decode($AUTOMATION['ifSomething'], true)['type'] == "inHome" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_inHome']?></option>
<option value="outHome" <?php ECHO (json_decode($AUTOMATION['ifSomething'], true)['type'] == "outHome" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_outHome']?></option>
<option value="time" <?php ECHO (json_decode($AUTOMATION['ifSomething'], true)['type'] == "time" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_time']?></option>
<option value="noOneHome" <?php ECHO (json_decode($AUTOMATION['ifSomething'], true)['type'] == "noOneHome" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_time']?></option>
<option value="atDeviceValue" <?php ECHO (json_decode($AUTOMATION['ifSomething'], true)['type'] == "atDeviceValue" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_deviceValue'];?></option>
<option value="noOneHome" <?php ECHO (json_decode($AUTOMATION['ifSomething'], true)['type'] == "noOneHome" ? 'selected="selected"' : ''); ?>><?php echo $LANG['w_noOne'] . ' ' . $LANG['w_neni'] . ' ' . $LANG['w_home'];?></option>
<option value="someOneHome" <?php ECHO (json_decode($AUTOMATION['ifSomething'], true)['type'] == "someOneHome" ? 'selected="selected"' : ''); ?>><?php echo $LANG['w_someOne'] . ' ' . $LANG['w_is'] . ' ' . $LANG['w_home'];?></option>
</select>
<input class="input" type="time" name="atTime" id="atTime" <?php ECHO ($AUTOMATION['ifSomething'] == "time" ? '' : 'disabled'); ?>/>
<select class="input" name="atDeviceValue" id="atDeviceValue" <?php ECHO ($AUTOMATION['ifSomething'] == "atDeviceValue" ? '' : 'disabled'); ?>>
@ -35,7 +39,7 @@
foreach($AUTOMATION['doSomething'] as $subDeviceId => $subDeviceData){ ?>
<div id="automation-<?php echo $AUTOMATIONID; ?>-content">
<div class="label"><?php echo $subDeviceData['name']; ?></div>
<select class="input" name="devices[<?php echo $subDeviceId; ?>]">
<select class="input" name="device[<?php echo $subDeviceId; ?>]">
<option value="0" <?php echo ($subDeviceData['state'] == "0" ? 'selected="selected"' : ''); ?>>off</option>
<option value="1" <?php echo ($subDeviceData['state'] == "1" ? 'selected="selected"' : ''); ?>>on</option>
</select>