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 @@