add edit to automatization
This commit is contained in:
parent
e2be9e57ee
commit
03ea63e839
@ -13,7 +13,7 @@ class AutomationManager{
|
|||||||
return Db::command ('UPDATE automation SET active = ? WHERE automation_id=?', array ($flipedValue,$automationId));
|
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 (
|
$scene = array (
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'on_days' => $onDays,
|
'on_days' => $onDays,
|
||||||
@ -21,7 +21,11 @@ class AutomationManager{
|
|||||||
'do_something' => $doCode,
|
'do_something' => $doCode,
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
|
if ($automationId == "") {
|
||||||
Db::add ('automation', $scene);
|
Db::add ('automation', $scene);
|
||||||
|
} else {
|
||||||
|
Db::edit ('automation', $scene, 'WHERE automation_id = ?', array ($automationId));
|
||||||
|
}
|
||||||
} catch(PDOException $error) {
|
} catch(PDOException $error) {
|
||||||
echo $error->getMessage();
|
echo $error->getMessage();
|
||||||
die();
|
die();
|
||||||
|
@ -10,6 +10,34 @@ if (isset($_POST) && !empty($_POST)){
|
|||||||
|
|
||||||
AutomationManager::create('name', $onDays, $doCode, $ifCode);
|
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);
|
header('Location: /vasek/home/' . strtolower(basename(__FILE__, '.php')), TRUE);
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
@ -5,17 +5,21 @@
|
|||||||
</div>
|
</div>
|
||||||
<h4 class="mb-4"><?php echo $LANG['t_createAutomation']?></h4>
|
<h4 class="mb-4"><?php echo $LANG['t_createAutomation']?></h4>
|
||||||
<form method="post">
|
<form method="post">
|
||||||
|
<input name="automation_id" type="hidden" value="<?php echo $AUTOMATIONID; ?>">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="label"><?php echo $LANG['l_runAt']?></div>
|
<div class="label"><?php echo $LANG['l_runAt']?></div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<?php //TODO Dodělat identifikaci pro Selctor události a selector času zařízení hodnoty ?>
|
<?php //TODO Dodělat identifikaci pro Selctor události a selector času zařízení hodnoty ?>
|
||||||
<select class="input" name="atSelector" id="valueSelector" required>
|
<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="sunSet" <?php ECHO (json_decode($AUTOMATION['ifSomething'], true)['type'] == "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="sunRise" <?php ECHO (json_decode($AUTOMATION['ifSomething'], true)['type'] == "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="inHome" <?php ECHO (json_decode($AUTOMATION['ifSomething'], true)['type'] == "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="outHome" <?php ECHO (json_decode($AUTOMATION['ifSomething'], true)['type'] == "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="time" <?php ECHO (json_decode($AUTOMATION['ifSomething'], true)['type'] == "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="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>
|
</select>
|
||||||
<input class="input" type="time" name="atTime" id="atTime" <?php ECHO ($AUTOMATION['ifSomething'] == "time" ? '' : 'disabled'); ?>/>
|
<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'); ?>>
|
<select class="input" name="atDeviceValue" id="atDeviceValue" <?php ECHO ($AUTOMATION['ifSomething'] == "atDeviceValue" ? '' : 'disabled'); ?>>
|
||||||
@ -35,7 +39,7 @@
|
|||||||
foreach($AUTOMATION['doSomething'] as $subDeviceId => $subDeviceData){ ?>
|
foreach($AUTOMATION['doSomething'] as $subDeviceId => $subDeviceData){ ?>
|
||||||
<div id="automation-<?php echo $AUTOMATIONID; ?>-content">
|
<div id="automation-<?php echo $AUTOMATIONID; ?>-content">
|
||||||
<div class="label"><?php echo $subDeviceData['name']; ?></div>
|
<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="0" <?php echo ($subDeviceData['state'] == "0" ? 'selected="selected"' : ''); ?>>off</option>
|
||||||
<option value="1" <?php echo ($subDeviceData['state'] == "1" ? 'selected="selected"' : ''); ?>>on</option>
|
<option value="1" <?php echo ($subDeviceData['state'] == "1" ? 'selected="selected"' : ''); ?>>on</option>
|
||||||
</select>
|
</select>
|
||||||
|
Loading…
Reference in New Issue
Block a user