diff --git a/api.php b/api.php index 204cc80..f7dc0df 100644 --- a/api.php +++ b/api.php @@ -3,12 +3,33 @@ include_once('./config.php'); //Autoloader -foreach (["class", "views"] as $dir) { - $files = scandir('./'.$dir.'/'); - $files = array_diff($files, array('.', '..')); - foreach ($files as $file) { - include_once './'.$dir.'/'. $file; - } + +$files = scandir('./app/class/'); + +$files = array_diff($files, array( + '.', + '..', + 'app', + 'ChartJS.php', + 'ChartJS_Line.php', + 'ChartManager.php', + 'DashboardManager.php', + 'Partial.php', + 'Form.php', + 'Route.php', + 'Template.php', + 'Ajax.php', +)); + +foreach($files as $file) { + include './app/class/'. $file; +} + + +//Allow acces only wia Curl, Ajax ETC +$restAcess = 'XMLHttpRequest' == ( $_SERVER['HTTP_X_REQUESTED_WITH'] ?? '' ); +if (!$restAcess){ + header('Location: ./'); } //Log @@ -21,17 +42,16 @@ Db::connect (DBHOST, DBUSER, DBPASS, DBNAME); $json = file_get_contents('php://input'); $obj = json_decode($json, true); - //zabespecit proti Ddosu if (isset($obj['user']) && $obj['user'] != ''){ //user at home - $user = UserManager::getUser($obj['user']); if (!empty($user)) { $userId = $user['user_id']; - $atHome = boolval ($obj['atHome']); - UserManager::atHome($userId, $atHome ? 'true' : 'false'); - echo 'Saved'; + $atHome = $obj['atHome']; + UserManager::atHome($userId, $atHome); + $logManager->write("[Record] user " . $userId . "changet his home state to " . $atHome . RECORDTIMOUT , LogRecordType::WARNING); + echo 'Saved: ' . $atHome; header("HTTP/1.1 200 OK"); die(); } @@ -61,7 +81,7 @@ try { try { RecordManager::clean(RECORDTIMOUT); } catch (\Exception $e) { - $logManager->write("[Record] cleaning record older that" . RECORDTIMOUT , LogRecordType::ERROR); + $logManager->write("[Record] cleaning record older that " . RECORDTIMOUT , LogRecordType::ERROR); } //Variables @@ -114,7 +134,7 @@ if ($values != null || $values != "") { SubDeviceManager::create($deviceId, $key, UNITS[$key]); } RecordManager::create($deviceId, $key, round($value['value'],2)); - $logManager->write("[API] Device_ID " . $deviceId . " writed value " . $key . $value['value'], LogRecordType::INFO); + $logManager->write("[API] Device_ID " . $deviceId . " writed value " . $key . ' ' . $value['value'], LogRecordType::INFO); } $hostname = strtolower($device['name']); diff --git a/class/AutomationManager.php b/app/class/AutomationManager.php similarity index 100% rename from class/AutomationManager.php rename to app/class/AutomationManager.php diff --git a/class/ChartJS.php b/app/class/ChartJS.php similarity index 100% rename from class/ChartJS.php rename to app/class/ChartJS.php diff --git a/class/ChartJS_Line.php b/app/class/ChartJS_Line.php similarity index 100% rename from class/ChartJS_Line.php rename to app/class/ChartJS_Line.php diff --git a/class/ChartManager.php b/app/class/ChartManager.php similarity index 100% rename from class/ChartManager.php rename to app/class/ChartManager.php diff --git a/class/DB.php b/app/class/DB.php similarity index 100% rename from class/DB.php rename to app/class/DB.php diff --git a/class/DashboardManager.php b/app/class/DashboardManager.php similarity index 100% rename from class/DashboardManager.php rename to app/class/DashboardManager.php diff --git a/class/DeviceManager.php b/app/class/DeviceManager.php similarity index 100% rename from class/DeviceManager.php rename to app/class/DeviceManager.php diff --git a/app/class/Form.php b/app/class/Form.php new file mode 100644 index 0000000..0dfbaa9 --- /dev/null +++ b/app/class/Form.php @@ -0,0 +1,121 @@ +formName = 'name="'.$name.'"'; + } + if ($id != "") { + $this->formId = 'id="'.$id.'"'; + } + if ($method != "") { + $this->method = 'method="'.$method.'"'; + } + if ($action != "") { + $this->$action = 'action="'.$action.'"'; + } + } + /** + * [addInput description] + * @param String $type Type of input element (text, number, color,checkbox, button, date, datetime, submit) + * @param String $name name of element + * @param String $id id of element + * @param String $label label of element + * @param String $value value of element + * @param boolean $require require selector toggle + * @param boolean $enabled enable selector toggle + */ + function addInput(String $type, String $name, String $id, String $label, String $value, Bool $require = false, Bool $enabled = true){ + $this->formContent .= '
'; @@ -29,6 +29,6 @@ class Partial{ extract($this->assignedValues); } - require('templates/part/' . $this->path . '.phtml'); + require('app/templates/part/' . $this->path . '.phtml'); } } diff --git a/class/RecordManager.php b/app/class/RecordManager.php similarity index 100% rename from class/RecordManager.php rename to app/class/RecordManager.php diff --git a/class/RoomManager.php b/app/class/RoomManager.php similarity index 100% rename from class/RoomManager.php rename to app/class/RoomManager.php diff --git a/class/Route.php b/app/class/Route.php similarity index 100% rename from class/Route.php rename to app/class/Route.php diff --git a/class/SceneManager.php b/app/class/SceneManager.php similarity index 100% rename from class/SceneManager.php rename to app/class/SceneManager.php diff --git a/class/SubDeviceManager.php b/app/class/SubDeviceManager.php similarity index 100% rename from class/SubDeviceManager.php rename to app/class/SubDeviceManager.php diff --git a/class/Template.php b/app/class/Template.php similarity index 64% rename from class/Template.php rename to app/class/Template.php index d64d42c..4d99dab 100644 --- a/class/Template.php +++ b/app/class/Template.php @@ -7,7 +7,7 @@ class Template extends Partial{ function __construct($path = "", $debug = false) { $this->debug = $debug; - if (!empty('templates/' . $path . '.phtml') && file_exists('templates/' . $path . '.phtml')) { + if (!empty('app/templates/' . $path . '.phtml') && file_exists('app/templates/' . $path . '.phtml')) { $this->path = $path; } else { echo ''; @@ -26,9 +26,9 @@ class Template extends Partial{ function render() { extract($this->assignedValues); - if (!empty('controls/' . $this->path . '.php') && file_exists('controls/' . $this->path . '.php')) { - require_once('controls/' . $this->path . '.php'); + if (!empty('app/controls/' . $this->path . '.php') && file_exists('app/controls/' . $this->path . '.php')) { + require_once('app/controls/' . $this->path . '.php'); } - require_once('templates/' . $this->path . '.phtml'); + require_once('app/templates/' . $this->path . '.phtml'); } } diff --git a/class/UserManager.php b/app/class/UserManager.php similarity index 100% rename from class/UserManager.php rename to app/class/UserManager.php diff --git a/class/Utilities.php b/app/class/Utilities.php similarity index 89% rename from class/Utilities.php rename to app/class/Utilities.php index 39d9052..87767bb 100644 --- a/class/Utilities.php +++ b/app/class/Utilities.php @@ -35,4 +35,10 @@ class Utilities ); return preg_replace(array_keys($utf8), array_values($utf8), $text); } + + function stringInsert($str,$insertstr,$pos) + { + $str = substr($str, 0, $pos) . $insertstr . substr($str, $pos); + return $str; + } } diff --git a/controls/automation.php b/app/controls/automation.php similarity index 100% rename from controls/automation.php rename to app/controls/automation.php diff --git a/controls/dashboard.php b/app/controls/dashboard.php similarity index 100% rename from controls/dashboard.php rename to app/controls/dashboard.php diff --git a/controls/home.php b/app/controls/home.php similarity index 100% rename from controls/home.php rename to app/controls/home.php diff --git a/controls/scene.php b/app/controls/scene.php similarity index 100% rename from controls/scene.php rename to app/controls/scene.php diff --git a/lang/cs.php b/app/lang/cs.php similarity index 97% rename from lang/cs.php rename to app/lang/cs.php index 885c641..d5090a9 100644 --- a/lang/cs.php +++ b/app/lang/cs.php @@ -6,6 +6,7 @@ $lang = [ 'm_settings' => 'Nastavení', 'm_automatization' => 'Automatizace', 'm_scenes' => 'Scény', + 'm_log' => 'Log', //Buttons 'b_year' => 'Rok', @@ -42,6 +43,7 @@ $lang = [ 'l_permission' => 'Oprávmnění', 'l_inMinutes' => 'v minutách', 'l_sleepTime' => 'Doba spánku zařízení', + 'l_atHome' => 'Doma Jsou', //Title 't_createScene' => 'Vytvořit scénu', diff --git a/lang/en.php b/app/lang/en.php similarity index 97% rename from lang/en.php rename to app/lang/en.php index b237341..e6952e8 100644 --- a/lang/en.php +++ b/app/lang/en.php @@ -6,6 +6,7 @@ $lang = [ 'm_settings' => 'Setting', 'm_automatization' => 'Automatization', 'm_scenes' => 'Scenes', + 'm_log' => 'Log', //Buttons 'b_year' => 'Year', @@ -42,6 +43,7 @@ $lang = [ 'l_permission' => 'Permission', 'l_inMinutes' => 'in minutes', 'l_sleepTime' => 'Device sleep Time', + 'l_atHome' => 'At home', //Title 't_createScene' => 'Create Scene', diff --git a/app/logs/.gitkeep b/app/logs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/templates/Elementum/scss/elements/_buttons.scss b/app/templates/Elementum/scss/elements/_buttons.scss similarity index 100% rename from templates/Elementum/scss/elements/_buttons.scss rename to app/templates/Elementum/scss/elements/_buttons.scss diff --git a/templates/automation.phtml b/app/templates/automation.phtml similarity index 65% rename from templates/automation.phtml rename to app/templates/automation.phtml index e7739a9..4d1b50a 100644 --- a/templates/automation.phtml +++ b/app/templates/automation.phtml @@ -11,23 +11,12 @@-+ prepare('item','automation'); + $partial->prepare('lang',$LANG); + $partial->render(); + ?>diff --git a/templates/css/font-awesome.min.css b/app/templates/css/font-awesome.min.css similarity index 100% rename from templates/css/font-awesome.min.css rename to app/templates/css/font-awesome.min.css diff --git a/templates/css/loading.css b/app/templates/css/loading.css similarity index 100% rename from templates/css/loading.css rename to app/templates/css/loading.css diff --git a/templates/css/main.css b/app/templates/css/main.css similarity index 100% rename from templates/css/main.css rename to app/templates/css/main.css diff --git a/templates/css/main.css.map b/app/templates/css/main.css.map similarity index 100% rename from templates/css/main.css.map rename to app/templates/css/main.css.map diff --git a/templates/css/modal.css b/app/templates/css/modal.css similarity index 100% rename from templates/css/modal.css rename to app/templates/css/modal.css diff --git a/templates/css/pre.css b/app/templates/css/pre.css similarity index 100% rename from templates/css/pre.css rename to app/templates/css/pre.css diff --git a/templates/dashboard.phtml b/app/templates/dashboard.phtml similarity index 67% rename from templates/dashboard.phtml rename to app/templates/dashboard.phtml index 747e310..5df6ff0 100644 --- a/templates/dashboard.phtml +++ b/app/templates/dashboard.phtml @@ -11,23 +11,12 @@-+ prepare('item', 'dashboard'); + $partial->prepare('lang',$LANG); + $partial->render(); + ?>Add Device diff --git a/templates/fonts/FontAwesome.otf b/app/templates/fonts/FontAwesome.otf similarity index 100% rename from templates/fonts/FontAwesome.otf rename to app/templates/fonts/FontAwesome.otf diff --git a/templates/fonts/Metropolis-Medium.otf b/app/templates/fonts/Metropolis-Medium.otf similarity index 100% rename from templates/fonts/Metropolis-Medium.otf rename to app/templates/fonts/Metropolis-Medium.otf diff --git a/templates/fonts/Metropolis-Regular.otf b/app/templates/fonts/Metropolis-Regular.otf similarity index 100% rename from templates/fonts/Metropolis-Regular.otf rename to app/templates/fonts/Metropolis-Regular.otf diff --git a/templates/fonts/Metropolis-SemiBold.otf b/app/templates/fonts/Metropolis-SemiBold.otf similarity index 100% rename from templates/fonts/Metropolis-SemiBold.otf rename to app/templates/fonts/Metropolis-SemiBold.otf diff --git a/templates/fonts/fontawesome-webfont.eot b/app/templates/fonts/fontawesome-webfont.eot similarity index 100% rename from templates/fonts/fontawesome-webfont.eot rename to app/templates/fonts/fontawesome-webfont.eot diff --git a/templates/fonts/fontawesome-webfont.svg b/app/templates/fonts/fontawesome-webfont.svg similarity index 100% rename from templates/fonts/fontawesome-webfont.svg rename to app/templates/fonts/fontawesome-webfont.svg diff --git a/templates/fonts/fontawesome-webfont.ttf b/app/templates/fonts/fontawesome-webfont.ttf similarity index 100% rename from templates/fonts/fontawesome-webfont.ttf rename to app/templates/fonts/fontawesome-webfont.ttf diff --git a/templates/fonts/fontawesome-webfont.woff b/app/templates/fonts/fontawesome-webfont.woff similarity index 100% rename from templates/fonts/fontawesome-webfont.woff rename to app/templates/fonts/fontawesome-webfont.woff diff --git a/templates/fonts/fontawesome-webfont.woff2 b/app/templates/fonts/fontawesome-webfont.woff2 similarity index 100% rename from templates/fonts/fontawesome-webfont.woff2 rename to app/templates/fonts/fontawesome-webfont.woff2 diff --git a/templates/home.phtml b/app/templates/home.phtml similarity index 68% rename from templates/home.phtml rename to app/templates/home.phtml index 51c3bbe..d265683 100644 --- a/templates/home.phtml +++ b/app/templates/home.phtml @@ -11,23 +11,12 @@-@@ -35,14 +24,8 @@ + prepare('item', 'home'); + $partial->prepare('lang',$LANG); + $partial->render(); + ?>diff --git a/templates/images/icon-192x192.png b/app/templates/images/icon-192x192.png similarity index 100% rename from templates/images/icon-192x192.png rename to app/templates/images/icon-192x192.png diff --git a/templates/images/icon-512x512.png b/app/templates/images/icon-512x512.png similarity index 100% rename from templates/images/icon-512x512.png rename to app/templates/images/icon-512x512.png diff --git a/templates/js/jquery.js b/app/templates/js/jquery.js similarity index 100% rename from templates/js/jquery.js rename to app/templates/js/jquery.js diff --git a/templates/js/jquery.redirect.js b/app/templates/js/jquery.redirect.js similarity index 100% rename from templates/js/jquery.redirect.js rename to app/templates/js/jquery.redirect.js diff --git a/templates/js/post.js b/app/templates/js/post.js similarity index 100% rename from templates/js/post.js rename to app/templates/js/post.js diff --git a/templates/js/script.js b/app/templates/js/script.js similarity index 100% rename from templates/js/script.js rename to app/templates/js/script.js diff --git a/templates/loading.css b/app/templates/loading.css similarity index 100% rename from templates/loading.css rename to app/templates/loading.css diff --git a/templates/log.phtml b/app/templates/log.phtml similarity index 54% rename from templates/log.phtml rename to app/templates/log.phtml index 9059726..f446e17 100644 --- a/templates/log.phtml +++ b/app/templates/log.phtml @@ -11,23 +11,12 @@diff --git a/templates/login.phtml b/app/templates/login.phtml similarity index 100% rename from templates/login.phtml rename to app/templates/login.phtml diff --git a/templates/part/automationButton.phtml b/app/templates/part/automationButton.phtml similarity index 100% rename from templates/part/automationButton.phtml rename to app/templates/part/automationButton.phtml diff --git a/templates/part/automationCreate.phtml b/app/templates/part/automationCreate.phtml similarity index 100% rename from templates/part/automationCreate.phtml rename to app/templates/part/automationCreate.phtml diff --git a/templates/part/automationCreateFinal.phtml b/app/templates/part/automationCreateFinal.phtml similarity index 100% rename from templates/part/automationCreateFinal.phtml rename to app/templates/part/automationCreateFinal.phtml diff --git a/templates/part/automationEdit.phtml b/app/templates/part/automationEdit.phtml similarity index 100% rename from templates/part/automationEdit.phtml rename to app/templates/part/automationEdit.phtml diff --git a/templates/part/dashboardButton.phtml b/app/templates/part/dashboardButton.phtml similarity index 100% rename from templates/part/dashboardButton.phtml rename to app/templates/part/dashboardButton.phtml diff --git a/templates/part/deviceButton.phtml b/app/templates/part/deviceButton.phtml similarity index 100% rename from templates/part/deviceButton.phtml rename to app/templates/part/deviceButton.phtml diff --git a/templates/part/deviceDetail.phtml b/app/templates/part/deviceDetail.phtml similarity index 100% rename from templates/part/deviceDetail.phtml rename to app/templates/part/deviceDetail.phtml diff --git a/templates/part/deviceEdit.phtml b/app/templates/part/deviceEdit.phtml similarity index 100% rename from templates/part/deviceEdit.phtml rename to app/templates/part/deviceEdit.phtml diff --git a/templates/part/footer.phtml b/app/templates/part/footer.phtml similarity index 100% rename from templates/part/footer.phtml rename to app/templates/part/footer.phtml diff --git a/templates/part/head.phtml b/app/templates/part/head.phtml similarity index 100% rename from templates/part/head.phtml rename to app/templates/part/head.phtml diff --git a/app/templates/part/menu.phtml b/app/templates/part/menu.phtml new file mode 100644 index 0000000..b87d80b --- /dev/null +++ b/app/templates/part/menu.phtml @@ -0,0 +1,46 @@ + \ No newline at end of file diff --git a/templates/part/sceneButton.phtml b/app/templates/part/sceneButton.phtml similarity index 100% rename from templates/part/sceneButton.phtml rename to app/templates/part/sceneButton.phtml diff --git a/templates/part/sceneCreate.phtml b/app/templates/part/sceneCreate.phtml similarity index 100% rename from templates/part/sceneCreate.phtml rename to app/templates/part/sceneCreate.phtml diff --git a/templates/part/sceneCreateOptions.phtml b/app/templates/part/sceneCreateOptions.phtml similarity index 100% rename from templates/part/sceneCreateOptions.phtml rename to app/templates/part/sceneCreateOptions.phtml diff --git a/templates/part/sceneEdit.phtml b/app/templates/part/sceneEdit.phtml similarity index 100% rename from templates/part/sceneEdit.phtml rename to app/templates/part/sceneEdit.phtml diff --git a/templates/part/test.phtml b/app/templates/part/test.phtml similarity index 100% rename from templates/part/test.phtml rename to app/templates/part/test.phtml diff --git a/templates/rooms.phtml b/app/templates/rooms.phtml similarity index 83% rename from templates/rooms.phtml rename to app/templates/rooms.phtml index 88ddd49..77b120a 100644 --- a/templates/rooms.phtml +++ b/app/templates/rooms.phtml @@ -11,23 +11,12 @@-+ prepare('item', 'log'); + $partial->prepare('lang',$LANG); + $partial->render(); + ?>@@ -42,15 +31,17 @@- - '; + '; + foreach ($file_lines as $line) { + echo $line; + } + echo ''; } - } - ?> + ?> +-diff --git a/templates/scene.phtml b/app/templates/scene.phtml similarity index 67% rename from templates/scene.phtml rename to app/templates/scene.phtml index f0b96ab..6b3d3b4 100644 --- a/templates/scene.phtml +++ b/app/templates/scene.phtml @@ -11,23 +11,12 @@ + prepare('item', 'rooms'); + $partial->prepare('lang',$LANG); + $partial->render(); + ?>-+ prepare('item', 'scene'); + $partial->prepare('lang',$LANG); + $partial->render(); + ?>diff --git a/templates/setting.phtml b/app/templates/setting.phtml similarity index 68% rename from templates/setting.phtml rename to app/templates/setting.phtml index a604415..593ad91 100644 --- a/templates/setting.phtml +++ b/app/templates/setting.phtml @@ -11,23 +11,12 @@ diff --git a/views/Ajax.php b/app/views/Ajax.php similarity index 98% rename from views/Ajax.php rename to app/views/Ajax.php index efb16f7..94caaa9 100644 --- a/views/Ajax.php +++ b/app/views/Ajax.php @@ -1,8 +1,8 @@ prepare('users', $users); + + //Users at home Info + $usersAtHome = ''; + $i = 0; + foreach ($users as $user) { + $i++; + if ($user['at_home'] == 'true') { + $usersAtHome .= $user['username']; + if ($usersAtHome != "" && isset($users[$i + 1])){ + $usersAtHome .= ', '; + } + } + } + $template->prepare('usersAtHome', $usersAtHome); + $roomsItems = []; $roomsData = RoomManager::getAllRooms(); foreach ($roomsData as $roomKey => $roomsData) { @@ -124,9 +142,6 @@ class Home extends Template ]; } - $users = UserManager::getUsers(); - $template->prepare('users', $users); - $rooms = RoomManager::getAllRooms(); $template->prepare('rooms', $rooms); $template->prepare('title', 'Home'); diff --git a/views/Log.php b/app/views/Log.php similarity index 93% rename from views/Log.php rename to app/views/Log.php index f8e671f..af2646e 100644 --- a/views/Log.php +++ b/app/views/Log.php @@ -16,7 +16,7 @@ class Log extends Template $template->prepare('title', 'Log'); $result = array(); - $cdir = scandir('./logs/'); + $cdir = scandir('./app/logs/'); foreach ($cdir as $key => $value) { if (!in_array($value,array(".",".."))) diff --git a/views/Login.php b/app/views/Login.php similarity index 100% rename from views/Login.php rename to app/views/Login.php diff --git a/views/Logout.php b/app/views/Logout.php similarity index 100% rename from views/Logout.php rename to app/views/Logout.php diff --git a/views/Rooms.php b/app/views/Rooms.php similarity index 100% rename from views/Rooms.php rename to app/views/Rooms.php diff --git a/views/Scene.php b/app/views/Scene.php similarity index 100% rename from views/Scene.php rename to app/views/Scene.php diff --git a/views/Setting.php b/app/views/Setting.php similarity index 100% rename from views/Setting.php rename to app/views/Setting.php diff --git a/class/Form.php b/class/Form.php deleted file mode 120000 index 7fa7c6a..0000000 --- a/class/Form.php +++ /dev/null @@ -1 +0,0 @@ -C:/Users/spaninger/Documents/git/PHP_FORM_GENERATOR/Form.php \ No newline at end of file diff --git a/index.php b/index.php index 545a7f7..a1ecd6c 100644 --- a/index.php +++ b/index.php @@ -11,10 +11,11 @@ mb_internal_encoding ("UTF-8"); //Autoloader foreach (["class", "views"] as $dir) { - $files = scandir('./'.$dir.'/'); - $files = array_diff($files, array('.', '..')); + $files = scandir('./app/'.$dir.'/'); + $files = array_diff($files, array('.', '..', 'app')); + foreach($files as $file) { - include_once './'.$dir.'/'. $file; + include './app/'.$dir.'/'. $file; } } @@ -33,7 +34,7 @@ if (DEBUGMOD == 1) { echo ''; echo '';*/ } -require_once './lang/' . $langTag . '.php'; +require_once './app/lang/' . $langTag . '.php'; //DB Conector Db::connect (DBHOST, DBUSER, DBPASS, DBNAME); @@ -55,8 +56,8 @@ $form->addInput(InputTypes::TEXT,'nadpis','','Label',''); $form->addInput(InputTypes::CHECK,'nadpis','','Label',''); $form->addInput(InputTypes::TEXT,'nadpis','','Label',''); $arg = array( - 'test_v' => 'test', - 'test_v2' => 'test', +'test_v' => 'test', +'test_v2' => 'test', ); $form->addSelect('1', '1', '1', $arg, false); $form->render();