From 03ea63e839caf69d0ebadfb5bc381a35a4599386 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 19 Sep 2019 20:05:32 +0200 Subject: [PATCH] add edit to automatization --- app/class/AutomationManager.php | 8 +++++-- app/controls/automation.php | 28 +++++++++++++++++++++++++ app/templates/part/automationEdit.phtml | 18 +++++++++------- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/app/class/AutomationManager.php b/app/class/AutomationManager.php index ce3bbcd..6a64924 100644 --- a/app/class/AutomationManager.php +++ b/app/class/AutomationManager.php @@ -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 { - Db::add ('automation', $scene); + if ($automationId == "") { + Db::add ('automation', $scene); + } else { + Db::edit ('automation', $scene, 'WHERE automation_id = ?', array ($automationId)); + } } catch(PDOException $error) { echo $error->getMessage(); die(); diff --git a/app/controls/automation.php b/app/controls/automation.php index 08bc32f..94432bb 100644 --- a/app/controls/automation.php +++ b/app/controls/automation.php @@ -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(); } diff --git a/app/templates/part/automationEdit.phtml b/app/templates/part/automationEdit.phtml index be57a32..615380c 100644 --- a/app/templates/part/automationEdit.phtml +++ b/app/templates/part/automationEdit.phtml @@ -5,17 +5,21 @@

+
/> +