From b1e19dd64d62576950827b2545de606d0a89e927 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Sun, 25 Aug 2019 14:07:01 +0200 Subject: [PATCH 1/8] Some minor changes of Automation system --- api.php | 35 ++++++++-------- class/AutomationManager.php | 37 ++++++++++++++--- class/DB.php | 4 ++ lang/cs.php | 4 ++ lang/en.php | 4 ++ templates/dashboard.phtml | 2 +- templates/home.phtml | 6 +-- templates/js/post.js | 2 +- templates/js/script.js | 60 +++++++++++++-------------- templates/part/automationCreate.phtml | 5 ++- views/Ajax.php | 1 + views/Automation.php | 10 ++--- 12 files changed, 106 insertions(+), 64 deletions(-) diff --git a/api.php b/api.php index 7960ed7..318821e 100644 --- a/api.php +++ b/api.php @@ -14,20 +14,6 @@ foreach (["class", "views"] as $dir) { //DB Conector Db::connect (DBHOST, DBUSER, DBPASS, DBNAME); -//Filtrování IP adress -/*if (DEBUGMOD != 1) { -if (!in_array($_SERVER['REMOTE_ADDR'], HOMEIP)) { -echo json_encode(array( -'state' => 'unsuccess', -'errorMSG' => "Using API from your IP insn´t alowed!", -)); -header("HTTP/1.1 401 Unauthorized"); -exit(); -} -}*/ - - - //Read API data $json = file_get_contents('php://input'); $obj = json_decode($json, true); @@ -36,10 +22,24 @@ if (isset($obj['user']) && $obj['user'] != ''){ //user at home $user = UserManager::getUser($obj['user']); $userId = $user['user_id']; - UserManager::atHome($userId, $obj['location']); + $keyWords = ['entered', 'connected', 'connected to']; + UserManager::atHome($userId, $obj['atHome']); + echo 'ssaved'; die(); } +//Filtrování IP adress +/*if (DEBUGMOD != 1) { + if (!in_array($_SERVER['REMOTE_ADDR'], HOMEIP)) { + echo json_encode(array( + 'state' => 'unsuccess', + 'errorMSG' => "Using API from your IP insn´t alowed!", + )); + header("HTTP/1.1 401 Unauthorized"); + exit(); + } +}*/ + //automationExecution AutomationManager::executeAll(); @@ -117,7 +117,6 @@ if ($values != null || $values != "") { 'state' => 'succes', )); header("HTTP/1.1 200 OK"); - die(); } else { //Vypis //TODO: doděla uložení výpisu jinými slovy zda li byl comman vykonán @@ -145,5 +144,7 @@ if ($values != null || $values != "") { 'value' => $subDeviceLastReordValue )); header("HTTP/1.1 200 OK"); - die(); } + + Db::disconect(); + die(); diff --git a/class/AutomationManager.php b/class/AutomationManager.php index d71ec63..bb76a40 100644 --- a/class/AutomationManager.php +++ b/class/AutomationManager.php @@ -73,13 +73,40 @@ class AutomationManager{ $restart = true; } } - } + } else if ($onValue['type'] == 'outHome') { - if ($onValue == 'outHome') { + } else if ($onValue['type'] == 'inHome') { - } - - if ($onValue == 'inHome') { + } else if ($onValue['type'] == 'noOneHome') { + $users = UserManager::getUsers(); + $membersHome = 0; + foreach ($users as $key => $user) { + if ($user['at_home'] == 'true'){ + $membersHome++; + } + } + if ($membersHome == 0 && $automation['executed'] == 0) { + $run = true; + } else if ($membersHome > 0 && $automation['executed'] == 1){ + $restart = true; + } + } else if ($onValue['type'] == 'someOneHome') { + $users = UserManager::getUsers(); + $membersHome = 0; + foreach ($users as $key => $user) { + if ($user['at_home'] == 'true'){ + $membersHome++; + } + } + if ($membersHome == 0 && $automation['executed'] == 0) { + $restart = true; + } else if ($membersHome > 0 && $automation['executed'] == 1){ + $run = true; + } + /*echo "Someone Home". '
'; + echo "at home" . $membersHome. '
'; + echo "run" . $run. '
'; + echo "restart" . $restart. '
';*/ } diff --git a/class/DB.php b/class/DB.php index 8134907..4308385 100644 --- a/class/DB.php +++ b/class/DB.php @@ -19,6 +19,10 @@ class Db{ } } + public static function disconect(){ + self::$join = null; + } + public static function loadOne ($sql, $values = array (), $numberKey = false) { $answer = self::$join->prepare ($sql); $answer->execute ($values); diff --git a/lang/cs.php b/lang/cs.php index c574793..b7e3af3 100644 --- a/lang/cs.php +++ b/lang/cs.php @@ -63,8 +63,12 @@ $lang = [ 'w_icon' => 'Ikona', 'w_no' => 'žádná', 'w_noOne' => 'Nikdo', + 'w_someOne' => 'Někdo', 'w_room' => 'Místnost', 'w_moduls' => 'Moduly', + 'w_home' => 'Doma', + 'w_neni' => 'Není', + 'w_is' => 'je', //example '' => '', diff --git a/lang/en.php b/lang/en.php index 77251f8..cfb2369 100644 --- a/lang/en.php +++ b/lang/en.php @@ -63,8 +63,12 @@ $lang = [ 'w_icon' => 'Icon', 'w_no' => 'no', 'w_noOne' => 'noone', + 'w_someOne' => 'Some', 'w_room' => 'Room', 'w_moduls' => 'Moduls', + 'w_home' => 'Home', + 'w_neni' => 'At', + 'w_is' => 'is', //example '' => '', diff --git a/templates/dashboard.phtml b/templates/dashboard.phtml index 0ab0229..747e310 100644 --- a/templates/dashboard.phtml +++ b/templates/dashboard.phtml @@ -48,7 +48,7 @@

Modal bitch

-
+
Zvolte zařízení: