2019-08-23 11:39:42 +00:00
|
|
|
<?php
|
|
|
|
if (isset($_POST) && !empty($_POST)){
|
2019-10-13 08:07:03 +00:00
|
|
|
if (isset($_POST['modalFinal']) && $_POST['action'] == "add") {
|
2019-08-24 11:07:07 +00:00
|
|
|
$doCode = json_encode($_POST['device'], JSON_PRETTY_PRINT);
|
2020-02-21 13:01:39 +00:00
|
|
|
|
|
|
|
$value = $_POST['atSelector'];
|
|
|
|
if ($_POST['atSelector'] == 'time'){
|
|
|
|
$value = $_POST['atSelectorValue'];
|
|
|
|
} else if ($_POST['atSelector'] == 'atDeviceValue') {
|
|
|
|
$value = json_decode($_POST['atSelectorValue']);
|
|
|
|
} else if ($_POST['atSelector'] == 'inHome' || $_POST['atSelector'] == 'outHome') {
|
|
|
|
$value = UserManager::getUserData('user_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-24 11:07:07 +00:00
|
|
|
$ifCode = json_encode([
|
|
|
|
"type" => $_POST['atSelector'],
|
2020-02-21 13:01:39 +00:00
|
|
|
"value" => $value,
|
2019-08-24 11:07:07 +00:00
|
|
|
], JSON_PRETTY_PRINT);
|
2019-08-23 11:39:42 +00:00
|
|
|
$onDays = $_POST['atDays'];
|
|
|
|
|
2019-10-13 08:07:03 +00:00
|
|
|
//Debug
|
2020-02-18 20:30:44 +00:00
|
|
|
// if (DEBUGMOD == 1) {
|
|
|
|
// echo '<pre>';
|
|
|
|
// echo $permissionsInJson;
|
|
|
|
// echo $deviceId;
|
|
|
|
// var_dump(json_decode ($permissionsInJson));
|
|
|
|
// echo '</pre>';
|
|
|
|
// echo '<a href="' . BASEDIR .'">CONTINUE</a>';
|
|
|
|
// die();
|
|
|
|
// }
|
2019-10-13 08:07:03 +00:00
|
|
|
|
2019-10-08 16:23:57 +00:00
|
|
|
AutomationManager::create($_POST['name'], $onDays, $doCode, $ifCode);
|
2019-08-23 11:39:42 +00:00
|
|
|
|
2020-04-28 09:52:14 +00:00
|
|
|
header('Location: ' . BASEURL . strtolower(basename(__FILE__, '.php')));
|
2019-09-19 18:05:32 +00:00
|
|
|
die();
|
2019-10-13 08:07:03 +00:00
|
|
|
} else if (isset($_POST['modalFinal']) && $_POST['action'] == "edit") {
|
2019-09-19 18:05:32 +00:00
|
|
|
$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']);
|
|
|
|
|
2020-02-21 13:01:39 +00:00
|
|
|
$device = [
|
2019-10-13 08:07:03 +00:00
|
|
|
'deviceID' => $subDeviceMaster['device_id'],
|
|
|
|
'type'=> $subDevice['type'],
|
|
|
|
'value'=> $subDeviceValue,
|
2020-02-21 13:01:39 +00:00
|
|
|
];
|
2019-09-19 18:05:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-21 13:01:39 +00:00
|
|
|
$value = $_POST['atSelector'];
|
|
|
|
if (isset($_POST['atTime'])){
|
|
|
|
$value = $_POST['atTime'];
|
|
|
|
} else if (isset($_POST['atDeviceValue'])) {
|
|
|
|
$value = $device;
|
|
|
|
} else if ($_POST['atSelector'] == 'inHome' || $_POST['atSelector'] == 'outHome') {
|
|
|
|
//TODO: opravit edit aby vkládal id původního uživatele
|
|
|
|
$value = UserManager::getUserData('user_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
$value = (isset($_POST['atTime']) ? $_POST['atTime'] : (isset($_POST['atDeviceValue']) ? $device : $_POST['atSelector']));
|
2019-09-19 18:05:32 +00:00
|
|
|
$ifCode = json_encode([
|
|
|
|
"type" => $_POST['atSelector'],
|
2020-02-21 13:01:39 +00:00
|
|
|
"value" => $value,
|
2019-09-19 18:05:32 +00:00
|
|
|
], 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
|
|
|
|
2020-04-28 09:52:14 +00:00
|
|
|
header('Location: ' . BASEURL . strtolower(basename(__FILE__, '.php')));
|
2019-08-23 12:30:46 +00:00
|
|
|
die();
|
|
|
|
}
|
2019-08-23 11:39:42 +00:00
|
|
|
}
|
|
|
|
?>
|