PHP_SMART_HOME_V3/app/controls/automation.php

46 lines
1.6 KiB
PHP
Raw Normal View History

2019-08-23 11:39:42 +00:00
<?php
if (isset($_POST) && !empty($_POST)){
if (isset($_POST['modalFinal']) && $_POST['modalFinal'] == "Next") {
2019-08-24 11:07:07 +00:00
$doCode = json_encode($_POST['device'], JSON_PRETTY_PRINT);
$ifCode = json_encode([
"type" => $_POST['atSelector'],
"value" => $_POST['atSelectorValue'],
], JSON_PRETTY_PRINT);
2019-08-23 11:39:42 +00:00
$onDays = $_POST['atDays'];
2019-10-08 16:23:57 +00:00
AutomationManager::create($_POST['name'], $onDays, $doCode, $ifCode);
2019-08-23 11:39:42 +00:00
2019-09-19 18:05:32 +00:00
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'],
2019-10-08 16:23:57 +00:00
'type'=> $subDevice['type'],
2019-09-19 18:05:32 +00:00
'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']) : '');
2019-10-08 16:23:57 +00:00
AutomationManager::create($_POST['name'], $onDays, $doCode, $ifCode, (isset ($_POST['automation_id']) ? $_POST['automation_id'] : ""));
2019-09-19 18:05:32 +00:00
2019-08-23 12:30:46 +00:00
header('Location: /vasek/home/' . strtolower(basename(__FILE__, '.php')), TRUE);
die();
}
2019-08-23 11:39:42 +00:00
}
?>