diff --git a/app/Routes.php b/app/Routes.php index cf2a959..de8b2e8 100644 --- a/app/Routes.php +++ b/app/Routes.php @@ -7,16 +7,12 @@ $router->setDefault(function(){ }); //Pages -$router->any('/', 'Home'); +$router->any('/', 'Log'); $router->any('/login', 'Login'); $router->any('/logout', 'Logout'); $router->any('/automation', 'Automation'); -$router->any('/dashboard', 'Dashboard'); $router->any('/setting', 'Setting'); -$router->any('/scene', 'Scene'); $router->any('/ajax', 'Ajax'); -$router->any('/log', 'Log'); -$router->any('/rooms', 'Rooms'); $router->post('/api/devices', 'DevicesApi@getAllDevices'); $router->post('/api/login', 'AuthApi@login'); diff --git a/app/controllers/dashboardController.php b/app/controllers/dashboardController.php deleted file mode 100644 index f2538c1..0000000 --- a/app/controllers/dashboardController.php +++ /dev/null @@ -1,13 +0,0 @@ - diff --git a/app/controllers/homeController.php b/app/controllers/homeController.php deleted file mode 100644 index 6660f4d..0000000 --- a/app/controllers/homeController.php +++ /dev/null @@ -1,87 +0,0 @@ - $deviceOwnerUserId, - 'name' => $deviceName, - 'icon' => $deviceIcon, - 'permission' => $permissionsInJson, - 'sleep_time' => $sleepTime, - 'room_id' => $deviceOwnerRoomId, - ); - DeviceManager::edit($deviceId, $args); - } catch (\Exception $e) { - echo $e->message(); - - } - - - - //Debug - if (DEBUGMOD == 1) { - echo '
';
-			echo $permissionsInJson;
-			echo $deviceId;
-			var_dump(json_decode ($permissionsInJson));
-			echo '
'; - echo 'CONTINUE'; - die(); - } - } else if (isset($_POST['approveDevice'])) { - $deviceId = $_POST['deviceId']; - $args = array( - 'approved' => 1, - ); - DeviceManager::edit($deviceId, $args); - } else if (isset($_POST['disableDevice'])) { - $deviceId = $_POST['deviceId']; - $args = array( - 'approved' => 2, - ); - DeviceManager::edit($deviceId, $args); - } - - //Debug - if (DEBUGMOD == 1) { - echo '
';
-		var_dump($POST);
-		echo '
'; - echo 'CONTINUE'; - die(); - } - header('Location: ' . BASEURL ); - die(); -} -?> diff --git a/app/controllers/loginController.php b/app/controllers/loginController.php index ae7a445..de4fed6 100644 --- a/app/controllers/loginController.php +++ b/app/controllers/loginController.php @@ -40,7 +40,7 @@ if ( $checkResult = $ga->verifyCode($otaSecret, $otaCode, 2); // 2 = 2*30sec clock tolerance if ($checkResult) { $landingPage = $userManager->login($userName, $userPassword, $rememberMe); - header('Location: ' . BASEURL . $landingPage); + header('Location: ' . BASEURL . '/'); echo 'OK'; } else { echo 'FAILED'; diff --git a/app/controllers/sceneController.php b/app/controllers/sceneController.php deleted file mode 100644 index b7f1f99..0000000 --- a/app/controllers/sceneController.php +++ /dev/null @@ -1,18 +0,0 @@ -'; - var_dump($_POST); - echo ''; - echo 'CONTINUE'; - die(); - } -} diff --git a/app/views/Dashboard.php b/app/views/Dashboard.php deleted file mode 100644 index 37ce3aa..0000000 --- a/app/views/Dashboard.php +++ /dev/null @@ -1,92 +0,0 @@ -isLogin()){ - header('Location: ' . BASEURL . 'login'); - } - - $template = new Template('dashboard'); - - $dashboard = []; - $dashboardData = DashboardManager::getAllDashboards($userManager->getUserData('user_id')); - foreach ($dashboardData as $dashboardItemKey => $dashboardItemValue) { - $subDeviceData = SubDeviceManager::getSubDevice($dashboardItemValue['subdevice_id']); - $deviceData = SubDeviceManager::getSubDeviceMaster($dashboardItemValue['subdevice_id']); - - $lastRecord = RecordManager::getLastRecord($dashboardItemValue['subdevice_id']); - $parsedValue = $lastRecord['value']; - - //TODO: Opravit aby to bylo stejné parsování jako na HOME - if ($subDeviceData['type'] == "on/off") { - $parsedValue = ($parsedValue == 1 ? 'ON' : 'OFF'); - } - if ($subDeviceData['type'] == "light") { - $parsedValue = ($parsedValue == 1 ? 'Light' : 'Dark'); - } - - $dashboard[$dashboardItemValue['dashboard_id']] = [ - 'icon' => $deviceData['icon'], - 'id' => $subDeviceData['subdevice_id'], - 'masterId' => $deviceData['device_id'], - 'name' => $deviceData['name'], - 'type' => $subDeviceData['type'], - 'unit' => $subDeviceData['unit'], - 'lastRecord' => [ - 'value' => $parsedValue, - ], - ]; - } - - $approvedSubDevices = []; - $allDevicesData = DeviceManager::getAllDevices(); - foreach ($allDevicesData as $deviceKey => $deviceValue) { - if (!$deviceValue['approved']) continue; - $allSubDevicesData = SubDeviceManager::getAllSubDevices($deviceValue['device_id']); - foreach ($allSubDevicesData as $subDeviceKey => $subDeviceValue) { - $approvedSubDevices[$subDeviceValue['subdevice_id']] = [ - 'name' => $allDevicesData[$deviceKey]['name'], - 'type' => $subDeviceValue['type'], - ]; - } - } - - - if (isset($_POST['deviceId'])){ - - $deviceData = DeviceManager::getDeviceById($_POST['deviceId']); - - $subDevices = []; - $subDevicesData = SubDeviceManager::getAllSubDevices($_POST['deviceId']); - - foreach ($subDevicesData as $subDeviceKey => $subDeviceData) { - $subDevices[$subDeviceData['subdevice_id']] = [ - 'type' => $subDeviceData['type'], - 'unit' => $subDeviceData['unit'], - ]; - } - - $device = [ - 'id' => $deviceData['device_id'], - 'name' => $deviceData['name'], - 'token' => $deviceData['token'], - 'icon' => $deviceData['icon'], - 'subDevices' => $subDevices, - ]; - $template->prepare('deviceData', $device); - } - - $template->prepare('baseDir', BASEDIR); - $template->prepare('debugMod', DEBUGMOD); - $template->prepare('title', 'Nástěnka'); - $template->prepare('langMng', $langMng); - $template->prepare('dashboard', $dashboard); - $template->prepare('subDevices', $approvedSubDevices); - - $template->render(); - } -} diff --git a/app/views/Home.php b/app/views/Home.php deleted file mode 100644 index 0f053f7..0000000 --- a/app/views/Home.php +++ /dev/null @@ -1,194 +0,0 @@ -isLogin()){ - header('Location: ' . BASEURL . 'login'); - } - - $template = new Template('home'); - - //users instantialize - $users = UserManager::getUsers(); - $template->prepare('users', $users); - - //Users at home Info - $usersAtHome = ''; - $i = 0; - foreach ($users as $user) { - if ($user['at_home'] == 'true') { - $i++; - $usersAtHome .= $user['username']; - if ($usersAtHome != "" && isset($users[$i + 1]) && $users[$i + 1]['at_home'] == 'true'){ - $usersAtHome .= ', '; - } - } - } - $template->prepare('usersAtHome', $usersAtHome); - - - $roomsItems = []; - $roomsData = RoomManager::getAllRooms(); - foreach ($roomsData as $roomKey => $roomsData) { - $devices = []; - $devicesData = DeviceManager::getAllDevicesInRoom($roomsData['room_id']); - foreach ($devicesData as $deviceKey => $deviceData) { - $subDevices = []; - $subDevicesData = SubDeviceManager::getAllSubDevices($deviceData['device_id']); - foreach ($subDevicesData as $subDeviceKey => $subDeviceData) { - - $events = RecordManager::getLastRecord($subDeviceData['subdevice_id'], 5); - $eventsRaw = $events; - - $connectionError = true; - $parsedValue = ""; - $niceTime = ""; - - if (sizeof($events) > 1) { - $lastRecord = $events[0]; - $lastValue = round($lastRecord['value']); - $parsedValue = $lastValue; - - /*Value Parsing*/ - //Last Value Parsing - switch ($subDeviceData['type']) { - case 'on/off': - $replacementTrue = 'On'; - $replacementFalse = 'Off'; - $operator = '=='; - $breakValue = 1; - break; - - case 'door': - $replacementTrue = 'Closed'; - $replacementFalse = 'Open'; - $operator = '=='; - $breakValue = 1; - break; - - case 'light': - $replacementTrue = 'Light'; - $replacementFalse = 'Dark'; - $operator = '=='; - $breakValue = 1; - if ($lastValue != 1 && $lastValue != 0) { //Digital Light Senzor - $operator = '<'; - $breakValue = 810; - } - break; - - case 'water': - $replacementTrue = 'Wet'; - $replacementFalse = 'Dry'; - $operator = '=='; - $breakValue = 1; - break; - - default: - $replacementTrue = ''; - $replacementFalse = ''; - break; - } - - if ($replacementTrue != '' && $replacementFalse != '') { - //parsing last values - $parsedValue = $replacementFalse; - - if (Utilities::checkOperator($lastValue, $operator, $breakValue)) { - $parsedValue = $replacementTrue; - } - - - //parsing last events values - foreach ($events as $key => $value) { - $events[$key]['value'] = $replacementFalse; - if (Utilities::checkOperator($value['value'], $operator, $breakValue)) { - $events[$key]['value'] = $replacementTrue; - } - } - } - - $LastRecordTime = new DateTime($lastRecord['time']); - $niceTime = Utilities::ago($LastRecordTime); - - $interval = $LastRecordTime->diff(new DateTime()); - $hours = $interval->format('%h'); - $minutes = $interval->format('%i'); - $lastSeen = ($hours * 60 + $minutes); - - if ( - $lastSeen < $deviceData['sleep_time'] || - $subDeviceData['type'] == "on/off" || - $subDeviceData['type'] == "door" - ) { - $connectionError = false; - } - } - - $subDevices[$subDeviceData['subdevice_id']] = [ - 'events'=> $events, - 'eventsRaw'=> $eventsRaw, - 'type' => $subDeviceData['type'], - 'unit' => $subDeviceData['unit'], - 'comError' => $connectionError, - 'lastRecort' => [ - 'value' => (empty($parsedValue) ? 0 : $parsedValue), - 'time' => (empty($lastRecord['time']) ? "00:00" : $lastRecord['time']), - 'niceTime' => (empty($niceTime) ? "00:00" : $niceTime), - ], - ]; - } - - $permissionArray = json_decode($deviceData['permission']); - $userIsDeviceAdmin = false; - if($permissionArray[1] == 3) { - $userIsDeviceAdmin = true; - } else if ($permissionArray[0] == 3) { - if ( $deviceData['owner'] == $_SESSION['user']['id']) { - $userIsDeviceAdmin = true; - } - } - - $devices[$deviceData['device_id']] = [ - 'name' => $deviceData['name'], - 'icon' => $deviceData['icon'], - 'room' => $deviceData['room_id'], - 'token' => $deviceData['token'], - 'type' => $deviceData['type'], - 'mac' => $deviceData['mac'], - 'ip' => $deviceData['ip_address'], - 'subnet' => $deviceData['subnet'], - 'gateway' => $deviceData['gateway'], - 'sleepTime' => $deviceData['sleep_time'], - 'approved' => $deviceData['approved'], - 'permission' => $permissionArray, - 'owner' => $deviceData['owner'], - 'userIsAdmin' => $userIsDeviceAdmin, - 'subDevices' => $subDevices, - ]; - } - $roomsItems[$roomsData['room_id']] = [ - 'name' => $roomsData['name'], - 'deviceCount' => $roomsData['device_count'], - 'devices' => $devices, - ]; - } - - $rooms = RoomManager::getAllRooms(); - $template->prepare('baseDir', BASEDIR); - $template->prepare('debugMod', DEBUGMOD); - $template->prepare('title', 'Home'); - $template->prepare('rooms', $rooms); - $template->prepare('langMng', $langMng); - $template->prepare('data', $roomsItems); - - $template->render(); - - } -} diff --git a/app/views/Rooms.php b/app/views/Rooms.php deleted file mode 100644 index f765e5e..0000000 --- a/app/views/Rooms.php +++ /dev/null @@ -1,87 +0,0 @@ -isLogin()){ - header('Location: ' . BASEURL . 'login'); - } - - $template = new Template('rooms'); - - $template->prepare('baseDir', BASEDIR); - $template->prepare('debugMod', DEBUGMOD); - $template->prepare('title', 'Rooms'); - $template->prepare('langMng', $langMng); - - $roomsItems = []; - $roomsData = RoomManager::getAllRooms(); - foreach ($roomsData as $roomKey => $roomsData) { - $devicesData = DeviceManager::getAllDevicesInRoom($roomsData['room_id']); - $roomReading = []; - if ($roomsData['device_count'] == 0) { - continue; - } - - $roomReadingCache = []; - $roomControlsCache = []; - foreach ($devicesData as $deviceKey => $deviceData) { - $subDevicesData = SubDeviceManager::getAllSubDevices($deviceData['device_id']); - foreach ($subDevicesData as $subDeviceKey => $subDeviceData) { - $subDeviceType = $subDeviceData['type']; - $subDeviceUnit = $subDeviceData['unit']; - $lastRecord = RecordManager::getLastRecord($subDeviceData['subdevice_id']); - - if (in_array($subDeviceType, ['on/off','battery','door'])) { - if ($subDeviceType == 'on/off') { - $roomControlsCache[$subDeviceKey] = [ - 'type' => $subDeviceType, - 'name' => $deviceData['name'], - 'icon' => $deviceData['icon'], - 'value' => $lastRecord['value'], - ]; - } - continue; - } - - if (array_key_exists($subDeviceType, $roomReadingCache)) { - $roomReadingCache[$subDeviceType] = [ - "value" => $roomReadingCache[$subDeviceType]['value'] + $lastRecord['value'], - "count" => $roomReadingCache[$subDeviceType]['count'] + 1, - "unit" => $subDeviceUnit, - ]; - } else { - $roomReadingCache[$subDeviceType] = [ - "value" => $lastRecord['value'], - "count" => 1, - "unit" => $subDeviceUnit, - ]; - } - } - } - - // parsing - foreach ($roomReadingCache as $type => $value) { - $roomReading[$type] = $value["value"] / $value["count"]; - $roomReading[$type] .= @($value['unit']); - } - - $roomsItems[$roomsData['room_id']] = [ - 'name' => $roomsData['name'], - 'reading' => $roomReading, - 'controls' => $roomControlsCache, - 'deviceCount' => $roomsData['device_count'], - ]; - } - - $template->prepare('rooms', $roomsItems); - - $template->render(); - - } -} diff --git a/app/views/Scene.php b/app/views/Scene.php deleted file mode 100644 index 5fee909..0000000 --- a/app/views/Scene.php +++ /dev/null @@ -1,84 +0,0 @@ -isLogin()){ - header('Location: ' . BASEURL . 'login'); - } - - $template = new Template('scene'); - $template->prepare('baseDir', BASEDIR); - $template->prepare('debugMod', DEBUGMOD); - $template->prepare('title', 'Scény'); - $template->prepare('langMng', $langMng); - - $scenes = []; - foreach (SceneManager::getAllScenes() as $sceneId => $sceneData) { - $doSomething = []; - foreach (json_decode($sceneData['do_something']) as $subdeviceId => $subDeviceState) { - $subDeviceMasterDeviceData = SubDeviceManager::getSubDeviceMaster($subdeviceId); - $doSomething[$subdeviceId] = [ - 'name' => $subDeviceMasterDeviceData['name'], - 'state' => $subDeviceState, - ]; - } - $scenes[$sceneData['scene_id']] = [ - "name" => $sceneData['name'], - "icon" => $sceneData['icon'], - "doSomething" => $doSomething, - - ]; - } - - $template->prepare('scenes', $scenes); - - $approvedSubDevices = []; - $allDevicesData = DeviceManager::getAllDevices(); - foreach ($allDevicesData as $deviceKey => $deviceValue) { - if (!$deviceValue['approved']) continue; - $allSubDevicesData = SubDeviceManager::getAllSubDevices($deviceValue['device_id']); - foreach ($allSubDevicesData as $subDeviceKey => $subDeviceValue) { - if ($subDeviceValue['type'] != 'on/off') continue; - $approvedSubDevices[$subDeviceValue['subdevice_id']] = [ - 'name' => $allDevicesData[$deviceKey]['name'], - ]; - } - } - $template->prepare('subDevices', $approvedSubDevices); - - $approvedSubDevices = []; - $allDevicesData = DeviceManager::getAllDevices(); - foreach ($allDevicesData as $deviceKey => $deviceValue) { - if (!$deviceValue['approved']) continue; - $allSubDevicesData = SubDeviceManager::getAllSubDevices($deviceValue['device_id']); - foreach ($allSubDevicesData as $subDeviceKey => $subDeviceValue) { - if ($subDeviceValue['type'] != 'on/off') continue; - $approvedSubDevices[$subDeviceValue['subdevice_id']] = [ - 'name' => $allDevicesData[$deviceKey]['name'], - ]; - } - } - $template->prepare('subDevices', $approvedSubDevices); - - if (isset($_POST['devices'])){ - $devices = $_POST['devices']; - $devicesOBJ = []; - foreach ($devices as $deviceId) { - $deviceData = DeviceManager::getDeviceById($deviceId); - $subdeviceData = SubDeviceManager::getSubDeviceByMaster($deviceId, 'on/off'); - $devicesOBJ[$deviceId] = [ - 'name' => $deviceData['name'], - 'setableSubDevices' => $subdeviceData['subdevice_id'], - ]; - } - $template->prepare('setStateFormDevices', $devicesOBJ); - $template->prepare('sceneName', $_POST['sceneName']); - $template->prepare('sceneIcon', $_POST['sceneIcon']); - } - $template->render(); - } -} diff --git a/app/views/templates/dashboard.phtml b/app/views/templates/dashboard.phtml deleted file mode 100644 index f62dcf6..0000000 --- a/app/views/templates/dashboard.phtml +++ /dev/null @@ -1,67 +0,0 @@ - - - - prepare('baseDir', $BASEDIR); - $partial->render(); - ?> - <?php echo $TITLE; ?> - - -
-
- -
- echo('t_addDevice'); ?> -
- $dashboardItemData) { - $partialDeviceButton = new Partial('dashboardButton'); - $partialDeviceButton->prepare('dashboardItemData', $dashboardItemData); - - $partialDeviceButton->render(); - } ?> -
-
-
- - - - prepare('DEVICEDATA', $DEVICEDATA); - - $partial->render(); - } - $partial = new Partial('footer'); - $partial->render(); - ?> - - diff --git a/app/views/templates/home.phtml b/app/views/templates/home.phtml deleted file mode 100644 index 59c4a24..0000000 --- a/app/views/templates/home.phtml +++ /dev/null @@ -1,107 +0,0 @@ - - - - prepare('baseDir', $BASEDIR); - $partial->render(); - ?> - <?php echo $TITLE ?> - - -
-
- - - - -
-
- echo('l_atHome'); - echo ': ' . $USERSATHOME; - } - ?> -
-
- -
-
- $room) { ?> - $device) { ?> - $subDevice) { - //BUTTON - $partialDeviceButton = new Partial('deviceButton'); - $partialDeviceButton->prepare('roomid',$roomId); - $partialDeviceButton->prepare('subdeviceid',$subDeviceKey); - $partialDeviceButton->prepare('subdevice',$subDevice); - $partialDeviceButton->prepare('deviceid',$deviceId); - $partialDeviceButton->prepare('device',$device); - - $partialDeviceButton->render(); - - //DETAIL - $partialDetail = new Partial('deviceDetail'); - $partialDetail->prepare('subdeviceid',$subDeviceKey); - $partialDetail->prepare('subdevice',$subDevice); - $partialDetail->prepare('device',$device); - $partialDetail->prepare('langMng',$LANGMNG); - - $partialDetail->render(); - - //SETTING - $partialEdit = new Partial('deviceEdit'); - $partialEdit->prepare('deviceid',$deviceId); - $partialEdit->prepare('subdevice',$subDevice); - $partialEdit->prepare('device',$device); - $partialEdit->prepare('users',$USERS); - $partialEdit->prepare('rooms',$ROOMS); - $partialEdit->prepare('langMng',$LANGMNG); - - $partialEdit->render(); - } - } - } ?> -
-
-
- render(); - ?> - - - diff --git a/app/views/templates/part/dashboardButton.phtml b/app/views/templates/part/dashboardButton.phtml deleted file mode 100644 index aa0a704..0000000 --- a/app/views/templates/part/dashboardButton.phtml +++ /dev/null @@ -1,21 +0,0 @@ -
-
-
-
-
-
-
&#x
-
-
-
-
-
-
-
- -
-
-
-
-
-
\ No newline at end of file diff --git a/app/views/templates/part/deviceButton.phtml b/app/views/templates/part/deviceButton.phtml deleted file mode 100644 index 93f8c4b..0000000 --- a/app/views/templates/part/deviceButton.phtml +++ /dev/null @@ -1,39 +0,0 @@ - - -
data-room-id=""> -
-
" id="device-" data-sub-device-id=""> -
-
-
-
&#x
-
-
- - - - - -
- -
-
-
-
- -
-
-
-
-
-
diff --git a/app/views/templates/part/deviceDetail.phtml b/app/views/templates/part/deviceDetail.phtml deleted file mode 100644 index b143984..0000000 --- a/app/views/templates/part/deviceDetail.phtml +++ /dev/null @@ -1,85 +0,0 @@ - - diff --git a/app/views/templates/part/deviceEdit.phtml b/app/views/templates/part/deviceEdit.phtml deleted file mode 100644 index f64e47c..0000000 --- a/app/views/templates/part/deviceEdit.phtml +++ /dev/null @@ -1,179 +0,0 @@ - diff --git a/app/views/templates/part/menu.phtml b/app/views/templates/part/menu.phtml index 14b1229..36d45e6 100644 --- a/app/views/templates/part/menu.phtml +++ b/app/views/templates/part/menu.phtml @@ -1,16 +1,6 @@