FTP -> GIT (SYNC)
This commit is contained in:
131
app/class/AutomationManager.php
Normal file
131
app/class/AutomationManager.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
class AutomationManager{
|
||||
public static $automation;
|
||||
|
||||
public function remove($automationId) {
|
||||
return Db::command ('DELETE FROM automation WHERE automation_id=?', array ($automationId));
|
||||
}
|
||||
|
||||
public function deactive($automationId) {
|
||||
$automation = Db::loadOne ("SELECT * FROM automation WHERE automation_id=?" , array ($automationId));
|
||||
$flipedValue = ($automation['active'] == 1 ? 0 : 1);
|
||||
return Db::command ('UPDATE automation SET active = ? WHERE automation_id=?', array ($flipedValue,$automationId));
|
||||
}
|
||||
|
||||
public function create ($name, $onDays, $doCode, $ifCode) {
|
||||
$scene = array (
|
||||
'name' => $name,
|
||||
'on_days' => $onDays,
|
||||
'if_something' => $ifCode,
|
||||
'do_something' => $doCode,
|
||||
);
|
||||
try {
|
||||
Db::add ('automation', $scene);
|
||||
} catch(PDOException $error) {
|
||||
echo $error->getMessage();
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
public function getAll(){
|
||||
return Db::loadAll ("SELECT * FROM automation");
|
||||
|
||||
}
|
||||
|
||||
public function executeAll(){
|
||||
global $logManager;
|
||||
|
||||
$automations = Db::loadAll ("SELECT * FROM automation");
|
||||
$dayNameNow = strtolower (date('D', time()));
|
||||
|
||||
foreach ($automations as $automation) {
|
||||
$onValue = json_decode($automation['if_something'], true);
|
||||
$sceneDoJson = $automation['do_something'];
|
||||
$actionDays = json_decode($automation['on_days'], true);
|
||||
$value = time();
|
||||
$run = false;
|
||||
$restart = false;
|
||||
|
||||
if ($automation['active'] != 0){
|
||||
if (in_array($dayNameNow, $actionDays)){
|
||||
if (in_array($onValue['type'], ['sunSet', 'sunRise', 'time','now'])) {
|
||||
|
||||
if ($onValue['type'] == 'sunSet') {
|
||||
$value = date_sunset($value, SUNFUNCS_RET_TIMESTAMP, 50.0755381 , 14.4378005, 90);
|
||||
} else if ($onValue['type'] == 'sunRise') {
|
||||
$value = date_sunrise($value, SUNFUNCS_RET_TIMESTAMP, 50.0755381 , 14.4378005, 90);
|
||||
} else if ($onValue['type'] == 'time') {
|
||||
$onValue = explode(':',$onValue['value']);
|
||||
$today = date_create('now');
|
||||
$onValue = $today->setTime($onValue[0], $onValue[1]);
|
||||
$value = $today->getTimestamp();
|
||||
}
|
||||
|
||||
/*
|
||||
Echo "Spouštění Automatizace";
|
||||
echo "Aktual" . date( "HH:mm", strtotime(time()));
|
||||
echo "Run At" . date( "HH:mm", strtotime($value));
|
||||
*/
|
||||
|
||||
if (time() > $value){
|
||||
if ($automation['executed'] == 0){
|
||||
$run = true;
|
||||
} else if (time() < $value && $automation['executed'] = 1) { //recovery realowing of automation
|
||||
$restart = true;
|
||||
}
|
||||
}
|
||||
} else if ($onValue['type'] == 'outHome') {
|
||||
|
||||
} else if ($onValue['type'] == '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'] == 1) {
|
||||
$restart = true;
|
||||
} else if ($membersHome > 0 && $automation['executed'] == 0){
|
||||
$run = true;
|
||||
}
|
||||
/*echo "Someone Home". '<br>';
|
||||
echo "at home" . $membersHome. '<br>';
|
||||
echo "run" . $run. '<br>';
|
||||
echo "restart" . $restart. '<br>';*/
|
||||
|
||||
}
|
||||
|
||||
//finalization
|
||||
if ($run) {
|
||||
$sceneDoArray = json_decode($sceneDoJson);
|
||||
foreach ($sceneDoArray as $deviceId => $deviceState) {
|
||||
RecordManager::create($deviceId, 'on/off', $deviceState);
|
||||
}
|
||||
$logManager->write("[AUTOMATIONS] automation id ". $automation['automation_id'] . " was executed");
|
||||
Db::edit('automation', array('executed' => 1), 'WHERE automation_id = ?', array($automation['automation_id']));
|
||||
} else if ($restart) {
|
||||
$logManager->write("[AUTOMATIONS] automation id ". $automation['automation_id'] . " was restarted");
|
||||
Db::edit('automation', array('executed' => 0), 'WHERE automation_id = ?', array($automation['automation_id']));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
194
app/class/ChartJS.php
Normal file
194
app/class/ChartJS.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
abstract class ChartJS
|
||||
{
|
||||
/**
|
||||
* @var array chart data
|
||||
*/
|
||||
protected $_datasets = array();
|
||||
/**
|
||||
* @var array chart labels
|
||||
*/
|
||||
protected $_labels = array();
|
||||
/**
|
||||
* The chart type
|
||||
* @var string
|
||||
*/
|
||||
protected $_type = '';
|
||||
/**
|
||||
* @var array Specific options for chart
|
||||
*/
|
||||
protected $_options = array();
|
||||
/**
|
||||
* @var string Chartjs canvas' ID
|
||||
*/
|
||||
protected $_id;
|
||||
/**
|
||||
* @var string Canvas width
|
||||
*/
|
||||
protected $_width;
|
||||
/**
|
||||
* @var string Canvas height
|
||||
*/
|
||||
protected $_height;
|
||||
/**
|
||||
* @var array Canvas attributes (class,
|
||||
*/
|
||||
protected $_attributes = array();
|
||||
/**
|
||||
* @var array Default colors
|
||||
*/
|
||||
protected static $_defaultColors = array('fill' => 'rgba(220,220,220,0.2)', 'stroke' => 'rgba(220,220,220,1)', 'point' => 'rgba(220,220,220,1)', 'pointStroke' => '#fff');
|
||||
/**
|
||||
* Add label(s)
|
||||
* @param array $labels
|
||||
* @param bool $reset
|
||||
*/
|
||||
public function addLabels(array $labels, $reset = false)
|
||||
{
|
||||
if ($reset) {
|
||||
$this->_labels = array();
|
||||
}
|
||||
$this->_labels = $this->_labels + $labels;
|
||||
}
|
||||
/**
|
||||
* Add dataset
|
||||
* @param $dataset
|
||||
* @param $reset
|
||||
*/
|
||||
public function addDataset($dataset, $reset)
|
||||
{
|
||||
if ($reset) {
|
||||
$this->_datasets = array();
|
||||
}
|
||||
$this->_datasets += $dataset;
|
||||
}
|
||||
public function __construct($id = null, $width = '', $height = '', $otherAttributes = array())
|
||||
{
|
||||
if (!$id) {
|
||||
$id = uniqid('chartjs_', true);
|
||||
}
|
||||
$this->_id = $id;
|
||||
$this->_width = $width;
|
||||
$this->_height = $height;
|
||||
// Always save otherAttributes as array
|
||||
if ($otherAttributes && !is_array($otherAttributes)) {
|
||||
$otherAttributes = array($otherAttributes);
|
||||
}
|
||||
$this->_attributes = $otherAttributes;
|
||||
}
|
||||
/**
|
||||
* This method allows to echo ChartJS object and directly renders canvas (instead of using ChartJS->render())
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->renderCanvas();
|
||||
}
|
||||
public function renderCanvas()
|
||||
{
|
||||
$data = $this->_renderData();
|
||||
$options = $this->_renderOptions();
|
||||
$height = $this->_renderHeight();
|
||||
$width = $this->_renderWidth();
|
||||
$attributes = $this->_renderAttributes();
|
||||
$canvas = '<canvas id="' . $this->_id . '" data-chartjs="' . $this->_type . '"' . $height . $width . $attributes . $data . $options . '></canvas>';
|
||||
return $canvas;
|
||||
}
|
||||
/**
|
||||
* Prepare canvas' attributes
|
||||
* @return string
|
||||
*/
|
||||
protected function _renderAttributes()
|
||||
{
|
||||
$attributes = '';
|
||||
foreach ($this->_attributes as $attribute => $value) {
|
||||
$attributes .= ' ' . $attribute . '="' . $value . '"';
|
||||
}
|
||||
return $attributes;
|
||||
}
|
||||
/**
|
||||
* Prepare width attribute for canvas
|
||||
* @return string
|
||||
*/
|
||||
protected function _renderWidth()
|
||||
{
|
||||
$width = '';
|
||||
if ($this->_width) {
|
||||
$width = ' width="' . $this->_width . '"';
|
||||
}
|
||||
return $width;
|
||||
}
|
||||
/**
|
||||
* Prepare height attribute for canvas
|
||||
* @return string
|
||||
*/
|
||||
protected function _renderHeight()
|
||||
{
|
||||
$height = '';
|
||||
if ($this->_height) {
|
||||
$height = ' height="' . $this->_height . '"';
|
||||
}
|
||||
return $height;
|
||||
}
|
||||
/**
|
||||
* Render custom options for the chart
|
||||
* @return string
|
||||
*/
|
||||
protected function _renderOptions()
|
||||
{
|
||||
if (empty($this->_options)) {
|
||||
return '';
|
||||
}
|
||||
return ' data-options=\'' . json_encode($this->_options) . '\'';
|
||||
}
|
||||
/**
|
||||
* Prepare data (labels and dataset) for the chart
|
||||
* @return string
|
||||
*/
|
||||
protected function _renderData()
|
||||
{
|
||||
$array_data = array('labels' => array(), 'datasets' => array());
|
||||
$i = 0;
|
||||
foreach ($this->_datasets as $line) {
|
||||
$this->_completeColors($line['options'], $i);
|
||||
$array_data['datasets'][] = $line['options'] + array('data' => $line['data']);
|
||||
$i++;
|
||||
}
|
||||
$array_data['labels'] = $this->_labels;
|
||||
return ' data-data=\'' . json_encode($array_data) . '\'';
|
||||
}
|
||||
/**
|
||||
* Set default colors
|
||||
* @param array $defaultColors
|
||||
*/
|
||||
public static function setDefaultColors(array $defaultColors)
|
||||
{
|
||||
self::$_defaultColors = $defaultColors;
|
||||
}
|
||||
/**
|
||||
* @param array $color
|
||||
*/
|
||||
public static function addDefaultColor(array $color)
|
||||
{
|
||||
if (!empty($color['fill']) && !empty($color['stroke']) && !empty($color['point']) && !empty($color['pointStroke'])) {
|
||||
self::$_defaultColors[] = $color;
|
||||
} else {
|
||||
trigger_error('Color is missing to add this theme (need fill, stroke, point and pointStroke) : color not added', E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
protected function _completeColors(&$options, &$i)
|
||||
{
|
||||
if (empty(static::$_defaultColors[$i])) {
|
||||
$i = 0;
|
||||
}
|
||||
$colors = static::$_defaultColors[$i];
|
||||
foreach (static::$_colorsRequired as $name) {
|
||||
if (empty($options[$name])) {
|
||||
$shortName = str_replace('Color', '', $name);
|
||||
if (empty($colors[$shortName])) {
|
||||
$shortName = static::$_colorsReplacement[$shortName];
|
||||
}
|
||||
$options[$name] = $colors[$shortName];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
21
app/class/ChartJS_Line.php
Normal file
21
app/class/ChartJS_Line.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
class ChartJS_Line extends ChartJS
|
||||
{
|
||||
protected $_type = 'Line';
|
||||
protected static $_colorsRequired = array('fillColor', 'strokeColor', 'pointColor', 'pointStrokeColor', 'pointHighlightFill', 'pointHighlightStroke');
|
||||
protected static $_colorsReplacement = array('pointHighlightFill' => 'point', 'pointHighlightStroke' => 'pointStroke');
|
||||
/**
|
||||
* Add a set of data
|
||||
* @param array $data
|
||||
* @param array $options
|
||||
* @param null $name Name cas be use to change data / options later
|
||||
*/
|
||||
public function addLine($data = array(), $options = array(), $name = null)
|
||||
{
|
||||
if (!$name) {
|
||||
$name = count($this->_datasets) + 1;
|
||||
}
|
||||
$this->_datasets[$name]['data'] = $data;
|
||||
$this->_datasets[$name]['options'] = $options;
|
||||
}
|
||||
}
|
86
app/class/ChartManager.php
Normal file
86
app/class/ChartManager.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
class ChartManager{
|
||||
function generateChart($data, $min = 0, $max = 100)
|
||||
{
|
||||
|
||||
echo '<br>Aktuální Hodnota: '.$data[0]['value'];
|
||||
echo "<style>
|
||||
.sloupec {
|
||||
border-top: solid 2px red;
|
||||
}
|
||||
</style>";
|
||||
echo '<div class=graph>';
|
||||
echo '<div class="posuv " graf-max="'.$max.'" graf-min='.$min.'>';
|
||||
for ($valuesRow = 0; $valuesRow < count($data); $valuesRow++) {
|
||||
$row = $data[$valuesRow];
|
||||
|
||||
echo '<div class="sloupec " name="sloupec" value="' . $row['value'] . '" data-toggle="tooltip" title=""></div>';
|
||||
}
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
echo '<script src="./include/js/chartDrwer.js"></script>';
|
||||
echo 'Poslední Update: ';
|
||||
|
||||
echo '<style>
|
||||
.graph {
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
|
||||
margin-top: auto;
|
||||
}
|
||||
|
||||
|
||||
.posuv {
|
||||
display: flex;
|
||||
height: 200px;
|
||||
background-image: url(./img/graph.png);
|
||||
padding: 20px;
|
||||
background-repeat: repeat;
|
||||
border-bottom: 1px solid black;
|
||||
}
|
||||
|
||||
.sloupec {
|
||||
border-top: solid 2px blue;
|
||||
background-color: grey;
|
||||
float: left;
|
||||
margin: auto 0 0;
|
||||
display: inline-block;
|
||||
width: 1%;
|
||||
}
|
||||
|
||||
</style>
|
||||
<script>
|
||||
var posuvList = document.getElementsByClassName("posuv");
|
||||
var maxHeight = posuvList[0].clientHeight;
|
||||
for (i = 0; i < posuvList.length; i++) {
|
||||
var maxPx = 0;
|
||||
var grafMax = Number(posuvList[i].getAttribute("graf-max")); //100%
|
||||
var grafMin = Number(posuvList[i].getAttribute("graf-min")); //0%
|
||||
if (grafMin == 0 && grafMax == 100) {
|
||||
var onePercent = 1;
|
||||
} else {
|
||||
var stepsBetWene = grafMax;
|
||||
if (grafMin !== 0) {
|
||||
if (grafMin < 0) {
|
||||
stepsBetWene = grafMax + Math.abs(grafMin);
|
||||
}
|
||||
if (grafMin > 0) {
|
||||
stepsBetWene = grafMax - grafMin;
|
||||
}
|
||||
}
|
||||
var onePercent = stepsBetWene / 100;
|
||||
}
|
||||
var sloupceList = posuvList[i].querySelectorAll(".sloupec");
|
||||
for (ai = 0; ai < sloupceList.length; ai++) {
|
||||
var onePxPercent = maxHeight / 100;
|
||||
var heightInPercent =
|
||||
Math.abs(sloupceList[ai].getAttribute("value")) / onePercent;
|
||||
var outputPx = onePxPercent * heightInPercent;
|
||||
|
||||
sloupceList[ai].style.height = outputPx + "px";
|
||||
}
|
||||
}
|
||||
</script>';
|
||||
}
|
||||
}
|
||||
?>
|
100
app/class/DB.php
Normal file
100
app/class/DB.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
class Db{
|
||||
private static $join;
|
||||
private static $commandDatabase = array (
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
|
||||
PDO::ATTR_EMULATE_PREPARES => false
|
||||
);
|
||||
|
||||
public static function connect ($host, $user, $password, $database) {
|
||||
if (!isset (self::$join)) {
|
||||
self::$join = @new PDO(
|
||||
"mysql:host=$host;dbname=$database;charset=utf8",
|
||||
$user,
|
||||
$password,
|
||||
self::$commandDatabase
|
||||
);
|
||||
self::$join->exec ("set names utf8");
|
||||
}
|
||||
}
|
||||
|
||||
public static function disconect(){
|
||||
self::$join = null;
|
||||
}
|
||||
|
||||
public static function loadOne ($sql, $values = array (), $numberKey = false) {
|
||||
$answer = self::$join->prepare ($sql);
|
||||
$answer->execute ($values);
|
||||
if (!$numberKey) {
|
||||
return $answer->fetch (PDO::FETCH_ASSOC);
|
||||
} else {
|
||||
return $answer->fetch (PDO::FETCH_NUM);
|
||||
}
|
||||
}
|
||||
|
||||
public static function command ($sql, $values = array()) {
|
||||
$answer = self::$join->prepare ($sql);
|
||||
return $answer->execute ($values);
|
||||
}
|
||||
|
||||
public static function loadAll ($sql, $values = array(), $numberKey = false) {
|
||||
$answer = self::$join->prepare ($sql);
|
||||
$answer->execute ($values);
|
||||
if (!$numberKey) {
|
||||
return $answer->fetchALL (PDO::FETCH_ASSOC);
|
||||
} else {
|
||||
return $answer->fetchALL (PDO::FETCH_NUM);
|
||||
}
|
||||
}
|
||||
|
||||
public static function loadAlone ($sql, $values = array()) {
|
||||
$answer = self::$join->prepare ($sql);
|
||||
$answer->execute ($values);
|
||||
return $answer->fetch (PDO::FETCH_NUM)[0];
|
||||
}
|
||||
|
||||
public static function add ($table, $values = array()) {
|
||||
return self::command (
|
||||
"INSERT INTO `$table` (`" .
|
||||
implode('`, `', array_keys($values)) .
|
||||
"`) VALUES (" .
|
||||
str_repeat('?,', (count($values) > 0 ? count($values)-1 : 0)) .
|
||||
"?)"
|
||||
, array_values ($values));
|
||||
}
|
||||
// TODO: pokud vlozim prazdne pole tak chyba ??
|
||||
public static function addAll ($table, $values = array ()) {
|
||||
try {
|
||||
foreach ($values as $value) {
|
||||
self::add ($table, $value);
|
||||
}
|
||||
} catch (PDOException $ex) {
|
||||
throw new PDOException ($ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static function edit (
|
||||
$table,
|
||||
$values = array(),
|
||||
$conditions,
|
||||
$values2 = array()
|
||||
) {
|
||||
return self::command (
|
||||
"UPDATE `$table` SET `" .
|
||||
implode('` =?, `', array_keys($values)) .
|
||||
"` =? " .
|
||||
$conditions
|
||||
, array_merge (array_values ($values), $values2));
|
||||
}
|
||||
|
||||
public static function insertId () {
|
||||
return self::$join->lastInsertId ();
|
||||
}
|
||||
|
||||
public static function addId ($lastTable, $lastIdName) {
|
||||
$answer = self::$join->prepare ("SELECT `$lastIdName` FROM `$lastTable` ORDER BY `$lastIdName` DESC");
|
||||
$answer->execute ();
|
||||
return $answer->fetch (PDO::FETCH_NUM)[0];
|
||||
}
|
||||
}
|
41
app/class/DashboardManager.php
Normal file
41
app/class/DashboardManager.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
class DashboardManager{
|
||||
public static $devices;
|
||||
|
||||
|
||||
function getAllDashboards ($userId) {
|
||||
return Db::loadAll ("SELECT * FROM dashboard WHERE user_id=?", array($userId));
|
||||
}
|
||||
|
||||
function getAllSubDevices ($userId) {
|
||||
return Db::loadAll ("SELECT * FROM subdevices WHERE subdevice_id IN (SELECT subdevice_id FROM dashboard WHERE user_id=?)", array($userId));
|
||||
}
|
||||
|
||||
function getSubDevice ($userId, $subDeviceId) {
|
||||
return Db::loadOne ("SELECT * FROM subdevices WHERE subdevice_id = (SELECT subdevice_id FROM dashboard WHERE user_id=? AND subdevice_id = ? )", array($userId, $subDeviceId));
|
||||
}
|
||||
|
||||
function Add ($subDeviceId) {
|
||||
if (self::getSubDevice(UserManager::getUserData('user_id'), $subDeviceId) == null){
|
||||
|
||||
// to do: pokud existuje nepridej
|
||||
//
|
||||
//
|
||||
$dashboardItem = array (
|
||||
'user_id' => UserManager::getUserData('user_id'),
|
||||
'subdevice_id' => $subDeviceId,
|
||||
);
|
||||
try {
|
||||
Db::add ('dashboard', $dashboardItem);
|
||||
} catch(PDOException $error) {
|
||||
echo $error->getMessage();
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Remove ($subDeviceId){
|
||||
$userId = UserManager::getUserData('user_id');
|
||||
Db::command ('DELETE FROM dashboard WHERE subdevice_id=? AND user_id = ?', array ($subDeviceId, $userId));
|
||||
}
|
||||
}
|
80
app/class/DeviceManager.php
Normal file
80
app/class/DeviceManager.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
class DeviceManager{
|
||||
public static $devices;
|
||||
|
||||
function getAllDevices () {
|
||||
return Db::loadAll ("SELECT * FROM devices WHERE approved != ?", Array(2));
|
||||
}
|
||||
|
||||
function getAllDevicesInRoom ($roomId = "") {
|
||||
return Db::loadAll ("SELECT * FROM devices WHERE room_id = ? AND approved != ?", Array($roomId, 2));
|
||||
}
|
||||
|
||||
function getOtherDevices(){
|
||||
return Db::loadAll ("SELECT * FROM devices WHERE room_id IS NULL ");
|
||||
}
|
||||
|
||||
function getDeviceByToken($deviceToken) {
|
||||
return Db::loadOne("SELECT * FROM devices WHERE token = ?", array($deviceToken));
|
||||
}
|
||||
|
||||
function getDeviceById($deviceId) {
|
||||
return Db::loadOne("SELECT * FROM devices WHERE device_id = ?", array($deviceId));
|
||||
}
|
||||
|
||||
public function create ($name, $token) {
|
||||
$device = array (
|
||||
'name' => $name,
|
||||
'token' => $token,
|
||||
);
|
||||
try {
|
||||
Db::add ('devices', $device);
|
||||
} catch(PDOException $error) {
|
||||
echo $error->getMessage();
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
public function edit ($deviceId, $values = []) {
|
||||
try {
|
||||
Db::edit ('devices', $values, 'WHERE device_id = ?', array($deviceId));
|
||||
} catch(PDOException $error) {
|
||||
echo $error->getMessage();
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [assignRoom Přiřazení zařízení do třídy]
|
||||
* @param [type] $roomId [číslo místnosti do kter se má zařízení přiřadit]
|
||||
* @param [type] $deviceId [Číslo zařízení které chcete přiřadit do místnosti]
|
||||
*/
|
||||
public function assignRoom ($roomId, $deviceId) {
|
||||
$device = array (
|
||||
'room_id' => $roomId,
|
||||
);
|
||||
try {
|
||||
Db::edit ('devices', $device, 'WHERE device_id = ?', array($deviceId));
|
||||
} catch(PDOException $error) {
|
||||
echo $error->getMessage();
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [delete Smazání zařízení]
|
||||
* @param [type] $deviceId [Id zařízení ke smazání]
|
||||
*/
|
||||
public function delete ($deviceId) {
|
||||
Db::command ('DELETE FROM devices WHERE device_id=?', array ($deviceId));
|
||||
}
|
||||
|
||||
public function registeret ($deviceToken) {
|
||||
return (count(Db::loadAll ("SELECT * FROM devices WHERE token=?", array($deviceToken))) == 1 ? true : false);
|
||||
}
|
||||
|
||||
public function approved ($deviceToken) {
|
||||
return (count(Db::loadAll ("SELECT * FROM devices WHERE token=? AND approved = ?", array($deviceToken, 1))) == 1 ? true : false);
|
||||
}
|
||||
}
|
||||
?>
|
121
app/class/Form.php
Normal file
121
app/class/Form.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* [InputTypes datatype for input types]
|
||||
*/
|
||||
class InputTypes
|
||||
{
|
||||
const TEXT = 'text';
|
||||
const NUMBER = 'number';
|
||||
const COLOR = 'color';
|
||||
const CHECK = 'checkbox';
|
||||
const BUTTON = 'button';
|
||||
const DATE = 'date';
|
||||
const DATETIME = 'datetime';
|
||||
const SUBMIT = 'submit';
|
||||
const HIDEN = 'hidden';
|
||||
const EMAIL = 'email';
|
||||
}
|
||||
/**
|
||||
* [Form Form Generator Class]
|
||||
*/
|
||||
class Form {
|
||||
|
||||
public $formContent = "";
|
||||
private $formName;
|
||||
private $formId;
|
||||
private $method;
|
||||
private $action;
|
||||
|
||||
/**
|
||||
* [__construct description]
|
||||
* @param String $name [description]
|
||||
* @param String $id [description]
|
||||
* @param String $method [description]
|
||||
* @param String $action [description]
|
||||
*/
|
||||
function __construct(String $name, String $id, String $method, String $action) {
|
||||
if ($name != "") {
|
||||
$this->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 .= '<div class="field">';
|
||||
if ($label != "") {
|
||||
$this->formContent .= '<div class="label">'.$label.'</div>';
|
||||
}
|
||||
$this->formContent .= '<input class="input" type="'.$type.'" name="'.$name.'" value="'.$value.'" ' . ($enabled ? '' : 'disabled') . ($require ? '' : 'required') .'>';
|
||||
$this->formContent .= '</div>';
|
||||
}
|
||||
|
||||
//TODO: add Group support
|
||||
/**
|
||||
* [addSelect description]
|
||||
* @param String $name name of element
|
||||
* @param String $id id of element
|
||||
* @param String $label label of element
|
||||
* @param Array $data array of options [value => valueName]
|
||||
* @param boolean $multiple multiple selector toggle
|
||||
* @param boolean $enabled enable selector toggle
|
||||
*/
|
||||
function addSelect(String $name, String $id, String $label, Array $data, Bool $multiple = false, Bool $require = false, Bool $enabled = true){
|
||||
$this->formContent .= '<div class="field">';
|
||||
if ($label != "") {
|
||||
$this->formContent .= '<div class="label">'.$label.'</div>';
|
||||
}
|
||||
$this->formContent .= '<select class="input"' . ($multiple ? '' : 'multiple') . ($enabled ? '' : 'disabled') . ($require ? '' : 'required') .'>';
|
||||
foreach ($data as $value => $text) {
|
||||
$this->formContent .= '<option value="' . $value . '">' . $text . '</option>';
|
||||
}
|
||||
$this->formContent .= '</select>';
|
||||
$this->formContent .= '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* [addTextarea description]
|
||||
* @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 $enabled enable selector toggle
|
||||
*/
|
||||
function addTextarea(String $name, String $id, String $label, Array $value, Bool $require = false, Bool $enabled = true){
|
||||
$this->formContent .= '<div class="field">';
|
||||
if ($label != "") {
|
||||
$this->formContent .= '<div class="label">'.$label.'</div>';
|
||||
}
|
||||
$this->formContent .= '<textarea class="input"' . ($enabled ? '' : 'disabled') . ($require ? '' : 'required') .'>';
|
||||
$this->formContent .= $value;
|
||||
$this->formContent .= '</textarea>';
|
||||
$this->formContent .= '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* [render function whitch dysplay generated form]
|
||||
*/
|
||||
function render(){
|
||||
self::addInput(InputTypes::SUBMIT, 'formSubmit', '', 'Submit', 'Submit');
|
||||
$form = '<form '.$this->formName.$this->formId.$this->method.$this->action.'">';
|
||||
$form .= $this->formContent;
|
||||
$form .= '</form>';
|
||||
echo $form;
|
||||
}
|
||||
}
|
39
app/class/LogManager.php
Normal file
39
app/class/LogManager.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
class LogRecordType{
|
||||
const WARNING = 'warning';
|
||||
const ERROR = 'error';
|
||||
const INFO = 'info';
|
||||
}
|
||||
|
||||
class LogManager
|
||||
{
|
||||
|
||||
private $logFile;
|
||||
function __construct($fileName = "")
|
||||
{
|
||||
if ($fileName == ""){
|
||||
$fileName = './app/logs/'. date("Y-m-d").'.log';
|
||||
}
|
||||
if(!is_dir("./app/logs/"))
|
||||
{
|
||||
mkdir("./app/logs/");
|
||||
}
|
||||
$this->logFile = fopen($fileName, "a") or die("Unable to open file!");
|
||||
}
|
||||
|
||||
function write($value, $type = LogRecordType::ERROR){
|
||||
$record = "[".date("H:m:s")."][".$type."]" . $value . "\n";
|
||||
$record = Utilities::stringInsert($record,"\n",65);
|
||||
fwrite($this->logFile, $record);
|
||||
}
|
||||
|
||||
function __destruct(){
|
||||
if (isset($this->logFile)) {
|
||||
fclose($this->logFile);
|
||||
}
|
||||
}
|
||||
}
|
34
app/class/Partial.php
Normal file
34
app/class/Partial.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
class Partial{
|
||||
var $assignedValues = [];
|
||||
var $partBuffer;
|
||||
var $path;
|
||||
var $debug;
|
||||
|
||||
function __construct($path = "", $debug = false) {
|
||||
$this->debug = $debug;
|
||||
if (!empty('app/templates/part/' . $path . '.phtml') && file_exists('app/templates/part/' . $path . '.phtml')) {
|
||||
$this->path = $path;
|
||||
} else {
|
||||
echo '<pre>';
|
||||
echo 'PHTML: Parial File ' . $path . ' not found';
|
||||
echo '</pre>';
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
function prepare($searchS, $repleaceS) {
|
||||
if (!empty($searchS)) {
|
||||
$this->assignedValues[strtoupper($searchS)] = $repleaceS;
|
||||
}
|
||||
echo ($this->debug == true ? var_dump($this->assignedValues) : '');
|
||||
}
|
||||
|
||||
function render() {
|
||||
if (!empty($this->assignedValues)){
|
||||
extract($this->assignedValues);
|
||||
}
|
||||
|
||||
require('app/templates/part/' . $this->path . '.phtml');
|
||||
}
|
||||
}
|
80
app/class/RecordManager.php
Normal file
80
app/class/RecordManager.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
class RecordManager{
|
||||
public static $records;
|
||||
|
||||
public function create ($deviceId, $type, $value) {
|
||||
$subDeviceId = Db::loadOne('SELECT * FROM subdevices WHERE device_id = ? AND type = ?;', array($deviceId, $type))['subdevice_id'];
|
||||
if ($subDeviceId == '') {
|
||||
return false;
|
||||
};
|
||||
$record = array (
|
||||
'subdevice_id' => $subDeviceId,
|
||||
'value' => $value,
|
||||
);
|
||||
try {
|
||||
return Db::add ('records', $record);
|
||||
} catch(PDOException $error) {
|
||||
echo $error->getMessage();
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
public static function setExecuted($recordId) {
|
||||
try {
|
||||
Db::edit ('records', ['execuded' => 1], 'WHERE record_id = ?', array($recordId));
|
||||
} catch(PDOException $error) {
|
||||
echo $error->getMessage();
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
public static function getRecordById($recordId) {
|
||||
return Db::loadOne('SELECT * FROM records WHERE record_id = ?;', array($recordId));
|
||||
}
|
||||
|
||||
public static function getLastInsertedRecordId() {
|
||||
return Db::insertId();
|
||||
}
|
||||
|
||||
public static function getLastRecord($subDeviceId, $num = 1) {
|
||||
if ($num == 1)
|
||||
return Db::loadOne('SELECT * FROM records WHERE subdevice_id = ? AND value != ? ORDER BY time DESC;', array($subDeviceId, 999));
|
||||
return Db::loadAll('SELECT * FROM records WHERE subdevice_id = ? AND value != ? ORDER BY time DESC LIMIT ?;', array($subDeviceId, 999, $num));
|
||||
}
|
||||
|
||||
public static function getAllRecord($subDeviceId, $timeFrom, $timeTo) {
|
||||
return Db::loadAll('SELECT * FROM records WHERE subdevice_id = ? AND time >= ? AND time <= ? AND value != ? ORDER BY time;', array($subDeviceId, $timeFrom, $timeTo, 999));
|
||||
}
|
||||
|
||||
public static function getAllRecordForGraph($subDeviceId, $period = "day", $groupBy = "hour") {
|
||||
$periodLocal = '- 1 ' . strtoupper($period);
|
||||
$dateTime = new DateTime();
|
||||
$dateTime = $dateTime->modify($periodLocal);
|
||||
$dateTime = $dateTime->format('Y-m-d');
|
||||
$groupBy = strtoupper($groupBy).'(time)';
|
||||
$sql = 'SELECT value, time FROM records
|
||||
WHERE
|
||||
subdevice_id = ?
|
||||
AND
|
||||
value != 999
|
||||
AND
|
||||
time > ?
|
||||
GROUP BY '.$groupBy.'
|
||||
ORDER BY time ASC';
|
||||
//TODO: Prasárna Opravit
|
||||
return Db::loadAll($sql, array($subDeviceId, $dateTime));
|
||||
}
|
||||
|
||||
public static function clean ($day) {
|
||||
if (isset($day)) {
|
||||
Db::command ('DELETE FROM records WHERE time < ADDDATE(NOW(), INTERVAL -? DAY);', array($day));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO: zkontrolovat jestli neco nezbilo po smazaní
|
||||
public static function cleanSubdeviceRecords ($subDeviceId) {
|
||||
Db::command ('DELETE FROM records WHERE subdevice_id = ?);', array($subDeviceId));
|
||||
}
|
||||
}
|
||||
?>
|
26
app/class/RoomManager.php
Normal file
26
app/class/RoomManager.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
class RoomManager{
|
||||
public static $rooms;
|
||||
|
||||
function getAllRooms () {
|
||||
$allRoom = Db::loadAll ("SELECT rooms.*, COUNT(devices.device_id) as device_count FROM rooms LEFT JOIN devices ON (devices.room_id=rooms.room_id) GROUP BY rooms.room_id");
|
||||
return $allRoom;
|
||||
}
|
||||
|
||||
public function create ($name) {
|
||||
$room = array (
|
||||
'name' => $name,
|
||||
);
|
||||
try {
|
||||
Db::add ('rooms', $room);
|
||||
} catch(PDOException $error) {
|
||||
echo $error->getMessage();
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
public function delete ($roomId) {
|
||||
Db::command ('DELETE FROM rooms WHERE room_id=?', array ($roomId));
|
||||
}
|
||||
}
|
||||
?>
|
30
app/class/Route.php
Normal file
30
app/class/Route.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
class Route{
|
||||
private $urls = [];
|
||||
private $views = [];
|
||||
|
||||
function __construct() {
|
||||
// code...
|
||||
}
|
||||
|
||||
function add($url, $view = "", $conrol = "") {
|
||||
$this->urls[] = '/'.trim($url, '/');
|
||||
if (!empty($view)) {
|
||||
$this->views[] = $view;
|
||||
}
|
||||
}
|
||||
|
||||
function submit(){
|
||||
$urlGetParam = isset($_GET['url']) ? '/' . $_GET['url'] : '/';
|
||||
foreach ($this->urls as $urlKey => $urlValue) {
|
||||
if ($urlValue === $urlGetParam) {
|
||||
$useView = $this->views[$urlKey];
|
||||
new $useView();
|
||||
die();
|
||||
}
|
||||
}
|
||||
echo 'Not Fount 404';
|
||||
die();
|
||||
//TODO: 404 přidělat
|
||||
}
|
||||
}
|
41
app/class/SceneManager.php
Normal file
41
app/class/SceneManager.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
class SceneManager{
|
||||
public static $scenes;
|
||||
|
||||
public function create ($icon, $name, $doCode) {
|
||||
$scene = array (
|
||||
'icon' => $icon,
|
||||
'name' => $name,
|
||||
'do_something' => $doCode,
|
||||
);
|
||||
try {
|
||||
Db::add ('scenes', $scene);
|
||||
} catch(PDOException $error) {
|
||||
echo $error->getMessage();
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllScenes () {
|
||||
return Db::loadAll ("SELECT * FROM scenes");
|
||||
}
|
||||
|
||||
public function getScene ($sceneId) {
|
||||
return Db::loadOne("SELECT * FROM scenes WHERE scene_id = ?", array($sceneId));
|
||||
}
|
||||
|
||||
public function execScene ($sceneId) {
|
||||
$sceneData = SceneManager::getScene($sceneId);
|
||||
$sceneDoJson = $sceneData['do_something'];
|
||||
$sceneDoArray = json_decode($sceneDoJson);
|
||||
foreach ($sceneDoArray as $deviceId => $deviceState) {
|
||||
RecordManager::create($deviceId, 'on/off', $deviceState);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function delete($sceneId){
|
||||
Db::command ('DELETE FROM scenes WHERE scene_id=?', array ($sceneId));
|
||||
}
|
||||
}
|
||||
?>
|
61
app/class/SubDeviceManager.php
Normal file
61
app/class/SubDeviceManager.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
class SubDeviceManager
|
||||
{
|
||||
public static $devices;
|
||||
|
||||
public function getAllSubDevices($deviceId)
|
||||
{
|
||||
return Db::loadAll("SELECT * FROM subdevices WHERE device_id = ?", array($deviceId));
|
||||
}
|
||||
|
||||
public function getSubDeviceMaster($subDeviceId)
|
||||
{
|
||||
return Db::loadOne("SELECT * FROM devices WHERE device_id = (SELECT device_id FROM subdevices WHERE subdevice_id = ?)", array($subDeviceId));
|
||||
}
|
||||
|
||||
public function getSubDeviceByMaster($deviceId, $subDeviceType = null)
|
||||
{
|
||||
if ($subDeviceType == null) {
|
||||
return Db::loadOne("SELECT * FROM subdevices WHERE device_id = ?;", array($deviceId));
|
||||
} else {
|
||||
return Db::loadOne("SELECT * FROM subdevices WHERE device_id = ? AND type = ?;", array($deviceId, $subDeviceType));
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubDeviceByMasterAndType($deviceId, $subDeviceType = null)
|
||||
{
|
||||
if (!empty($subDeviceType)) {
|
||||
return Db::loadOne("SELECT * FROM subdevices WHERE device_id = ?;", array($deviceId));
|
||||
} else {
|
||||
return Db::loadOne("SELECT * FROM subdevices WHERE device_id = ? AND type = ?;", array($deviceId, $subDeviceType));
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubDevice($subDeviceId)
|
||||
{
|
||||
return Db::loadOne("SELECT * FROM subdevices WHERE subdevice_id = ?;", array($subDeviceId));
|
||||
}
|
||||
|
||||
//check if dubdevice exist
|
||||
|
||||
public function create($deviceId, $type, $unit)
|
||||
{
|
||||
$record = array(
|
||||
'device_id' => $deviceId,
|
||||
'type' => $type,
|
||||
'unit' => $unit,
|
||||
);
|
||||
try {
|
||||
Db::add('subdevices', $record);
|
||||
} catch (PDOException $error) {
|
||||
echo $error->getMessage();
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
public function remove($subDeviceId)
|
||||
{
|
||||
RecordManager::cleanSubdeviceRecords($subDeviceId);
|
||||
return Db::loadAll("DELETE FROM subdevices WHERE subdevice_id = ?", array($subDeviceId));
|
||||
}
|
||||
}
|
34
app/class/Template.php
Normal file
34
app/class/Template.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
class Template extends Partial{
|
||||
var $assignedValues = [];
|
||||
var $partBuffer;
|
||||
var $path;
|
||||
var $debug;
|
||||
|
||||
function __construct($path = "", $debug = false) {
|
||||
$this->debug = $debug;
|
||||
if (!empty('app/templates/' . $path . '.phtml') && file_exists('app/templates/' . $path . '.phtml')) {
|
||||
$this->path = $path;
|
||||
} else {
|
||||
echo '<pre>';
|
||||
echo 'PHTML: Template File ' . $path . ' not found';
|
||||
echo '</pre>';
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
function prepare($searchS, $repleaceS) {
|
||||
if (!empty($searchS)) {
|
||||
$this->assignedValues[strtoupper($searchS)] = $repleaceS;
|
||||
}
|
||||
echo ($this->debug == true ? var_dump($this->assignedValues) : '');
|
||||
}
|
||||
|
||||
function render() {
|
||||
extract($this->assignedValues);
|
||||
if (!empty('app/controls/' . $this->path . '.php') && file_exists('app/controls/' . $this->path . '.php')) {
|
||||
require_once('app/controls/' . $this->path . '.php');
|
||||
}
|
||||
require_once('app/templates/' . $this->path . '.phtml');
|
||||
}
|
||||
}
|
180
app/class/UserManager.php
Normal file
180
app/class/UserManager.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
class UserManager
|
||||
{
|
||||
public function getUsers () {
|
||||
try {
|
||||
$allRoom = Db::loadAll ("SELECT * FROM users");
|
||||
return $allRoom;
|
||||
} catch(PDOException $error) {
|
||||
echo $error->getMessage();
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
public function getUser ($userName) {
|
||||
try {
|
||||
$user = Db::loadOne ("SELECT * FROM users WHERE username = ?", [$userName]);
|
||||
return $user;
|
||||
} catch(PDOException $error) {
|
||||
echo $error->getMessage();
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
public function login ($username, $password, $rememberMe) {
|
||||
try {
|
||||
if ($user = Db::loadOne ('SELECT * FROM users WHERE LOWER(username)=LOWER(?)', array ($username))) {
|
||||
if ($user['password'] == UserManager::getHashPassword($password)) {
|
||||
if (isset($rememberMe) && $rememberMe == 'true') {
|
||||
setcookie ("rememberMe" . str_replace(".", "_", $_SERVER['HTTP_HOST']), $this->setEncryptedCookie($user['username']), time () + (30 * 24 * 60 * 60 * 1000), "/", $_SERVER['HTTP_HOST'], 1);
|
||||
}
|
||||
$_SESSION['user']['id'] = $user['user_id'];
|
||||
$page = "./index.php";
|
||||
if ($user["startPage"] == 1) {
|
||||
$page = "./dashboard.php";
|
||||
}
|
||||
unset($_POST['login']);
|
||||
return $page;
|
||||
} else {
|
||||
throw new PDOException("Heslo není správné!");
|
||||
}
|
||||
} else {
|
||||
throw new PDOException("Uživatel s tím to jménem neexistuje!");
|
||||
}
|
||||
} catch(PDOException $error) {
|
||||
echo $error->getMessage();
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
public function isLogin () {
|
||||
if (isset ($_SESSION['user']) && isset($_SESSION['user']['id'])) {
|
||||
return true;
|
||||
} else {
|
||||
if (isset ($_COOKIE['rememberMe' . str_replace(".", "_", $_SERVER['HTTP_HOST'])])){
|
||||
if ($user = Db::loadOne ('SELECT * FROM users WHERE LOWER(username)=LOWER(?)', array ($this->getDecryptedCookie($_COOKIE['rememberMe' . str_replace(".", "_", $_SERVER['HTTP_HOST'])])))) {
|
||||
$_SESSION['user']['id'] = $user['user_id'];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function logout () {
|
||||
setcookie ("rememberMe" . str_replace(".", "_", $_SERVER['HTTP_HOST']),"", time() - (30 * 24 * 60 * 60 * 1000), "/", $_SERVER['HTTP_HOST'], 1);
|
||||
unset($_SESSION['user']);
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
public function setEncryptedCookie($value){
|
||||
$first_key = base64_decode(FIRSTKEY);
|
||||
$second_key = base64_decode(SECONDKEY);
|
||||
|
||||
$method = "aes-256-cbc";
|
||||
$ivlen = openssl_cipher_iv_length($method);
|
||||
$iv = openssl_random_pseudo_bytes($ivlen);
|
||||
$newvalue_raw = openssl_encrypt($value, $method, $first_key, OPENSSL_RAW_DATA, $iv);
|
||||
$hmac = hash_hmac('sha256', $newvalue_raw, $second_key, TRUE);
|
||||
$newvalue = base64_encode ($iv.$hmac.$newvalue_raw);
|
||||
return $newvalue;
|
||||
}
|
||||
|
||||
public function getDecryptedCookie($value){
|
||||
$first_key = base64_decode(FIRSTKEY);
|
||||
$second_key = base64_decode(SECONDKEY);
|
||||
|
||||
$c = base64_decode($value);
|
||||
$method = "aes-256-cbc";
|
||||
$ivlen = openssl_cipher_iv_length($method);
|
||||
$iv = substr($c, 0, $ivlen);
|
||||
$hmac = substr($c, $ivlen, 32);
|
||||
$newValue_raw = substr($c, $ivlen+32);
|
||||
$newValue = openssl_decrypt($newValue_raw, $method, $first_key, OPENSSL_RAW_DATA, $iv);
|
||||
$calcmac = hash_hmac('sha256', $newValue_raw, $second_key, TRUE);
|
||||
if (hash_equals ($hmac, $calcmac)) {
|
||||
return $newValue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getUserData ($type) {
|
||||
if (isset($_SESSION['user']['id'])) {
|
||||
$user = Db::loadOne ('SELECT ' . $type . ' FROM users WHERE user_id=?', array ($_SESSION['user']['id']));
|
||||
return $user[$type];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public function setUserData ($type, $value) {
|
||||
if (isset ($_SESSION['user']['id'])) {
|
||||
Db::command ('UPDATE users SET ' . $type . '=? WHERE user_id=?', array ($value, $_SESSION['user']['id']));
|
||||
}
|
||||
}
|
||||
|
||||
public function getHashPassword ($password) {
|
||||
$salt = "s0mRIdlKvI";
|
||||
$hashPassword = hash('sha512', ($password . $salt));
|
||||
return $hashPassword;
|
||||
}
|
||||
|
||||
public function ulozitObrazek ($file, $path = "", $name = "") {
|
||||
if (!@is_array (getimagesize($file['tmp_name']))) {
|
||||
throw new ChybaUzivatele("Formát obrázku ". $file['name'] ." není podporován!");
|
||||
} else {
|
||||
$extension = strtolower(strrchr($file['name'], '.'));
|
||||
switch ($extension) {
|
||||
case '.jpg':
|
||||
case '.jpeg':
|
||||
$img = @imagecreatefromjpeg($file['tmp_name']);
|
||||
break;
|
||||
case '.gif':
|
||||
$img = @imagecreatefromgif($file['tmp_name']);
|
||||
break;
|
||||
case '.png':
|
||||
$img2 = @imagecreatefrompng($file['tmp_name']);
|
||||
break;
|
||||
case '.ico':
|
||||
$img3 = @$file['tmp_name'];
|
||||
break;
|
||||
default:
|
||||
$img = false;
|
||||
break;
|
||||
}
|
||||
if($name == ""){
|
||||
$nazev = substr($file['name'], 0, strpos($file['name'], ".")) ."_". round(microtime(true) * 1000);
|
||||
}else{
|
||||
$nazev = $name;
|
||||
}
|
||||
if(!file_exists($path)){
|
||||
mkdir($path, 0777, true);
|
||||
}
|
||||
if (@$img) {
|
||||
if (!imagejpeg ($img, $path . $nazev .".jpg", 95)) {
|
||||
throw new ChybaUzivatele ("Obrázek neuložen!");
|
||||
}
|
||||
imagedestroy ($img);
|
||||
} else if (@$img2) {
|
||||
if (!imagepng ($img2, $path . $nazev .".jpg")) {
|
||||
throw new ChybaUzivatele ("Obrázek neuložen!");
|
||||
}
|
||||
imagedestroy ($img2);
|
||||
} else if (@$img3) {
|
||||
if (!copy($img3, $path . $nazev .'.ico')) {
|
||||
throw new ChybaUzivatele ("Obrázek neuložen!");
|
||||
}
|
||||
}
|
||||
return array('success' => true, 'url' => $path . $nazev .".jpg");
|
||||
}
|
||||
}
|
||||
|
||||
public function atHome($userId, $atHome){
|
||||
try {
|
||||
Db::edit ('users', ['at_home' => $atHome], 'WHERE user_id = ?', array($userId));
|
||||
} catch(PDOException $error) {
|
||||
echo $error->getMessage();
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
44
app/class/Utilities.php
Normal file
44
app/class/Utilities.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Utilities
|
||||
{
|
||||
function cleanString($text) {
|
||||
$utf8 = array(
|
||||
'/[áàâãªä]/u' => 'a',
|
||||
'/[ÁÀÂÃÄ]/u' => 'A',
|
||||
'/[ÍÌÎÏ]/u' => 'I',
|
||||
'/[íìîï]/u' => 'i',
|
||||
'/[ěéèêë]/u' => 'e',
|
||||
'/[ĚÉÈÊË]/u' => 'E',
|
||||
'/[óòôõºö]/u' => 'o',
|
||||
'/[ÓÒÔÕÖ]/u' => 'O',
|
||||
'/[úùûü]/u' => 'u',
|
||||
'/[ÚÙÛÜ]/u' => 'U',
|
||||
'/Š/' => 'S',
|
||||
'/š/' => 's',
|
||||
'/Č/' => 'C',
|
||||
'/č/' => 'c',
|
||||
'/ř/' => 'r',
|
||||
'/Ř/' => 'R',
|
||||
'/Ý/' => 'Y',
|
||||
'/ý/' => 'y',
|
||||
'/ç/' => 'c',
|
||||
'/Ç/' => 'C',
|
||||
'/ñ/' => 'n',
|
||||
'/Ñ/' => 'N',
|
||||
'/–/' => '-', // UTF-8 hyphen to "normal" hyphen
|
||||
'/[’‘‹›‚]/u' => ' ', // Literally a single quote
|
||||
'/[“”«»„]/u' => ' ', // Double quote
|
||||
'/ /' => ' ', // nonbreaking space (equiv. to 0x160)
|
||||
);
|
||||
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;
|
||||
}
|
||||
}
|
17
app/controls/automation.php
Normal file
17
app/controls/automation.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
if (isset($_POST) && !empty($_POST)){
|
||||
if (isset($_POST['modalFinal']) && $_POST['modalFinal'] == "Next") {
|
||||
$doCode = json_encode($_POST['device'], JSON_PRETTY_PRINT);
|
||||
$ifCode = json_encode([
|
||||
"type" => $_POST['atSelector'],
|
||||
"value" => $_POST['atSelectorValue'],
|
||||
], JSON_PRETTY_PRINT);
|
||||
$onDays = $_POST['atDays'];
|
||||
|
||||
AutomationManager::create('name', $onDays, $doCode, $ifCode);
|
||||
|
||||
header('Location: /vasek/home/' . strtolower(basename(__FILE__, '.php')), TRUE);
|
||||
die();
|
||||
}
|
||||
}
|
||||
?>
|
14
app/controls/dashboard.php
Normal file
14
app/controls/dashboard.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
if (isset($_POST) && !empty($_POST)){
|
||||
|
||||
if (isset($_POST['modalFinal']) && $_POST['modalFinal'] == "Next") {
|
||||
$subDeviceIds = $_POST['devices'];
|
||||
foreach ($subDeviceIds as $subDeviceId) {
|
||||
DashboardManager::Add($subDeviceId);
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: /vasek/home/' . strtolower(basename(__FILE__, '.php')), TRUE);
|
||||
die();
|
||||
}
|
||||
?>
|
73
app/controls/home.php
Normal file
73
app/controls/home.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
if (isset($_POST) && !empty($_POST)){
|
||||
if (isset($_POST['saveDevice']) && $_POST['saveDevice'] != "") {
|
||||
$deviceId = $_POST['deviceId'];
|
||||
$deviceName = $_POST['deviceName'];
|
||||
$deviceIcon = $_POST['deviceIcon'];
|
||||
$sleepTime = 0;
|
||||
if (isset($_POST['sleepTime'])) {
|
||||
$sleepTime = $_POST['sleepTime'];
|
||||
}
|
||||
//TODO: if device isnt on off
|
||||
$permissionsInJson = json_encode([
|
||||
(int) $_POST['permissionOwner'],
|
||||
(int) $_POST['permissionOther'],
|
||||
]);
|
||||
|
||||
|
||||
$deviceOwnerUserId = $_POST['deviceOwnerUserId'];
|
||||
$deviceOwnerRoomId = $_POST['deviceOwnerId'];
|
||||
|
||||
try {
|
||||
$args = array(
|
||||
'owner' => $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 '<pre>';
|
||||
echo $permissionsInJson;
|
||||
echo $deviceId;
|
||||
var_dump(json_decode ($permissionsInJson));
|
||||
echo '</pre>';
|
||||
echo '<a href="/vasek/home/">CONTINUE</a>';
|
||||
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 '<pre>';
|
||||
var_dump($POST);
|
||||
echo '</pre>';
|
||||
echo '<a href="/vasek/home/">CONTINUE</a>';
|
||||
die();
|
||||
}
|
||||
header('Location: /vasek/home/', TRUE);
|
||||
die();
|
||||
}
|
||||
?>
|
18
app/controls/scene.php
Normal file
18
app/controls/scene.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
if (isset($_POST) && !empty($_POST)){
|
||||
|
||||
SceneManager::create($_POST['sceneIcon'], $_POST['sceneName'], json_encode($_POST['devices']));
|
||||
|
||||
//Debug
|
||||
if (DEBUGMOD == 1) {
|
||||
echo '<pre>';
|
||||
var_dump($_POST);
|
||||
echo '</pre>';
|
||||
echo '<a href="/vasek/home/' . strtolower(basename(__FILE__, '.php')).'">CONTINUE</a>';
|
||||
die();
|
||||
}
|
||||
|
||||
header('Location: /vasek/home/' . strtolower(basename(__FILE__, '.php')), TRUE);
|
||||
die();
|
||||
}
|
77
app/lang/cs.php
Normal file
77
app/lang/cs.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
$lang = [
|
||||
//Menu
|
||||
'm_home' => 'Domů',
|
||||
'm_dashboard' => 'Nástěnka',
|
||||
'm_settings' => 'Nastavení',
|
||||
'm_automatization' => 'Automatizace',
|
||||
'm_scenes' => 'Scény',
|
||||
'm_log' => 'Log',
|
||||
|
||||
//Buttons
|
||||
'b_year' => 'Rok',
|
||||
'b_month' => 'Měsíc',
|
||||
'b_week' => 'Týden',
|
||||
'b_day' => 'Den',
|
||||
'b_hour' => 'Hodina',
|
||||
'b_next' => 'Další',
|
||||
'b_create' => 'Vytvořit',
|
||||
'b_edit' => 'Upravit',
|
||||
'b_remove' => 'Smazat',
|
||||
'b_approve' => 'Povolit',
|
||||
'b_disable' => 'Zakázat',
|
||||
'b_save' => 'Uložit',
|
||||
|
||||
|
||||
//labels
|
||||
'l_choseDevice' => 'Zvolte zařízení:',
|
||||
'l_inHome' => 'Při příchodu',
|
||||
'l_outHome' => 'Pri odchodu',
|
||||
'l_sunSet' => 'Západ Slunce',
|
||||
'l_sunRice' => 'Východ Slunce',
|
||||
'l_time' => 'Čase',
|
||||
'l_deviceValue' => 'Hodnotě zařízení',
|
||||
'l_runAt' => 'Spustit při',
|
||||
'l_resetAt' => 'Restartovat při',
|
||||
'l_affectedDevices' => 'Ovlivněná zařízení',
|
||||
'l_atDays' => 'Ve dny',
|
||||
'l_read' => 'Číst',
|
||||
'l_use' => 'Použít',
|
||||
'l_edit' => 'Upravit',
|
||||
'l_owner' => 'Vlastník',
|
||||
'l_member' => 'Člen Domácnosti',
|
||||
'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',
|
||||
't_editScene' => 'Upravit scénu',
|
||||
|
||||
't_createAutomation' => 'Vytvořit Automatizaci',
|
||||
|
||||
't_editDevice' => 'Upravit Zařízení',
|
||||
|
||||
//constants
|
||||
'temp' => 'Teplota',
|
||||
'humi' => 'Vlhkost',
|
||||
'light' => 'Světlo',
|
||||
'battery' => 'Baterie',
|
||||
'on/off' => 'Vypínač',
|
||||
|
||||
//words
|
||||
'w_title' => 'Název',
|
||||
'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
|
||||
'' => '',
|
||||
];
|
77
app/lang/en.php
Normal file
77
app/lang/en.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
$lang = [
|
||||
//Menu
|
||||
'm_home' => 'Home',
|
||||
'm_dashboard' => 'Dashboard',
|
||||
'm_settings' => 'Setting',
|
||||
'm_automatization' => 'Automatization',
|
||||
'm_scenes' => 'Scenes',
|
||||
'm_log' => 'Log',
|
||||
|
||||
//Buttons
|
||||
'b_year' => 'Year',
|
||||
'b_month' => 'Month',
|
||||
'b_week' => 'Week',
|
||||
'b_day' => 'Day',
|
||||
'b_hour' => 'Hour',
|
||||
'b_next' => 'Next',
|
||||
'b_create' => 'Create',
|
||||
'b_edit' => 'Edit',
|
||||
'b_remove' => 'Remove',
|
||||
'b_approve' => 'Approve',
|
||||
'b_disable' => 'Disable',
|
||||
'b_save' => 'Save',
|
||||
|
||||
|
||||
//labels
|
||||
'l_choseDevice' => 'Chose device:',
|
||||
'l_inHome' => 'When entering',
|
||||
'l_outHome' => 'When exiting',
|
||||
'l_sunSet' => 'Sun Set',
|
||||
'l_sunRice' => 'Sun Rise',
|
||||
'l_time' => 'Time',
|
||||
'l_deviceValue' => 'Device Valalue',
|
||||
'l_runAt' => 'Run at',
|
||||
'l_resetAt' => 'Reset at',
|
||||
'l_affectedDevices' => 'Affected devices',
|
||||
'l_atDays' => 'At days',
|
||||
'l_read' => 'Read',
|
||||
'l_use' => 'Use',
|
||||
'l_edit' => 'Edit',
|
||||
'l_owner' => 'Owner',
|
||||
'l_member' => 'Home Member',
|
||||
'l_permission' => 'Permission',
|
||||
'l_inMinutes' => 'in minutes',
|
||||
'l_sleepTime' => 'Device sleep Time',
|
||||
'l_atHome' => 'At home',
|
||||
|
||||
//Title
|
||||
't_createScene' => 'Create Scene',
|
||||
't_editScene' => 'Edit scénu',
|
||||
|
||||
't_createAutomation' => 'Create Automation',
|
||||
|
||||
't_editDevice' => 'Edit Device',
|
||||
|
||||
//constants
|
||||
'humi' => 'Humidity',
|
||||
'temp' => 'Temperature',
|
||||
'light' => 'Light',
|
||||
'battery' => 'Batteri',
|
||||
'on/off' => 'Switch',
|
||||
|
||||
//words
|
||||
'w_title' => 'Name',
|
||||
'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
|
||||
'' => '',
|
||||
];
|
0
app/logs/.gitkeep
Normal file
0
app/logs/.gitkeep
Normal file
69
app/templates/Elementum/scss/elements/_buttons.scss
Normal file
69
app/templates/Elementum/scss/elements/_buttons.scss
Normal file
@@ -0,0 +1,69 @@
|
||||
.button{
|
||||
background-color: $secondary-color;
|
||||
border: 0;
|
||||
border-radius: $control-border-radius;
|
||||
color: $base-font-color;
|
||||
padding: $control-padding-y $control-padding-x;
|
||||
transition: background-color .15s;
|
||||
height: 2.5rem;
|
||||
display: inline-block;
|
||||
line-height: 1.5;
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover{
|
||||
color: $base-font-color;
|
||||
background-color: $secondary-color-dark;
|
||||
}
|
||||
&:active{
|
||||
background-color: $secondary-color-dark;
|
||||
}
|
||||
&:focus{
|
||||
box-shadow: 0 0 3px $control-focus-color;
|
||||
}
|
||||
}
|
||||
|
||||
.button.is-small{
|
||||
padding: $control-padding-y $control-padding-x/1.5;
|
||||
height: 2rem;
|
||||
font-size: .875rem;
|
||||
}
|
||||
|
||||
.button.is-large{
|
||||
height: 3rem;
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.buttons .button{
|
||||
margin-right: .25rem;
|
||||
margin-bottom: .25rem;
|
||||
}
|
||||
|
||||
.button.is-primary{
|
||||
background-color: $primary-color;
|
||||
color: white;
|
||||
|
||||
&:hover{
|
||||
color: white;
|
||||
background-color: $primary-color-dark;
|
||||
}
|
||||
&:active{
|
||||
background-color: $primary-color-dark;
|
||||
}
|
||||
}
|
||||
|
||||
.button.is-danger{
|
||||
background-color: map-get($red-colors , '100');
|
||||
color: map-get($red-colors , '500');
|
||||
|
||||
&:hover{
|
||||
background-color: map-get($red-colors , '200');
|
||||
color: map-get($red-colors , '600');
|
||||
}
|
||||
&:active{
|
||||
background-color: map-get($red-colors , '200');
|
||||
color: map-get($red-colors , '600');
|
||||
}
|
||||
}
|
59
app/templates/automation.phtml
Normal file
59
app/templates/automation.phtml
Normal file
@@ -0,0 +1,59 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
</head>
|
||||
<body class="no-transitions">
|
||||
<div class="row no-gutters main">
|
||||
<div class="col-md-3 d-sm-none"></div>
|
||||
<div class="col-md-3 nav-container">
|
||||
<?php
|
||||
$partial = new Partial('menu');
|
||||
$partial->prepare('item','automation');
|
||||
$partial->prepare('lang',$LANG);
|
||||
$partial->render();
|
||||
?>
|
||||
</div>
|
||||
<div class="col-md-9 main-body">
|
||||
<a class="button is-primary m-1" onClick="$('#modal').removeClass('modal-container-hiden').show();"><?php echo $LANG['t_createAutomation'];?></a>
|
||||
<div class="row no-gutters">
|
||||
<?php foreach ($AUTOMATIONS as $automationId => $automationData) {
|
||||
//BUTTON
|
||||
$partial = new Partial('automationButton');
|
||||
$partial->prepare('lang',$LANG);
|
||||
$partial->prepare('automationId',$automationId);
|
||||
$partial->prepare('automationData',$automationData);
|
||||
$partial->render();
|
||||
|
||||
//EDIT
|
||||
$partial = new Partial('automationEdit');
|
||||
$partial->prepare('lang',$LANG);
|
||||
$partial->prepare('automationId',$automationId);
|
||||
$partial->prepare('automation',$automationData);
|
||||
$partial->prepare('subDevices',$SUBDEVICES);
|
||||
$partial->render();
|
||||
} ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
if (isset($_POST['modalNext'])) {
|
||||
$partial = new Partial('automationCreateFinal');
|
||||
$partial->prepare('lang',$LANG);
|
||||
$partial->prepare('subDevices',$SUBDEVICES);
|
||||
$partial->render();
|
||||
} else {
|
||||
$partial = new Partial('automationCreate');
|
||||
$partial->prepare('lang',$LANG);
|
||||
$partial->prepare('subDevices',$SUBDEVICES);
|
||||
$partial->render();
|
||||
}
|
||||
$partial = new Partial('footer');
|
||||
$partial->render();
|
||||
?>
|
||||
</body>
|
||||
</html>
|
6
app/templates/css/font-awesome.min.css
vendored
Normal file
6
app/templates/css/font-awesome.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
19
app/templates/css/loading.css
Normal file
19
app/templates/css/loading.css
Normal file
@@ -0,0 +1,19 @@
|
||||
.loader {
|
||||
border: 16px solid #f3f3f3;
|
||||
border-radius: 50%;
|
||||
border-top: 16px solid rgb(101, 30, 122);;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
-webkit-animation: spin 2s linear infinite; /* Safari */
|
||||
animation: spin 2s linear infinite;
|
||||
}
|
||||
|
||||
@-webkit-keyframes spin {
|
||||
0% { -webkit-transform: rotate(0deg); }
|
||||
100% { -webkit-transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
2971
app/templates/css/main.css
Normal file
2971
app/templates/css/main.css
Normal file
File diff suppressed because it is too large
Load Diff
44
app/templates/css/main.css.map
Normal file
44
app/templates/css/main.css.map
Normal file
File diff suppressed because one or more lines are too long
28
app/templates/css/modal.css
Normal file
28
app/templates/css/modal.css
Normal file
@@ -0,0 +1,28 @@
|
||||
.modal-container-hiden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
#modal:target {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
#modal2:target {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
#modal3:target {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
#modal4:target {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
|
||||
@media (max-width: 767px){
|
||||
.modal>.overflow {
|
||||
height: calc(100% - 44px);
|
||||
overflow-y: scroll;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
}
|
17
app/templates/css/pre.css
Normal file
17
app/templates/css/pre.css
Normal file
@@ -0,0 +1,17 @@
|
||||
pre{
|
||||
border-radius: 3px;
|
||||
border: 0px solid transparent;
|
||||
color: #d4def7;
|
||||
padding: 0.5em 0.8em;
|
||||
line-height: 1.5;
|
||||
background: #121a2b;
|
||||
width: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.rectangle-content{
|
||||
width: 100%;
|
||||
background: linear-gradient(135deg, rgba(116, 34, 189, 0.5), rgba(185, 19, 121, 0.5));
|
||||
border-radius: 8px;
|
||||
padding: .25rem !important;
|
||||
}
|
65
app/templates/dashboard.phtml
Normal file
65
app/templates/dashboard.phtml
Normal file
@@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
</head>
|
||||
<body class="no-transitions">
|
||||
<div class="row no-gutters main">
|
||||
<div class="col-md-3 d-sm-none"></div>
|
||||
<div class="col-md-3 nav-container">
|
||||
<?php
|
||||
$partial = new Partial('menu');
|
||||
$partial->prepare('item', 'dashboard');
|
||||
$partial->prepare('lang',$LANG);
|
||||
$partial->render();
|
||||
?>
|
||||
</div>
|
||||
<div class="col-md-9 main-body">
|
||||
<a onClick="$('#modal').removeClass('modal-container-hiden').show();" class="button is-primary m-1">Add Device</a>
|
||||
<div class="row no-gutters">
|
||||
<?php foreach ($DASHBOARD as $dashboardItemId => $dashboardItemData) {
|
||||
$partialDeviceButton = new Partial('dashboardButton');
|
||||
$partialDeviceButton->prepare('dashboardItemData', $dashboardItemData);
|
||||
|
||||
$partialDeviceButton->render();
|
||||
} ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-container modal-container-hiden" id="modal">
|
||||
<div class="modal">
|
||||
<div class="close">
|
||||
<i class="fa fa-times"></i>
|
||||
</div>
|
||||
<h4 class="mb-4">Modal bitch</h4>
|
||||
<form method="post">
|
||||
<div class="field px-2">
|
||||
<div class="label">Zvolte zařízení:</div>
|
||||
<select class="input" name="devices[]" multiple>
|
||||
<?php foreach ($SUBDEVICES as $subDeviceKey => $subDeviceValue){ ?>
|
||||
<option value="<?php echo $subDeviceKey; ?>"><?php echo $subDeviceValue['name'] . '[' . $subDeviceValue['type'] . ']'; ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<input type="submit" class="button" name="modalFinal" value="Next"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if (isset($_POST['deviceId'])) {
|
||||
$partial = new Partial('deviceEdit');
|
||||
$partial->prepare('DEVICEDATA', $DEVICEDATA);
|
||||
|
||||
$partial->render();
|
||||
}
|
||||
$partial = new Partial('footer');
|
||||
$partial->render();
|
||||
?>
|
||||
</body>
|
||||
</html>
|
BIN
app/templates/fonts/FontAwesome.otf
Normal file
BIN
app/templates/fonts/FontAwesome.otf
Normal file
Binary file not shown.
BIN
app/templates/fonts/Metropolis-Medium.otf
Normal file
BIN
app/templates/fonts/Metropolis-Medium.otf
Normal file
Binary file not shown.
BIN
app/templates/fonts/Metropolis-Regular.otf
Normal file
BIN
app/templates/fonts/Metropolis-Regular.otf
Normal file
Binary file not shown.
BIN
app/templates/fonts/Metropolis-SemiBold.otf
Normal file
BIN
app/templates/fonts/Metropolis-SemiBold.otf
Normal file
Binary file not shown.
BIN
app/templates/fonts/fontawesome-webfont.eot
Normal file
BIN
app/templates/fonts/fontawesome-webfont.eot
Normal file
Binary file not shown.
2671
app/templates/fonts/fontawesome-webfont.svg
Normal file
2671
app/templates/fonts/fontawesome-webfont.svg
Normal file
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 434 KiB |
BIN
app/templates/fonts/fontawesome-webfont.ttf
Normal file
BIN
app/templates/fonts/fontawesome-webfont.ttf
Normal file
Binary file not shown.
BIN
app/templates/fonts/fontawesome-webfont.woff
Normal file
BIN
app/templates/fonts/fontawesome-webfont.woff
Normal file
Binary file not shown.
BIN
app/templates/fonts/fontawesome-webfont.woff2
Normal file
BIN
app/templates/fonts/fontawesome-webfont.woff2
Normal file
Binary file not shown.
84
app/templates/home.phtml
Normal file
84
app/templates/home.phtml
Normal file
@@ -0,0 +1,84 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
</head>
|
||||
<body class="no-transitions">
|
||||
<div class="row no-gutters main">
|
||||
<div class="col-md-3 d-sm-none"></div>
|
||||
<div class="col-md-3 nav-container">
|
||||
<?php
|
||||
$partial = new Partial('menu');
|
||||
$partial->prepare('item', 'home');
|
||||
$partial->prepare('lang',$LANG);
|
||||
$partial->render();
|
||||
?>
|
||||
</div>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.bundle.min.js"></script>
|
||||
|
||||
<div class="col-md-9 main-body">
|
||||
<div class="label m-1">
|
||||
<?php
|
||||
if ($USERSATHOME != "") {
|
||||
echo $LANG['l_atHome'] . ': ' . $USERSATHOME;
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<select class="select m-1" name="room">
|
||||
<option value="all">All</option>
|
||||
<?php foreach ($ROOMS as $key => $room) {
|
||||
if ($room['device_count'] > 0) { ?>
|
||||
<option value="<?php echo $room['room_id']?>"><?php echo $room['name'] ?></option>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</select>
|
||||
<div class="row no-gutters">
|
||||
<?php foreach ($DATA as $roomId => $room) { ?>
|
||||
<?php foreach ($room['devices'] as $deviceId => $device) { ?>
|
||||
<?php foreach ($device['subDevices'] as $subDeviceKey => $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('lang',$LANG);
|
||||
|
||||
$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('lang',$LANG);
|
||||
|
||||
$partialEdit->render();
|
||||
}
|
||||
}
|
||||
} ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
$partial = new Partial('footer');
|
||||
$partial->render();
|
||||
?>
|
||||
</body>
|
||||
</html>
|
BIN
app/templates/images/icon-192x192.png
Normal file
BIN
app/templates/images/icon-192x192.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.1 KiB |
BIN
app/templates/images/icon-512x512.png
Normal file
BIN
app/templates/images/icon-512x512.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
2
app/templates/js/jquery.js
vendored
Normal file
2
app/templates/js/jquery.js
vendored
Normal file
File diff suppressed because one or more lines are too long
182
app/templates/js/jquery.redirect.js
Normal file
182
app/templates/js/jquery.redirect.js
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
jQuery Redirect v1.1.3
|
||||
|
||||
Copyright (c) 2013-2018 Miguel Galante
|
||||
Copyright (c) 2011-2013 Nemanja Avramovic, www.avramovic.info
|
||||
|
||||
Licensed under CC BY-SA 4.0 License: http://creativecommons.org/licenses/by-sa/4.0/
|
||||
|
||||
This means everyone is allowed to:
|
||||
|
||||
Share - copy and redistribute the material in any medium or format
|
||||
Adapt - remix, transform, and build upon the material for any purpose, even commercially.
|
||||
Under following conditions:
|
||||
|
||||
Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
|
||||
ShareAlike - If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
|
||||
*/
|
||||
;(function ($) {
|
||||
'use strict';
|
||||
|
||||
//Defaults configuration
|
||||
var defaults = {
|
||||
url: null,
|
||||
values: null,
|
||||
method: "POST",
|
||||
target: null,
|
||||
traditional: false,
|
||||
redirectTop: false
|
||||
};
|
||||
|
||||
/**
|
||||
* jQuery Redirect
|
||||
* @param {string} url - Url of the redirection
|
||||
* @param {Object} values - (optional) An object with the data to send. If not present will look for values as QueryString in the target url.
|
||||
* @param {string} method - (optional) The HTTP verb can be GET or POST (defaults to POST)
|
||||
* @param {string} target - (optional) The target of the form. "_blank" will open the url in a new window.
|
||||
* @param {boolean} traditional - (optional) This provides the same function as jquery's ajax function. The brackets are omitted on the field name if its an array. This allows arrays to work with MVC.net among others.
|
||||
* @param {boolean} redirectTop - (optional) If its called from a iframe, force to navigate the top window.
|
||||
*//**
|
||||
* jQuery Redirect
|
||||
* @param {string} opts - Options object
|
||||
* @param {string} opts.url - Url of the redirection
|
||||
* @param {Object} opts.values - (optional) An object with the data to send. If not present will look for values as QueryString in the target url.
|
||||
* @param {string} opts.method - (optional) The HTTP verb can be GET or POST (defaults to POST)
|
||||
* @param {string} opts.target - (optional) The target of the form. "_blank" will open the url in a new window.
|
||||
* @param {boolean} opts.traditional - (optional) This provides the same function as jquery's ajax function. The brackets are omitted on the field name if its an array. This allows arrays to work with MVC.net among others.
|
||||
* @param {boolean} opts.redirectTop - (optional) If its called from a iframe, force to navigate the top window.
|
||||
*/
|
||||
$.redirect = function (url, values, method, target, traditional, redirectTop) {
|
||||
var opts = url;
|
||||
if (typeof url !== "object") {
|
||||
var opts = {
|
||||
url: url,
|
||||
values: values,
|
||||
method: method,
|
||||
target: target,
|
||||
traditional: traditional,
|
||||
redirectTop: redirectTop
|
||||
};
|
||||
}
|
||||
|
||||
var config = $.extend({}, defaults, opts);
|
||||
var generatedForm = $.redirect.getForm(config.url, config.values, config.method, config.target, config.traditional);
|
||||
$('body', config.redirectTop ? window.top.document : undefined).append(generatedForm.form);
|
||||
generatedForm.submit();
|
||||
generatedForm.form.remove();
|
||||
};
|
||||
|
||||
$.redirect.getForm = function (url, values, method, target, traditional) {
|
||||
method = (method && ["GET", "POST", "PUT", "DELETE"].indexOf(method.toUpperCase()) !== -1) ? method.toUpperCase() : 'POST';
|
||||
|
||||
url = url.split("#");
|
||||
var hash = url[1] ? ("#" + url[1]) : "";
|
||||
url = url[0];
|
||||
|
||||
if (!values) {
|
||||
var obj = $.parseUrl(url);
|
||||
url = obj.url;
|
||||
values = obj.params;
|
||||
}
|
||||
|
||||
values = removeNulls(values);
|
||||
|
||||
var form = $('<form>')
|
||||
.attr("method", method)
|
||||
.attr("action", url + hash);
|
||||
|
||||
|
||||
if (target) {
|
||||
form.attr("target", target);
|
||||
}
|
||||
|
||||
var submit = form[0].submit;
|
||||
iterateValues(values, [], form, null, traditional);
|
||||
|
||||
return { form: form, submit: function () { submit.call(form[0]); } };
|
||||
}
|
||||
|
||||
//Utility Functions
|
||||
/**
|
||||
* Url and QueryString Parser.
|
||||
* @param {string} url - a Url to parse.
|
||||
* @returns {object} an object with the parsed url with the following structure {url: URL, params:{ KEY: VALUE }}
|
||||
*/
|
||||
$.parseUrl = function (url) {
|
||||
|
||||
if (url.indexOf('?') === -1) {
|
||||
return {
|
||||
url: url,
|
||||
params: {}
|
||||
};
|
||||
}
|
||||
var parts = url.split('?'),
|
||||
query_string = parts[1],
|
||||
elems = query_string.split('&');
|
||||
url = parts[0];
|
||||
|
||||
var i, pair, obj = {};
|
||||
for (i = 0; i < elems.length; i += 1) {
|
||||
pair = elems[i].split('=');
|
||||
obj[pair[0]] = pair[1];
|
||||
}
|
||||
|
||||
return {
|
||||
url: url,
|
||||
params: obj
|
||||
};
|
||||
};
|
||||
|
||||
//Private Functions
|
||||
var getInput = function (name, value, parent, array, traditional) {
|
||||
var parentString;
|
||||
if (parent.length > 0) {
|
||||
parentString = parent[0];
|
||||
var i;
|
||||
for (i = 1; i < parent.length; i += 1) {
|
||||
parentString += "[" + parent[i] + "]";
|
||||
}
|
||||
|
||||
if (array) {
|
||||
if (traditional)
|
||||
name = parentString;
|
||||
else
|
||||
name = parentString + "[" + name + "]";
|
||||
} else {
|
||||
name = parentString + "[" + name + "]";
|
||||
}
|
||||
}
|
||||
|
||||
return $("<input>").attr("type", "hidden")
|
||||
.attr("name", name)
|
||||
.attr("value", value);
|
||||
};
|
||||
|
||||
var iterateValues = function (values, parent, form, isArray, traditional) {
|
||||
var i, iterateParent = [];
|
||||
Object.keys(values).forEach(function (i) {
|
||||
if (typeof values[i] === "object") {
|
||||
iterateParent = parent.slice();
|
||||
iterateParent.push(i);
|
||||
iterateValues(values[i], iterateParent, form, Array.isArray(values[i]), traditional);
|
||||
} else {
|
||||
form.append(getInput(i, values[i], parent, isArray, traditional));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var removeNulls = function (values) {
|
||||
var propNames = Object.getOwnPropertyNames(values);
|
||||
for (var i = 0; i < propNames.length; i++) {
|
||||
var propName = propNames[i];
|
||||
if (values[propName] === null || values[propName] === undefined) {
|
||||
delete values[propName];
|
||||
} else if (typeof values[propName] === 'object') {
|
||||
values[propName] = removeNulls(values[propName]);
|
||||
} else if (values[propName].length < 1) {
|
||||
delete values[propName];
|
||||
}
|
||||
}
|
||||
return values;
|
||||
};
|
||||
}(window.jQuery || window.Zepto || window.jqlite));
|
73
app/templates/js/post.js
Normal file
73
app/templates/js/post.js
Normal file
@@ -0,0 +1,73 @@
|
||||
function ajaxPostSimple(path, params, reload = false) {
|
||||
navigator.vibrate([200]);
|
||||
$.ajax({
|
||||
url: path,
|
||||
type: 'POST',
|
||||
data: params,
|
||||
success: function(msg){
|
||||
console.log(msg);
|
||||
if (reload){
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
error: function (request, status, error) {
|
||||
console.log('0');
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function ajaxPost(path, params, self, reload = false) {
|
||||
navigator.vibrate([200]);
|
||||
$.ajax({
|
||||
url: path,
|
||||
type: 'POST',
|
||||
data: params,
|
||||
success: function(msg){
|
||||
if (msg != '' && msg != 1){
|
||||
$(self).find('.content').addClass( "loader" );
|
||||
$(self).find('.row').hide();
|
||||
waitForExecution(params, self, msg);
|
||||
} else {
|
||||
|
||||
}
|
||||
console.log(msg);
|
||||
if (reload){
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
error: function (request, status, error) {
|
||||
console.log('0');
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function waitForExecution(params, elements, msg_state){
|
||||
console.log('Waiting FOR Executed');
|
||||
var interval = setInterval(
|
||||
function(){
|
||||
$.ajax({
|
||||
url: 'ajax',
|
||||
type: 'POST',
|
||||
data: {
|
||||
lastRecord:'',
|
||||
subDevice_id : params['subDevice_id']
|
||||
},
|
||||
success: function(msg){
|
||||
if (msg == 1){
|
||||
$(elements).find('.text-right').text(msg_state);
|
||||
$(elements).find('.content').removeClass( "loader" );
|
||||
$(elements).find('.row').show();
|
||||
console.log('Executed');
|
||||
clearInterval(interval);
|
||||
}
|
||||
console.log('Waiting FOR Executed');
|
||||
console.log(msg);
|
||||
},
|
||||
error: function (request, status, error) {
|
||||
console.log('0');
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
}
|
272
app/templates/js/script.js
Normal file
272
app/templates/js/script.js
Normal file
@@ -0,0 +1,272 @@
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', () => {
|
||||
navigator.serviceWorker.register('serviceWorker.js')
|
||||
.then(registration => {
|
||||
console.log('Service Worker is registered', registration);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('Registration failed:', err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$('select').change(function(e) {
|
||||
console.log($(this).val());
|
||||
if( $(this).val() == 'time') {
|
||||
|
||||
$('#atTime').prop( "disabled", false );
|
||||
|
||||
$('#atDeviceValue').prop( "disabled", true );
|
||||
$('#atDeviceValueInt').prop( "disabled", true );
|
||||
} else if( $(this).val() == 'atDeviceValue') {
|
||||
|
||||
$('#atDeviceValue').prop( "disabled", false );
|
||||
$('#atDeviceValueInt').prop( "disabled", false );
|
||||
|
||||
$('#atTime').prop( "disabled", true );
|
||||
}
|
||||
});
|
||||
|
||||
var pressTimer;
|
||||
var touch = 0;
|
||||
var touchSubId = "";
|
||||
$("div.square-content").on('touchend', function (e){
|
||||
clearTimeout(pressTimer);
|
||||
});
|
||||
|
||||
$("div.square-content").on('touchstart', function (eTarget) {
|
||||
navigator.vibrate([500]);
|
||||
var id = '';
|
||||
|
||||
var windowLoc = $(location).attr('pathname');
|
||||
windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
|
||||
console.log(windowLoc);
|
||||
if (windowLoc == "/") {
|
||||
id = $(this).attr('id').replace('device-', '');
|
||||
} else if (windowLoc == "/scene") {
|
||||
id = $(this).attr('id').replace('scene-', '');
|
||||
} else if (windowLoc == "/automation") {
|
||||
id = $(this).attr('id').replace('automation-', '');
|
||||
}
|
||||
|
||||
var subId = $(this).attr('data-sub-device-id');
|
||||
|
||||
touch++;
|
||||
if(touch == 2 && touchSubId == subId){
|
||||
console.log("Detail");
|
||||
if (windowLoc == "/") {
|
||||
$("#modal-detail-"+subId).removeClass('modal-container-hiden').show();
|
||||
ajaxChart(subId);
|
||||
} else if (windowLoc == "/scene") {
|
||||
|
||||
} else if (windowLoc == "/automation") {
|
||||
}
|
||||
touch = 0;
|
||||
touchSubId = "";
|
||||
return;
|
||||
}
|
||||
touchSubId = subId;
|
||||
|
||||
pressTimer = window.setTimeout(function (e) {
|
||||
console.log("Setting");
|
||||
$("#modal-setting-"+id).removeClass('modal-container-hiden').show();
|
||||
touch = 0;
|
||||
}, 500);
|
||||
});
|
||||
|
||||
$("div.square-content").mousedown(function(e) {
|
||||
if (event.which == 3) {
|
||||
var windowLoc = $(location).attr('pathname');
|
||||
windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
|
||||
console.log(windowLoc);
|
||||
var id = null;
|
||||
if (windowLoc == "/") {
|
||||
id = $(this).attr('id').replace('device-', '');
|
||||
} else if (windowLoc == "/scene") {
|
||||
id = $(this).attr('id').replace('scene-', '');
|
||||
} else if (windowLoc == "/automation") {
|
||||
id = $(this).attr('id').replace('automation-', '');
|
||||
}
|
||||
$("#modal-setting-"+id).removeClass('modal-container-hiden').show();
|
||||
console.log("Setting");
|
||||
console.log("modal" + id);
|
||||
}
|
||||
});
|
||||
|
||||
$(".close").on('click', function (e) {
|
||||
var a = $(this).parent().parent();
|
||||
a.hide();
|
||||
});
|
||||
|
||||
$(this).bind("contextmenu", function(e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("div.square-content").on('dblclick', function (eTarget) {
|
||||
windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
|
||||
if (windowLoc == "/") {
|
||||
console.log("Detail");
|
||||
var subId = $(this).attr('data-sub-device-id');
|
||||
ajaxChart(subId);
|
||||
$("#modal-detail-"+subId).removeClass('modal-container-hiden').show();
|
||||
}
|
||||
});
|
||||
|
||||
$("input#sleepTime").change(function() {
|
||||
console.log("Input text changed!");
|
||||
});
|
||||
|
||||
var element = $('div.delete');
|
||||
element.hide();
|
||||
$("a#remove").on('click', function (e) {
|
||||
console.log("Show/Hide Button");
|
||||
var element = $('div.delete');
|
||||
element.toggle();
|
||||
});
|
||||
|
||||
function ajaxChart(id, period = 'day', group = 'hour'){
|
||||
$.ajax({
|
||||
url: 'ajax',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
"subDevice": id,
|
||||
"action": 'chart',
|
||||
"period": period,
|
||||
"group": group
|
||||
},
|
||||
success: function(data){
|
||||
console.log('ID: ',id, 'DATA: ', data);
|
||||
var ctx = document.getElementById('canvas-'+id).getContext('2d');
|
||||
var myChart = new Chart(ctx, data);
|
||||
},
|
||||
error: function (request, status, error) {
|
||||
console.log("ERROR ajaxChart():", request, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//select room on load
|
||||
var windowLoc = $(location).attr('pathname');
|
||||
windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
|
||||
console.log();
|
||||
if (windowLoc == "/") {
|
||||
var selectRoomId = localStorage.getItem("selectedRoomId");
|
||||
console.log('Saved Selected Room ID '+ selectRoomId);
|
||||
$('[name="room"]').val(selectRoomId);
|
||||
$('.device-button').each(function(){
|
||||
if (selectRoomId != 'all'){
|
||||
if($(this).data('room-id') != selectRoomId){
|
||||
$(this).hide();
|
||||
} else {
|
||||
$(this).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//Room selector
|
||||
$( '[name="room"]' ).change(function (e) {
|
||||
console.log('Selected Room ID ' + this.value)
|
||||
var roomId = this.value;
|
||||
localStorage.setItem("selectedRoomId", roomId);
|
||||
$('.device-button').show();
|
||||
if (roomId != 'all'){
|
||||
$('.device-button').each(function(){
|
||||
if($(this).data('room-id') != roomId){
|
||||
$(this).hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// var windowLoc = $(location).attr('pathname');
|
||||
// windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
|
||||
// console.log();
|
||||
// if (windowLoc == "/") {
|
||||
// var autoUpdate = setInterval(function(){
|
||||
// $.ajax({
|
||||
// url: 'ajax',
|
||||
// type: 'POST',
|
||||
// dataType: 'json',
|
||||
// data: {
|
||||
// "action": 'getState'
|
||||
// },
|
||||
// success: function(data){
|
||||
// // console.log('DATA: ', data);
|
||||
// for (const key in data) {
|
||||
// if (data.hasOwnProperty(key)) {
|
||||
// const device = data[key];
|
||||
// $('[data-sub-device-id="'+key+'"]')
|
||||
// .find('.device-button-value')
|
||||
// .text(device['value'])
|
||||
// .attr('title',device['time'])
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// error: function (request, status, error) {
|
||||
// console.log("ERROR ajaxChart():", request, error);
|
||||
// }
|
||||
// });
|
||||
// },2000);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
//Graphs
|
||||
$('.graph-period').on('click', function (e) {
|
||||
var subId = $(this).attr('data-sub-device-id');
|
||||
var period = $(this).attr('data-period');
|
||||
var groupBy = $(this).attr('data-group');
|
||||
ajaxChart(subId, period, groupBy);
|
||||
});
|
||||
|
||||
$( "button[name=remove]" ).click(function(e) {
|
||||
if (confirm('Are you shure ?')) {
|
||||
var windowLoc = $(location).attr('pathname');
|
||||
windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
|
||||
console.log(windowLoc);
|
||||
var id = null;
|
||||
if (windowLoc == "/scene") {
|
||||
id = $(this).data('scene-id');
|
||||
$("#scene-"+id+"-content").remove();
|
||||
} else if (windowLoc == "/automation") {
|
||||
id = $(this).data('automation-id');
|
||||
$("#automation-"+id+"-content").remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
20
app/templates/loading.css
Normal file
20
app/templates/loading.css
Normal file
@@ -0,0 +1,20 @@
|
||||
.loader {
|
||||
border: 16px solid #f3f3f3;
|
||||
border-radius: 50%;
|
||||
border-top: 16px solid #3498db;
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
-webkit-animation: spin 2s linear infinite; /* Safari */
|
||||
animation: spin 2s linear infinite;
|
||||
}
|
||||
|
||||
/* Safari */
|
||||
@-webkit-keyframes spin {
|
||||
0% { -webkit-transform: rotate(0deg); }
|
||||
100% { -webkit-transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
64
app/templates/log.phtml
Normal file
64
app/templates/log.phtml
Normal file
@@ -0,0 +1,64 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
</head>
|
||||
<body class="no-transitions">
|
||||
<div class="row no-gutters main">
|
||||
<div class="col-md-3 d-sm-none"></div>
|
||||
<div class="col-md-3 nav-container">
|
||||
<?php
|
||||
$partial = new Partial('menu');
|
||||
$partial->prepare('item', 'log');
|
||||
$partial->prepare('lang',$LANG);
|
||||
$partial->render();
|
||||
?>
|
||||
</div>
|
||||
<div class="col-md-9 main-body">
|
||||
<div class="col-12 col-sm-9 mx-auto mt-4">
|
||||
<form method="post" action="">
|
||||
<div class="field">
|
||||
<div class="label">LOG:CZ</div>
|
||||
<select class="input" name="LogFile">
|
||||
<?php foreach ($LOGSFILES as $key => $value) { ?>
|
||||
<option value="<?php echo $value; ?>"><?php echo $value; ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
<input type="submit" class="button" name="selectFile" value="file"/>
|
||||
</div>
|
||||
</form>
|
||||
<?php
|
||||
if (isset($_POST['LogFile'])) {
|
||||
$file_lines = file('./app/logs/' . $_POST['LogFile']);
|
||||
echo '<pre>';
|
||||
foreach ($file_lines as $line) {
|
||||
echo $line;
|
||||
}
|
||||
echo '</pre>';
|
||||
}
|
||||
?>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$partial = new Partial('footer');
|
||||
$partial->render();
|
||||
//TODO js do main.js
|
||||
?>
|
||||
<script>
|
||||
$( "#enable-features" ).click(function(e) {
|
||||
var selectRoomId = localStorage.getItem("enableFeature");
|
||||
if (selectRoomId){
|
||||
localStorage.setItem("enableFeature", true);
|
||||
}else {
|
||||
localStorage.setItem("enableFeature", false);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
37
app/templates/login.phtml
Normal file
37
app/templates/login.phtml
Normal file
@@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
</head>
|
||||
<body class="no-transitions">
|
||||
<div class="modal-container">
|
||||
<div class="modal">
|
||||
<h4 class="mb-4">Login</h4>
|
||||
<form method="post">
|
||||
<div class="field">
|
||||
<div class="label">Name:</div>
|
||||
<input class="input" type="text" name="username" placeholder="Jméno.."/>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Password:</div>
|
||||
<input class="input" type="password" name="password" placeholder="Heslo.."/>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Remember me:</div>
|
||||
<input class="" type="checkbox" name="remember" value="true"/>
|
||||
</div>
|
||||
<input type="submit" class="button" name="login" value="Login"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$partial = new Partial('footer');
|
||||
$partial->render();
|
||||
?>
|
||||
</body>
|
||||
</html>
|
54
app/templates/part/automationButton.phtml
Normal file
54
app/templates/part/automationButton.phtml
Normal file
@@ -0,0 +1,54 @@
|
||||
<div class="col-12 col-md-6 col-xl-4 square-wrap">
|
||||
<div class="rectangle-2">
|
||||
<div class="square-content double <?php echo ($AUTOMATIONDATA['active'] == 0 ? 'paused' : ''); ?>" id="automation-<?php echo $AUTOMATIONID; ?>">
|
||||
<div class="row">
|
||||
<div class="col-1">
|
||||
<h5 class="fa">
|
||||
<?php
|
||||
//echo $AUTOMATIONDATA['ifSomething'];
|
||||
switch ($AUTOMATIONDATA['ifSomething']) {
|
||||
case 'sunSet':
|
||||
echo'';
|
||||
break;
|
||||
|
||||
case 'sunRise':
|
||||
echo' ';
|
||||
break;
|
||||
|
||||
case 'inHome':
|
||||
echo'';
|
||||
break;
|
||||
|
||||
case 'outHome':
|
||||
echo'';
|
||||
break;
|
||||
|
||||
case 'outDevice':
|
||||
echo'';
|
||||
break;
|
||||
|
||||
default:
|
||||
echo'';
|
||||
break;
|
||||
}
|
||||
?>
|
||||
</h5>
|
||||
</div>
|
||||
<div class="col">
|
||||
<h5 class="text-right break-all">
|
||||
<?php
|
||||
if (!in_array($AUTOMATIONDATA['ifSomething'], ["sunRise", "sunSet"])) {
|
||||
echo $AUTOMATIONDATA['ifSomething'];
|
||||
}
|
||||
?>
|
||||
</h5>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<?php echo implode(', ',$AUTOMATIONDATA['onDays']);?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
66
app/templates/part/automationCreate.phtml
Normal file
66
app/templates/part/automationCreate.phtml
Normal file
@@ -0,0 +1,66 @@
|
||||
<div class="modal-container modal-container-hiden" id="modal">
|
||||
<div class="modal">
|
||||
<a href=""><i class="fa fa-times close"></i></a>
|
||||
<h4 class="mb-4"><?php echo $LANG['t_createAutomation']?></h4>
|
||||
<form method="post">
|
||||
<div class="field">
|
||||
<div class="label"><?php echo $LANG['l_runAt']?></div>
|
||||
<div class="field">
|
||||
<select class="input" name="atSelector" id="valueSelector" required>
|
||||
<option value="sunSet"><?php echo $LANG['l_sunSet']?></option>
|
||||
<option value="sunRise"><?php echo $LANG['l_sunRice']?></option>
|
||||
<option value="inHome"><?php echo $LANG['l_inHome']?></option>
|
||||
<option value="outHome"><?php echo $LANG['l_outHome']?></option>
|
||||
<option value="time"><?php echo $LANG['l_time']?></option>
|
||||
<option value="noOneHome"><?php echo $LANG['l_time']?></option>
|
||||
<option value="atDeviceValue"><?php echo $LANG['l_deviceValue'];?></option>
|
||||
<option value="noOneHome"><?php echo $LANG['w_noOne'] . ' ' . $LANG['w_neni'] . ' ' . $LANG['w_home'];?></option>
|
||||
<option value="someOneHome"><?php echo $LANG['w_someOne'] . ' ' . $LANG['w_is'] . ' ' . $LANG['w_home'];?></option>
|
||||
</select>
|
||||
<input class="input" type="time" name="atTime" id="atTime" disabled/>
|
||||
<select class="input" name="atDeviceValue" id="atDeviceValue" disabled>
|
||||
<?php foreach ($SUBDEVICES as $subDeviceKey => $subDeviceValue){ ?>
|
||||
<option value="<?php echo $subDeviceKey; ?>"><?php echo $subDeviceValue['name']; ?>[<?php echo $subDeviceValue['type']; ?>]</option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
=
|
||||
<input class="input" type="num" name="atDeviceValueInt" id="atDeviceValueInt" required disabled/>
|
||||
</div>
|
||||
|
||||
<div class="label"><?php echo $LANG['l_affectedDevices']?></div>
|
||||
<div class="field">
|
||||
<select class="input" name="devices[]" multiple>
|
||||
<?php foreach ($SUBDEVICES as $subDeviceKey => $subDeviceValue){
|
||||
if ($subDeviceValue['type'] != 'on/off') continue;?>
|
||||
<option value="<?php echo $subDeviceValue['masterDevice']; ?>"><?php echo $subDeviceValue['name']; ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
<div class="label"><?php echo $LANG['l_atDays']?></div>
|
||||
<div class="field">
|
||||
<input type="checkbox" name="day[]" value="mon"/> Pondělí
|
||||
</div>
|
||||
<div class="field">
|
||||
<input type="checkbox" name="day[]" value="tue"/> Úterý
|
||||
</div>
|
||||
<div class="field">
|
||||
<input type="checkbox" name="day[]" value="wed"/> Středa
|
||||
</div>
|
||||
<div class="field">
|
||||
<input type="checkbox" name="day[]" value="thu"/> Čtvrtek
|
||||
</div>
|
||||
<div class="field">
|
||||
<input type="checkbox" name="day[]" value="fri"/> Pátek
|
||||
</div>
|
||||
<div class="field">
|
||||
<input type="checkbox" name="day[]" value="sat"/> Sobota
|
||||
</div>
|
||||
<div class="field">
|
||||
<input type="checkbox" name="day[]" value="sun"/> Neděle
|
||||
</div>
|
||||
</div>
|
||||
<input type="submit" class="button" name="modalNext" value="<?php echo $LANG['b_next']?>"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
39
app/templates/part/automationCreateFinal.phtml
Normal file
39
app/templates/part/automationCreateFinal.phtml
Normal file
@@ -0,0 +1,39 @@
|
||||
<div class="modal-container" id="modal">
|
||||
<div class="modal">
|
||||
<a href=""><i class="fa fa-times close"></i></a>
|
||||
<h4 class="mb-4"><?php echo $LANG['t_createAutomation']?></h4>
|
||||
<form method="post">
|
||||
<div class="field">
|
||||
<input type="hidden" name="atSelector" value="<?php echo $_POST['atSelector']; ?>" required/>
|
||||
<input type="hidden" name="atSelectorValue" value="<?php if (isset($_POST['atTime'])) {
|
||||
echo $_POST['atTime'];
|
||||
} else 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,
|
||||
]);
|
||||
echo htmlspecialchars($json);
|
||||
}
|
||||
else {
|
||||
echo $_POST['atSelector'];
|
||||
} ?>" required/>
|
||||
<input type="hidden" name="atDays" value="<?php echo htmlspecialchars(($_POST['day'] != '' ? json_encode($_POST['day']) : '')); ?>" required/>
|
||||
<?php foreach ($_POST['devices'] as $value) { ?>
|
||||
<?php $deviceData = DeviceManager::getDeviceById($value); ?>
|
||||
<div class="label"><?php echo $deviceData['name'];?></div>
|
||||
<select class="input" name="device[<?php echo $deviceData['device_id'];?>]">
|
||||
<option value="1">ON</option>
|
||||
<option value="0">OFF</option>
|
||||
</select>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<input type="submit" class="button" name="modalFinal" value="Next"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
98
app/templates/part/automationEdit.phtml
Normal file
98
app/templates/part/automationEdit.phtml
Normal file
@@ -0,0 +1,98 @@
|
||||
<div class="modal-container modal-container-hiden" id="modal-setting-<?php echo $AUTOMATIONID; ?>">
|
||||
<div class="modal">
|
||||
<div class="close">
|
||||
<i class="fa fa-times"></i>
|
||||
</div>
|
||||
<h4 class="mb-4"><?php echo $LANG['t_createAutomation']?></h4>
|
||||
<form method="post">
|
||||
<div class="field">
|
||||
<div class="label"><?php echo $LANG['l_runAt']?></div>
|
||||
<div class="field">
|
||||
<?php //TODO Dodělat identifikaci pro Selctor události a selector času zařízení hodnoty ?>
|
||||
<select class="input" name="atSelector" id="valueSelector" required>
|
||||
<option value="sunSet" <?php ECHO ($AUTOMATION['ifSomething'] == "sunSet" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_sunSet']?></option>
|
||||
<option value="sunRise" <?php ECHO ($AUTOMATION['ifSomething'] == "sunRise" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_sunRice']?></option>
|
||||
<option value="inHome" <?php ECHO ($AUTOMATION['ifSomething'] == "inHome" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_inHome']?></option>
|
||||
<option value="outHome" <?php ECHO ($AUTOMATION['ifSomething'] == "outHome" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_outHome']?></option>
|
||||
<option value="time" <?php ECHO ($AUTOMATION['ifSomething'] == "time" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_time']?></option>
|
||||
<option value="atDeviceValue" <?php ECHO ($AUTOMATION['ifSomething'] == "atDeviceValue" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_deviceValue']?></option>
|
||||
</select>
|
||||
<input class="input" type="time" name="atTime" id="atTime" <?php ECHO ($AUTOMATION['ifSomething'] == "time" ? '' : 'disabled'); ?>/>
|
||||
<select class="input" name="atDeviceValue" id="atDeviceValue" <?php ECHO ($AUTOMATION['ifSomething'] == "atDeviceValue" ? '' : 'disabled'); ?>>
|
||||
<?php foreach ($SUBDEVICES as $subDeviceKey => $subDeviceValue){ ?>
|
||||
<option value="<?php echo $subDeviceKey; ?>"><?php echo $subDeviceValue['name']; ?>[<?php echo $subDeviceValue['type']; ?>]</option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
=
|
||||
<input class="input" type="num" name="atDeviceValueInt" id="atDeviceValueInt" required <?php ECHO ($AUTOMATION['ifSomething'] == "atDeviceValue" ? '' : 'disabled'); ?>/>
|
||||
</div>
|
||||
|
||||
<div class="label"><?php echo $LANG['l_resetAt']?></div>
|
||||
<div class="field">
|
||||
<?php //TODO Dodělat identifikaci pro Selctor události a selector času zařízení hodnoty ?>
|
||||
<select class="input" name="restartAtSelector" id="valueSelector" required>
|
||||
<option value="sunSet" <?php ECHO ($AUTOMATION['ifSomething'] == "sunSet" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_sunSet']?></option>
|
||||
<option value="sunRise" <?php ECHO ($AUTOMATION['ifSomething'] == "sunRise" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_sunRice']?></option>
|
||||
<option value="inHome" <?php ECHO ($AUTOMATION['ifSomething'] == "inHome" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_inHome']?></option>
|
||||
<option value="outHome" <?php ECHO ($AUTOMATION['ifSomething'] == "outHome" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_outHome']?></option>
|
||||
<option value="time" <?php ECHO ($AUTOMATION['ifSomething'] == "time" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_time']?></option>
|
||||
<option value="atDeviceValue" <?php ECHO ($AUTOMATION['ifSomething'] == "atDeviceValue" ? 'selected="selected"' : ''); ?>><?php echo $LANG['l_deviceValue']?></option>
|
||||
</select>
|
||||
<input class="input" type="time" name="restartAtTime" id="atTime" <?php ECHO ($AUTOMATION['ifSomething'] == "time" ? '' : 'disabled'); ?>/>
|
||||
<select class="input" name="restartAtDeviceValue" id="atDeviceValue" <?php ECHO ($AUTOMATION['ifSomething'] == "atDeviceValue" ? '' : 'disabled'); ?>>
|
||||
<?php foreach ($SUBDEVICES as $subDeviceKey => $subDeviceValue){ ?>
|
||||
<option value="<?php echo $subDeviceKey; ?>"><?php echo $subDeviceValue['name']; ?>[<?php echo $subDeviceValue['type']; ?>]</option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
=
|
||||
<input class="input" type="num" name="restartAtDeviceValueInt" id="atDeviceValueInt" required <?php ECHO ($AUTOMATION['ifSomething'] == "atDeviceValue" ? '' : 'disabled'); ?>/>
|
||||
</div>
|
||||
|
||||
<div class="label"><?php echo $LANG['l_affectedDevices'];?></div>
|
||||
<div class="field">
|
||||
<div class="field px-2">
|
||||
<?php
|
||||
$i = 0;
|
||||
foreach($AUTOMATION['doSomething'] as $subDeviceId => $subDeviceData){ ?>
|
||||
<div id="automation-<?php echo $AUTOMATIONID; ?>-content">
|
||||
<div class="label"><?php echo $subDeviceData['name']; ?></div>
|
||||
<select class="input" name="devices[<?php echo $subDeviceId; ?>]">
|
||||
<option value="0" <?php echo ($subDeviceData['state'] == "0" ? 'selected="selected"' : ''); ?>>off</option>
|
||||
<option value="1" <?php echo ($subDeviceData['state'] == "1" ? 'selected="selected"' : ''); ?>>on</option>
|
||||
</select>
|
||||
<button name="remove" type="button" class="button is-danger fa" data-automation-id="<?php echo $AUTOMATIONID; ?>"></button>
|
||||
</div>
|
||||
<?php
|
||||
$i++;
|
||||
} ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="label"><?php echo $LANG['l_atDays'];?></div>
|
||||
<div class="field">
|
||||
<input type="checkbox" name="day[]" value="mon" <?php ECHO (in_array("mon", $AUTOMATION['onDays']) ? 'checked' : ''); ?>/> Pondělí
|
||||
</div>
|
||||
<div class="field">
|
||||
<input type="checkbox" name="day[]" value="tue" <?php ECHO (in_array("tue", $AUTOMATION['onDays']) ? 'checked' : ''); ?>/> Úterý
|
||||
</div>
|
||||
<div class="field">
|
||||
<input type="checkbox" name="day[]" value="wed" <?php ECHO (in_array("wed", $AUTOMATION['onDays']) ? 'checked' : ''); ?>/> Středa
|
||||
</div>
|
||||
<div class="field">
|
||||
<input type="checkbox" name="day[]" value="thu" <?php ECHO (in_array("thu", $AUTOMATION['onDays']) ? 'checked' : ''); ?>/> Čtvrtek
|
||||
</div>
|
||||
<div class="field">
|
||||
<input type="checkbox" name="day[]" value="fri" <?php ECHO (in_array("fri", $AUTOMATION['onDays']) ? 'checked' : ''); ?>/> Pátek
|
||||
</div>
|
||||
<div class="field">
|
||||
<input type="checkbox" name="day[]" value="sat" <?php ECHO (in_array("sat", $AUTOMATION['onDays']) ? 'checked' : ''); ?>/> Sobota
|
||||
</div>
|
||||
<div class="field">
|
||||
<input type="checkbox" name="day[]" value="sun" <?php ECHO (in_array("sun", $AUTOMATION['onDays']) ? 'checked' : ''); ?>/> Neděle
|
||||
</div>
|
||||
</div>
|
||||
<input type="submit" class="button" name="modalFinal" value="<?php echo $LANG['b_edit'];?>"/>
|
||||
<input type="submit" class="button is-danger" onClick="ajaxPostSimple('ajax',{automation_id: '<?php echo $AUTOMATIONID ?>', action:'delete'}, true);" name="remove" value="<?php echo $LANG['b_remove'];?>"/>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
21
app/templates/part/dashboardButton.phtml
Normal file
21
app/templates/part/dashboardButton.phtml
Normal file
@@ -0,0 +1,21 @@
|
||||
<div class="col-4 col-sm-3 col-xl-2 square-wrap">
|
||||
<div class="square">
|
||||
<div class="square-content" id="device-<?php echo $DASHBOARDITEMDATA['masterId'] ?>" onClick="ajaxPost('ajax',{subDevice_id:'<?php echo $DASHBOARDITEMDATA['id']; ?>'}, this);">
|
||||
<div class="content">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h5 class="fa">&#x<?php echo $DASHBOARDITEMDATA['icon'] ?></h5>
|
||||
</div>
|
||||
<div class="col">
|
||||
<h5 class="text-right"><?php echo $DASHBOARDITEMDATA['lastRecord']['value'].''.$DASHBOARDITEMDATA['unit'] ?></h5>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<?php echo $DASHBOARDITEMDATA['name'] ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
29
app/templates/part/deviceButton.phtml
Normal file
29
app/templates/part/deviceButton.phtml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
$action = "";
|
||||
if ($SUBDEVICE['type'] == 'on/off') {
|
||||
$action = 'onClick="ajaxPost(\'ajax\',{subDevice_id:\'' . $SUBDEVICEID . '\'}, this);"';
|
||||
}
|
||||
//neaktivní zařízení is-inactive
|
||||
?>
|
||||
|
||||
<div class="device-button col-4 col-sm-3 col-xl-2 square-wrap" <?php echo $action; ?> data-room-id="<?php echo $ROOMID; ?>">
|
||||
<div class="square">
|
||||
<div class="square-content <?php echo (($SUBDEVICE['comError'] == 1 || $DEVICE['approved'] == 0) ? "is-inactive" : "") ;?>" id="device-<?php echo $DEVICEID ?>" data-sub-device-id="<?php echo $SUBDEVICEID;?>">
|
||||
<div class="content">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h5 unselectable="on" class="fa">&#x<?php echo $DEVICE['icon'] ?></h5>
|
||||
</div>
|
||||
<div class="col">
|
||||
<h5 unselectable="on" class="device-button-value text-right" title="<?php echo $SUBDEVICE['lastRecort']['time']; ?>"><?php echo $SUBDEVICE['lastRecort']['value'] . $SUBDEVICE['unit']?></h5>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col" unselectable="on" >
|
||||
<?php echo $DEVICE['name']; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
80
app/templates/part/deviceDetail.phtml
Normal file
80
app/templates/part/deviceDetail.phtml
Normal file
@@ -0,0 +1,80 @@
|
||||
<!-- Detail -->
|
||||
<div class="modal-container modal-container-hiden" id="modal-detail-<?php echo $SUBDEVICEID;?>">
|
||||
<div class="modal">
|
||||
<div class="close">
|
||||
<i class="fa fa-times"></i>
|
||||
</div>
|
||||
<h4 class="mb-4"><?php echo $DEVICE['name']; ?></h4>
|
||||
<h5 class="mb-4"><?php echo $SUBDEVICE['lastRecort']['value'] . $SUBDEVICE['unit']?></h5>
|
||||
<p>Last Seen <?php echo $SUBDEVICE['lastRecort']['niceTime']; ?></p>
|
||||
<div class="">
|
||||
<canvas id="canvas-<?php echo $SUBDEVICEID;?>"></canvas>
|
||||
</div>
|
||||
|
||||
|
||||
<input
|
||||
type="submit"
|
||||
class="button col-2 graph-period"
|
||||
data-period="year"
|
||||
data-group="month"
|
||||
data-sub-device-id="<?php echo $SUBDEVICEID;?>"
|
||||
value="<?php echo $LANG['b_year']?>"
|
||||
/>
|
||||
|
||||
<input
|
||||
type="submit"
|
||||
class="button col-2 graph-period"
|
||||
data-period="month"
|
||||
data-group="day"
|
||||
data-sub-device-id="<?php echo $SUBDEVICEID;?>"
|
||||
value="<?php echo $LANG['b_month']?>"
|
||||
/>
|
||||
|
||||
<input
|
||||
type="submit"
|
||||
class="button col-2 graph-period"
|
||||
data-period="week"
|
||||
data-group="day"
|
||||
data-sub-device-id="<?php echo $SUBDEVICEID;?>"
|
||||
value="<?php echo $LANG['b_week']?>"
|
||||
/>
|
||||
|
||||
<input
|
||||
type="submit"
|
||||
class="button col-2 graph-period"
|
||||
data-period="day"
|
||||
data-group="hour"
|
||||
data-sub-device-id="<?php echo $SUBDEVICEID;?>"
|
||||
value="<?php echo $LANG['b_day']?>"
|
||||
/>
|
||||
|
||||
<input
|
||||
type="submit"
|
||||
class="button col-2 graph-period"
|
||||
data-period="hour"
|
||||
data-group="minute"
|
||||
data-sub-device-id="<?php echo $SUBDEVICEID;?>"
|
||||
value="<?php echo $LANG['b_hour']?>"
|
||||
/>
|
||||
|
||||
<div>
|
||||
<table class="table is-fluid">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Time</th>
|
||||
<th>State</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($SUBDEVICE['events'] as $key => $value) { ?>
|
||||
<tr>
|
||||
<th><?php echo (new DateTime($value['time']))->format(DATEFORMAT); ?></th>
|
||||
<th title="test"><?php echo $value['value'] . $SUBDEVICE['unit'];?></th>
|
||||
<?php //TODO: P5IDAT TOOLTIP PRO RAW VALUE?>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
160
app/templates/part/deviceEdit.phtml
Normal file
160
app/templates/part/deviceEdit.phtml
Normal file
@@ -0,0 +1,160 @@
|
||||
<div class="modal-container modal-container-hiden" id="modal-setting-<?php echo $DEVICEID ?>">
|
||||
<div class="modal">
|
||||
<div class="close">
|
||||
<i class="fa fa-times"></i>
|
||||
</div>
|
||||
<h4 class="mb-4"><?php echo $LANG['t_editDevice']; ?></h4>
|
||||
<form method="post" action="">
|
||||
<input class="input" type="hidden" name="deviceId" value="<?php echo $DEVICEID; ?>">
|
||||
<?php if ($DEVICE['approved'] != 0) { ?>
|
||||
<?php if ($DEVICE['userIsAdmin']) { ?>
|
||||
<div class="field">
|
||||
<div class="label"><?php echo $LANG['l_owner']; ?></div>
|
||||
<select class="input" name="deviceOwnerUserId">
|
||||
<option value=""><?php echo $LANG['w_noOne']; ?></option>
|
||||
<?php foreach ($USERS as $user) {
|
||||
$userId = $user['user_id'];
|
||||
$userName = $user['username'];
|
||||
?>
|
||||
<option value="<?php echo $userId; ?>" <?php ECHO ((int) $userId === (int) $DEVICE['owner'] ? 'selected="selected"' : ''); ?>><?php echo $userName; ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="label"> <?php echo $LANG['l_permission']; ?></div>
|
||||
<div class="row">
|
||||
|
||||
<div class="col-6">
|
||||
<div class="label"> - <?php echo $LANG['l_owner']; ?></div>
|
||||
</div>
|
||||
|
||||
<div class="col-6">
|
||||
<?php
|
||||
$permissions = $DEVICE['permission'];
|
||||
//Debug
|
||||
if (DEBUGMOD == 1) {
|
||||
echo '<pre>';
|
||||
VAR_DUMP($permissions);
|
||||
echo '</pre>';
|
||||
}
|
||||
?>
|
||||
<input type="radio" name="permissionOwner" value=1 <?php ECHO ($permissions[0] == 1 ? 'checked' : ''); ?>/> <?php echo $LANG['l_read']; ?>
|
||||
<input type="radio" name="permissionOwner" value=2 <?php ECHO ($permissions[0] == 2 ? 'checked' : ''); ?>/> <?php echo $LANG['l_use']; ?>
|
||||
<input type="radio" name="permissionOwner" value=3 <?php ECHO ($permissions[0] == 3 ? 'checked' : ''); ?>/> <?php echo $LANG['l_edit']; ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="label"> - <?php echo $LANG['l_member']; ?></div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<input type="radio" name="permissionOther" value=1 <?php ECHO ($permissions[1] == 1 ? 'checked' : ''); ?>/> <?php echo $LANG['l_read']; ?>
|
||||
<input type="radio" name="permissionOther" value=2 <?php ECHO ($permissions[1] == 2 ? 'checked' : ''); ?>/> <?php echo $LANG['l_use']; ?>
|
||||
<input type="radio" name="permissionOther" value=3 <?php ECHO ($permissions[1] == 3 ? 'checked' : ''); ?>/> <?php echo $LANG['l_edit']; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label"><?php echo $LANG['w_title']; ?></div>
|
||||
<input class="input" type="text" name="deviceName" value="<?php echo $DEVICE['name']; ?>" <?php echo (!$DEVICE['userIsAdmin'] ? 'disabled' : ''); ?>>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="field">
|
||||
<div class="label">Token:</div>
|
||||
<input class="input" type="text" name="deviceToken" value="<?php echo $DEVICE['token']; ?>" disabled>
|
||||
</div>
|
||||
<?php if ($DEVICE['userIsAdmin']) { ?>
|
||||
<?php if (!in_array($SUBDEVICE['type'], ['on/off', 'door'])) { ?>
|
||||
<div class="field">
|
||||
<div class="label"><?php echo $LANG['l_sleepTime']; ?></div>
|
||||
<input class="input" type="int" name="sleepTime" value="<?php echo $DEVICE['sleepTime']; ?>" <?php echo (!$DEVICE['userIsAdmin'] ? 'disabled' : ''); ?>>
|
||||
<p>* - <?php echo $LANG['l_inMinutes']; ?></p>
|
||||
</div>
|
||||
<?php }?>
|
||||
<div class="field">
|
||||
<div class="label"><?php echo $LANG['w_room']; ?></div>
|
||||
<select class="input" name="deviceOwnerId">
|
||||
<?php foreach ($ROOMS as $room) {
|
||||
$roomId = $room['room_id'];
|
||||
$roomName = $room['name'];
|
||||
?>
|
||||
<option value="<?php echo $roomId; ?>" <?php ECHO ((int) $roomId === (int) $DEVICE['room'] ? 'selected="selected"' : ''); ?>><?php echo $roomName; ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label"><?php echo $LANG['w_icon']; ?></div>
|
||||
<select class="input fa" name="deviceIcon" <?php echo (!$DEVICE['userIsAdmin'] ? 'disabled' : ''); ?>>
|
||||
<option value=""><?php echo $LANG['w_no'] . ' ' . $LANG['w_icon']; ?></option>
|
||||
<option value="f0eb" <?php ECHO ($DEVICE['icon'] == "f0eb" ? 'selected="selected"' : ''); ?>> - fa-lightbulb-o</option>
|
||||
<option value="f2dc" <?php ECHO ($DEVICE['icon'] == "f2dc" ? 'selected="selected"' : ''); ?>> - fa-snowflake-o</option>
|
||||
<option value="f0e7" <?php ECHO ($DEVICE['icon'] == "f0e7" ? 'selected="selected"' : ''); ?>> - fa-bolt</option>
|
||||
<option value="f2c7" <?php ECHO ($DEVICE['icon'] == "f2c7" ? 'selected="selected"' : ''); ?>> - fa-thermometer-full</option>
|
||||
<option value="f236" <?php ECHO ($DEVICE['icon'] == "f236" ? 'selected="selected"' : ''); ?>> - fa-bed</option>
|
||||
<option value="f185" <?php ECHO ($DEVICE['icon'] == "f185" ? 'selected="selected"' : ''); ?>> - fa-sun-o</option>
|
||||
<option value="f2db" <?php ECHO ($DEVICE['icon'] == "f2db" ? 'selected="selected"' : ''); ?>> - fa-microchip</option>
|
||||
<option value="f011" <?php ECHO ($DEVICE['icon'] == "f011" ? 'selected="selected"' : ''); ?>> - fa-power-off</option>
|
||||
<option value="f011" <?php ECHO ($DEVICE['icon'] == "f011" ? 'selected="selected"' : ''); ?>> - fa-desktop</option>
|
||||
</select>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="field">
|
||||
<div class="label"><?php echo $LANG['w_moduls']; ?></div>
|
||||
<div class="row no-gutters">
|
||||
<?php foreach ($DEVICE['subDevices'] as $subDeviceKey => $subDevice) { ?>
|
||||
<div class="col-4 col-sm-3 col-xl-2 square-wrap">
|
||||
<div class="square">
|
||||
<div class="square-content">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h3 class="fa">&#x<?php echo $DEVICE['icon']; ?></h3>
|
||||
</div>
|
||||
<div class="col">
|
||||
<h3><?php echo $subDevice['unit']; ?></h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<?php echo $DEVICE['name']; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<input type="submit" class="button" name="saveDevice" value="<?php echo $LANG['b_save']; ?>" <?php echo (!$DEVICE['userIsAdmin'] ? 'disabled' : ''); ?>/>
|
||||
<input type="submit" class="button is-danger" name="disableDevice" value="<?php echo $LANG['b_disable']; ?>"/>
|
||||
<?php } else { ?>
|
||||
<div class="field">
|
||||
<div class="label"><?php echo $LANG['w_moduls']; ?></div>
|
||||
<div class="row no-gutters">
|
||||
<?php foreach ($DEVICE['subDevices'] as $subDeviceKey => $subDevice) { ?>
|
||||
<div class="col-4 col-sm-3 col-xl-2 square-wrap">
|
||||
<div class="square">
|
||||
<div class="square-content">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h3 class="fa">&#x<?php echo $DEVICE['icon']; ?></h3>
|
||||
</div>
|
||||
<div class="col">
|
||||
<h3><?php echo $subDevice['unit']; ?></h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<?php echo $DEVICE['name']; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<input type="submit" class="button is-primary" name="approveDevice" value="<?php echo $LANG['b_approve']; ?>"/>
|
||||
<input type="submit" class="button is-danger" name="disableDevice" value="<?php echo $LANG['b_disable']; ?>"/>
|
||||
<?php } ?>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
3
app/templates/part/footer.phtml
Normal file
3
app/templates/part/footer.phtml
Normal file
@@ -0,0 +1,3 @@
|
||||
<script src="./templates/js/jquery.js"></script>
|
||||
<script src="./templates/js/post.js"></script>
|
||||
<script src="./templates/js/script.js"></script>
|
25
app/templates/part/head.phtml
Normal file
25
app/templates/part/head.phtml
Normal file
@@ -0,0 +1,25 @@
|
||||
<link rel="manifest" href="manifest.json">
|
||||
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="application-name" content="Home">
|
||||
<meta name="apple-mobile-web-app-title" content="Home">
|
||||
<meta name="theme-color" content="#182239">
|
||||
<meta name="msapplication-navbutton-color" content="#182239">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||
<meta name="msapplication-starturl" content="/vasek/home/">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<link rel="icon" sizes="192x192" href="/vasek/home/templates/images/icon-192x192.png">
|
||||
<link rel="apple-touch-icon" sizes="192x192" href="/vasek/home/templates/images/icon-192x192.png">
|
||||
<link rel="icon" sizes="512x512" href="/vasek/home/templates/images/icon-512x512.png">
|
||||
<link rel="apple-touch-icon" sizes="512x512" href="/vasek/home/templates/images/icon-512x512.png">
|
||||
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<link rel="stylesheet" href="./templates/css/main.css">
|
||||
<link rel="stylesheet" href="./templates/css/font-awesome.min.css">
|
||||
<link rel="stylesheet" href="./templates/css/modal.css">
|
||||
<link rel="stylesheet" href="./templates/css/pre.css">
|
||||
<link rel="stylesheet" href="./templates/css/loading.css">
|
46
app/templates/part/menu.phtml
Normal file
46
app/templates/part/menu.phtml
Normal file
@@ -0,0 +1,46 @@
|
||||
<div class="nav">
|
||||
<?php
|
||||
$menuItems = [
|
||||
'fa-home' => [
|
||||
'slug' => 'home',
|
||||
'lngKey' => 'home',
|
||||
'path' => './',
|
||||
],
|
||||
'fa-tachometer' => [
|
||||
'slug' => 'dashboard',
|
||||
'lngKey' => 'dashboard',
|
||||
'path' => 'dashboard',
|
||||
],
|
||||
'fa-wrench' => [
|
||||
'slug' => 'setting',
|
||||
'lngKey' => 'settings',
|
||||
'path' => 'setting',
|
||||
],
|
||||
'fa-calendar-o' => [
|
||||
'slug' => 'automation',
|
||||
'lngKey' => 'automatization',
|
||||
'path' => 'automation',
|
||||
],
|
||||
'fa-terminal' => [
|
||||
'slug' => 'scene',
|
||||
'lngKey' => 'scenes',
|
||||
'path' => 'scene',
|
||||
],
|
||||
'fa-bug' =>[
|
||||
'slug' => 'log',
|
||||
'lngKey' => 'log',
|
||||
'path' => 'log',
|
||||
],
|
||||
];
|
||||
foreach ( $menuItems as $key => $value) { ?>
|
||||
<div class="nav-item <?php echo ($ITEM == $value ? 'is-active' : ''); ?>">
|
||||
<a href="<?php echo $value['path']?>">
|
||||
<i class="fa <?php echo $key ?>"></i>
|
||||
<span>
|
||||
<?php echo $LANG['m_'.$value['lngKey']]; ?>
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
<?php }?>
|
||||
|
||||
</div>
|
22
app/templates/part/sceneButton.phtml
Normal file
22
app/templates/part/sceneButton.phtml
Normal file
@@ -0,0 +1,22 @@
|
||||
<div class="col-12 col-md-6 col-xl-4 square-wrap noselect">
|
||||
<div class="rectangle-2">
|
||||
<div class="square-content double" id="scene-<?php echo $SCENEID ?>" onClick="ajaxPost('ajax',{scene_id:'<?php echo $SCENEID; ?>'}, this);" >
|
||||
<div class="row">
|
||||
<div class="col-1">
|
||||
<h5 class="fa noselect">
|
||||
&#x<?php echo $SCENEDATA['icon']; ?>
|
||||
</h5>
|
||||
</div>
|
||||
<div class="col">
|
||||
<h5 class="text-right break-all noselect">
|
||||
<?php echo $SCENEDATA['name']; ?>
|
||||
</h5>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
40
app/templates/part/sceneCreate.phtml
Normal file
40
app/templates/part/sceneCreate.phtml
Normal file
@@ -0,0 +1,40 @@
|
||||
<div class="modal-container modal-container-hiden" id="modal">
|
||||
<div class="modal">
|
||||
<div class="close">
|
||||
<i class="fa fa-times"></i>
|
||||
</div>
|
||||
<h4 class="mb-4"><?php echo $LANG['t_createScene'];?></h4>
|
||||
<form method="post" action="" >
|
||||
<div class="field">
|
||||
<div class="label"><?php echo $LANG['w_title'];?>:</div>
|
||||
<input type="text" class="input" name="sceneName" value=""/>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label"><?php echo $LANG['w_icon'];?>:</div>
|
||||
<select class="input fa" name="sceneIcon" <?php echo (!$DEVICE['userIsAdmin'] ? 'disabled' : ''); ?>>
|
||||
<option value="">No icon</option>
|
||||
<option value="f0eb"> - fa-lightbulb-o</option>
|
||||
<option value="f2dc"> - fa-snowflake-o</option>
|
||||
<option value="f0e7"> - fa-bolt</option>
|
||||
<option value="f2c7"> - fa-thermometer-full</option>
|
||||
<option value="f236"> - fa-bed</option>
|
||||
<option value="f185"> - fa-sun-o</option>
|
||||
<option value="f2db"> - fa-microchip</option>
|
||||
<option value="f011"> - fa-power-off</option>
|
||||
<option value="f011"> - fa-desktop</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label"><?php echo $LANG['l_choseDevice'];?></div>
|
||||
<select class="input" name="devices[]" multiple>
|
||||
<?php
|
||||
foreach ($SUBDEVICES as $subdeviceId => $subdeviceData) {
|
||||
echo '<option value="'.$subdeviceId.'">'.$subdeviceData['name'].'</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<input type="submit" class="button" name="submit" value="<?php echo $LANG['b_next'];?>"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
26
app/templates/part/sceneCreateOptions.phtml
Normal file
26
app/templates/part/sceneCreateOptions.phtml
Normal file
@@ -0,0 +1,26 @@
|
||||
<div class="modal-container" id="modal">
|
||||
<div class="modal">
|
||||
<div class="close">
|
||||
<i class="fa fa-times"></i>
|
||||
</div>
|
||||
<h4 class="mb-4"><?php echo $LANG['t_createScene'];?></h4>
|
||||
<form method="post">
|
||||
<input type="hidden" name="sceneName" value="<?php echo $SCENENAME; ?>">
|
||||
<input type="hidden" name="sceneIcon" value="<?php echo $SCENEICON; ?>">
|
||||
<?php
|
||||
$i = 0;
|
||||
foreach($SETSTATEFORMDEVICES as $device){ ?>
|
||||
<div class="field px-2">
|
||||
<div class="label"><?php echo $device['name']; ?></div>
|
||||
<select class="input" name="devices[<?php echo $device['setableSubDevices']; ?>]">
|
||||
<option value="0">off</option>
|
||||
<option value="1">on</option>
|
||||
</select>
|
||||
</div>
|
||||
<?php
|
||||
$i++;
|
||||
} ?>
|
||||
<input type="submit" class="button" name="submit" value="<?php echo $LANG['b_create'];?>"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
48
app/templates/part/sceneEdit.phtml
Normal file
48
app/templates/part/sceneEdit.phtml
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php //TODO DOD2LAT UKL8D8N9?>
|
||||
<div class="modal-container modal-container-hiden" id="modal-setting-<?php echo $SCENEID ?>">
|
||||
<div class="modal">
|
||||
<div class="close">
|
||||
<i class="fa fa-times"></i>
|
||||
</div>
|
||||
<h4 class="mb-4"><?php echo $LANG['t_editScene']?></h4>
|
||||
<form method="post">
|
||||
<div class="field">
|
||||
<div class="label"><?php echo $LANG['w_title'];?>:</div>
|
||||
<input type="text" class="input" name="sceneName" value="<?php echo $SCENE['name']; ?>"/>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label"><?php echo $LANG['w_icon'];?>:</div>
|
||||
<select class="input fa" name="sceneIcon">
|
||||
<option value=""><?php echo $LANG['w_no'].$LANG['w_icon'];?></option>
|
||||
<option value="f0eb" <?php ECHO ($SCENE['icon'] == "f0eb" ? 'selected="selected"' : ''); ?>> - fa-lightbulb-o</option>
|
||||
<option value="f2dc" <?php ECHO ($SCENE['icon'] == "f2dc" ? 'selected="selected"' : ''); ?>> - fa-snowflake-o</option>
|
||||
<option value="f0e7" <?php ECHO ($SCENE['icon'] == "f0e7" ? 'selected="selected"' : ''); ?>> - fa-bolt</option>
|
||||
<option value="f2c7" <?php ECHO ($SCENE['icon'] == "f2c7" ? 'selected="selected"' : ''); ?>> - fa-thermometer-full</option>
|
||||
<option value="f236" <?php ECHO ($SCENE['icon'] == "f236" ? 'selected="selected"' : ''); ?>> - fa-bed</option>
|
||||
<option value="f185" <?php ECHO ($SCENE['icon'] == "f185" ? 'selected="selected"' : ''); ?>> - fa-sun-o</option>
|
||||
<option value="f2db" <?php ECHO ($SCENE['icon'] == "f2db" ? 'selected="selected"' : ''); ?>> - fa-microchip</option>
|
||||
<option value="f011" <?php ECHO ($SCENE['icon'] == "f011" ? 'selected="selected"' : ''); ?>> - fa-power-off</option>
|
||||
<option value="f011" <?php ECHO ($SCENE['icon'] == "f011" ? 'selected="selected"' : ''); ?>> - fa-desktop</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field px-2">
|
||||
<?php
|
||||
$i = 0;
|
||||
foreach($SCENE['doSomething'] as $subDeviceId => $subDeviceData){ ?>
|
||||
<div id="scene-<?php echo $SCENEID; ?>-content">
|
||||
<div class="label"><?php echo $subDeviceData['name']; ?></div>
|
||||
<select class="input" name="devices[<?php echo $subDeviceId; ?>]">
|
||||
<option value="0" <?php ECHO ($subDeviceData['state'] == "0" ? 'selected="selected"' : ''); ?>>off</option>
|
||||
<option value="1" <?php ECHO ($subDeviceData['state'] == "1" ? 'selected="selected"' : ''); ?>>on</option>
|
||||
</select>
|
||||
<button name="remove" type="button" class="button is-danger fa" data-scene-id="<?php echo $SCENEID; ?>"></button>
|
||||
</div>
|
||||
<?php
|
||||
$i++;
|
||||
} ?>
|
||||
</div>
|
||||
<input type="submit" class="button" name="saveDevice" value="<?php echo $LANG['b_edit'];?>"/>
|
||||
<input type="button" class="button is-danger" onClick="ajaxPost('ajax',{scene_id:'<?php echo $SCENEID ?>', 'action':'delete'}, this, true);" name="saveDevice" value="<?php echo $LANG['b_remove'];?>"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
3
app/templates/part/test.phtml
Normal file
3
app/templates/part/test.phtml
Normal file
@@ -0,0 +1,3 @@
|
||||
<H1>
|
||||
TEST - TEST
|
||||
</H1>
|
152
app/templates/rooms.phtml
Normal file
152
app/templates/rooms.phtml
Normal file
@@ -0,0 +1,152 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
</head>
|
||||
<body class="no-transitions">
|
||||
<div class="row no-gutters main">
|
||||
<div class="col-md-3 d-sm-none"></div>
|
||||
<div class="col-md-3 nav-container">
|
||||
<?php
|
||||
$partial = new Partial('menu');
|
||||
$partial->prepare('item', 'rooms');
|
||||
$partial->prepare('lang',$LANG);
|
||||
$partial->render();
|
||||
?>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="col-md-9 main-body">
|
||||
<div class="frame">
|
||||
<?php foreach ($ROOMS as $roomId => $room) { ?>
|
||||
<div class="single-frame" id="room-<?php echo $roomId; ?>">
|
||||
<div class="">
|
||||
<h1><?php echo $room['name']; ?></h1>
|
||||
<?php foreach ($room['reading'] as $key => $value) { ?>
|
||||
<?php echo $LANG[$key] .": ". $value; ?></br>
|
||||
<?php } ?>
|
||||
<?php if (DEBUGMOD == 1) { ?>
|
||||
<pre>
|
||||
<?php var_dump($room);?>
|
||||
</pre>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php foreach ($room['controls'] as $key => $value) { ?>
|
||||
<div class="row no-gutters">
|
||||
<div class="device-button col-4 col-sm-3 col-xl-2 square-wrap" data-room-id="">
|
||||
<div class="square">
|
||||
<div class="square-content" id="device-" data-sub-device-id="">
|
||||
<div class="content">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h5 unselectable="on" class="fa">&#x<?php echo $value['icon'];?></h5>
|
||||
</div>
|
||||
<div class="col">
|
||||
<h5 unselectable="on" class="device-button-value text-right" title=""><?php echo $value['value'];?></h5>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col" unselectable="on" >
|
||||
<?php echo $value['name'];?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<style>
|
||||
.single-frame {
|
||||
background-color: red;
|
||||
width: 100%;
|
||||
flex: 0 0 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.frame {
|
||||
overflow-x: auto;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body,html{
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.frame .single-frame:nth-child(even) {
|
||||
background: red;
|
||||
}
|
||||
|
||||
.frame .single-frame:nth-child(odd) {
|
||||
background: green;
|
||||
}
|
||||
|
||||
</style>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
$partial = new Partial('footer');
|
||||
$partial->render();
|
||||
?>
|
||||
<script>
|
||||
var prev_id;
|
||||
var id;
|
||||
var current_element
|
||||
var elementWidth = $('.frame').width();
|
||||
|
||||
$('.frame').scroll(function(){
|
||||
//console.log('SCROLLING!');
|
||||
//console.log('scrool'+$('.single-frame').scrollLeft());
|
||||
var element_width = $('.single-frame').width();
|
||||
|
||||
var offset = $('.single-frame').offset();
|
||||
var positive = Math.abs(offset.left)
|
||||
var divided = positive / element_width;
|
||||
var round = Math.round(divided);
|
||||
|
||||
current_element = $('.frame').children().eq(round);
|
||||
id = current_element.attr('id');
|
||||
|
||||
if (prev_id != id){
|
||||
prev_id = id;
|
||||
console.log(prev_id);
|
||||
}
|
||||
var scrollTo = $('#'+id).offset().left;
|
||||
console.log('s-f: '+ scrollTo)
|
||||
|
||||
});
|
||||
$('.frame').on('touchend', function(){ // listen to mouse up
|
||||
console.log('STOPPED SCROLLING!');
|
||||
var scrollLeft = $('.frame').scrollLeft();
|
||||
console.log('frameLeft' + scrollLeft);
|
||||
var a = $('.frame').children();
|
||||
for (index = 0; index < a.length; ++index) {
|
||||
if(a[index].id == id){
|
||||
$('.frame').animate({
|
||||
scrollLeft: (index * elementWidth)
|
||||
});
|
||||
$('.frame').animate({
|
||||
scrollLeft: (index * elementWidth)
|
||||
});
|
||||
}
|
||||
console.log(a[index]);
|
||||
}
|
||||
|
||||
if (scrollTo > 160) {
|
||||
console.log($('#'+id).left)
|
||||
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
65
app/templates/scene.phtml
Normal file
65
app/templates/scene.phtml
Normal file
@@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
</head>
|
||||
<body class="no-transitions">
|
||||
<div class="row no-gutters main">
|
||||
<div class="col-md-3 d-sm-none"></div>
|
||||
<div class="col-md-3 nav-container">
|
||||
<?php
|
||||
$partial = new Partial('menu');
|
||||
$partial->prepare('item', 'scene');
|
||||
$partial->prepare('lang',$LANG);
|
||||
$partial->render();
|
||||
?>
|
||||
</div>
|
||||
<div class="col-md-9 main-body">
|
||||
<a class="button is-primary m-1" onClick="$('#modal').removeClass('modal-container-hiden').show();"><?php echo $LANG['t_createScene'];?></a>
|
||||
<div class="row no-gutters">
|
||||
<?php foreach ($SCENES as $sceneId => $sceneData) {
|
||||
//BUTTON
|
||||
$partialScenButton = new Partial('sceneButton');
|
||||
$partialScenButton->prepare('lang', $LANG);
|
||||
$partialScenButton->prepare('sceneId', $sceneId);
|
||||
$partialScenButton->prepare('sceneData', $sceneData);
|
||||
|
||||
$partialScenButton->render();
|
||||
|
||||
// Edit
|
||||
$partialSceneEdit = new Partial('sceneEdit');
|
||||
$partialSceneEdit->prepare('lang',$LANG);
|
||||
$partialSceneEdit->prepare('sceneId',$sceneId);
|
||||
$partialSceneEdit->prepare('scene',$sceneData);
|
||||
|
||||
$partialSceneEdit->render();
|
||||
?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (isset($_POST['devices'])) {
|
||||
$partial = new Partial('sceneCreateOptions');
|
||||
$partial->prepare('lang',$LANG);
|
||||
$partial->prepare('setStateFormDevices',$SETSTATEFORMDEVICES );
|
||||
$partial->prepare('sceneIcon',$SCENEICON );
|
||||
$partial->prepare('SceneName',$SCENENAME );
|
||||
|
||||
$partial->render();
|
||||
} else {
|
||||
$partial = new Partial('sceneCreate');
|
||||
$partial->prepare('lang',$LANG);
|
||||
$partial->prepare('subDevices',$SUBDEVICES);
|
||||
|
||||
$partial->render();
|
||||
}
|
||||
$partial = new Partial('footer');
|
||||
$partial->render();
|
||||
?>
|
||||
</body>
|
||||
</html>
|
73
app/templates/setting.phtml
Normal file
73
app/templates/setting.phtml
Normal file
@@ -0,0 +1,73 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
</head>
|
||||
<body class="no-transitions">
|
||||
<div class="row no-gutters main">
|
||||
<div class="col-md-3 d-sm-none"></div>
|
||||
<div class="col-md-3 nav-container">
|
||||
<?php
|
||||
$partial = new Partial('menu');
|
||||
$partial->prepare('item', 'setting');
|
||||
$partial->prepare('lang',$LANG);
|
||||
$partial->render();
|
||||
?>
|
||||
</div>
|
||||
<div class="col-md-9 main-body">
|
||||
<div class="col-12 col-sm-9 mx-auto mt-4">
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<div class="">
|
||||
<div class="field">
|
||||
<div class="label">Stránka po načtení</div>
|
||||
<select class="input" name="loadPage">
|
||||
<option value="0" <?php echo (UserManager::getUserData("startPage") == 0 ? "selected" : ""); ?>>Default</option>
|
||||
<option value="1" <?php echo (UserManager::getUserData("startPage") == 1 ? "selected" : ""); ?>>Dashboard</option>
|
||||
</select>
|
||||
</div>
|
||||
<input type="submit" name="submit" class="button" value="Uložit"/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="col-12 col-sm-9 mx-auto mt-4">
|
||||
<div class="field">
|
||||
<a href="logout" class="button is-primary">Odhlásit se</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-sm-9 mx-auto mt-4">
|
||||
<div class="label">Testovavcí Nastavení</div>
|
||||
<div class="field">
|
||||
<a href="rooms" class="button">ROOMS</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-sm-9 mx-auto mt-4">
|
||||
<div class="field">
|
||||
<a href="log" class="button">Logs</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$partial = new Partial('footer');
|
||||
$partial->render();
|
||||
//TODO js do main.js
|
||||
?>
|
||||
<script>
|
||||
$( "#enable-features" ).click(function(e) {
|
||||
var selectRoomId = localStorage.getItem("enableFeature");
|
||||
if (selectRoomId){
|
||||
localStorage.setItem("enableFeature", true);
|
||||
}else {
|
||||
localStorage.setItem("enableFeature", false);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
172
app/views/Ajax.php
Normal file
172
app/views/Ajax.php
Normal file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
$files = scandir('app/class/');
|
||||
$files = array_diff($files, array('.', '..'));
|
||||
foreach($files as $file) {
|
||||
include_once 'app/class/'. $file;
|
||||
}
|
||||
|
||||
class Ajax extends Template
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
global $userManager;
|
||||
global $lang;
|
||||
|
||||
if (!$userManager->isLogin()){
|
||||
header('Location: ./');
|
||||
}
|
||||
|
||||
$is_ajax = 'XMLHttpRequest' == ( $_SERVER['HTTP_X_REQUESTED_WITH'] ?? '' );
|
||||
if (!$is_ajax){
|
||||
header('Location: ./');
|
||||
}
|
||||
|
||||
if (isset($_POST['subDevice_id'])){
|
||||
$subDeviceId = $_POST['subDevice_id'];
|
||||
if (isset($_POST['lastRecord'])){
|
||||
echo RecordManager::getLastRecord($subDeviceId)['execuded'];
|
||||
die();
|
||||
}
|
||||
$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
|
||||
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
||||
if ($subDeviceData['type'] == 'on/off'){
|
||||
//TODO: Pridelat kontrolu změnit stav pouze pokud se poslední [executed] stav != novému
|
||||
if (RecordManager::getLastRecord($subDeviceData['subdevice_id'])['value'] == 0){
|
||||
RecordManager::create($deviceId, 'on/off', 1);
|
||||
echo 'ON';
|
||||
}else{
|
||||
RecordManager::create($deviceId, 'on/off', 0);
|
||||
echo 'OFF';
|
||||
}
|
||||
}
|
||||
|
||||
} else if (isset($_POST['automation_id'])){
|
||||
$automationId = $_POST['automation_id'];
|
||||
if (isset($_POST['action']) && $_POST['action'] == 'delete') {
|
||||
AutomationManager::remove($automationId);
|
||||
}else {
|
||||
AutomationManager::deactive($automationId);
|
||||
}
|
||||
} else if (isset($_POST['subDevice']) && isset($_POST['action']) && $_POST['action'] == "chart") {
|
||||
//TODO lepe rozstrukturovat
|
||||
$subDeviceId = $_POST['subDevice'];
|
||||
$period = $_POST['period'];
|
||||
$groupBy = $_POST['group'];
|
||||
|
||||
$subDevice = SubDeviceManager::getSubDevice($subDeviceId);
|
||||
$records = RecordManager::getAllRecordForGraph($subDeviceId, $period, $groupBy);
|
||||
|
||||
$array = array_column($records, 'value');
|
||||
|
||||
if ($subDevice['type'] == 'light'){
|
||||
foreach ($array as $key => $value) {
|
||||
if ($value == 1 || $value == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ($value > 810){
|
||||
$array[$key] = 1;
|
||||
} else {
|
||||
$array[$key] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data = json_encode($array);
|
||||
|
||||
$arrayTimeStamps = array_column($records, 'time');
|
||||
foreach ($arrayTimeStamps as $key => $value) {
|
||||
$arrayTimeStamps[$key] = (new DateTime($value))->format(TIMEFORMAT);
|
||||
}
|
||||
|
||||
$labels = json_encode($arrayTimeStamps);
|
||||
$range = RANGES[$subDevice['type']];
|
||||
header('Content-Type: application/json');
|
||||
$JSON = '{
|
||||
"type": "line",
|
||||
"data": {
|
||||
"labels": ' . $labels . ',
|
||||
"datasets": [{
|
||||
"data": ' . $data . ',
|
||||
"backgroundColor": "#7522bf",
|
||||
"lineTension": 0,
|
||||
"radius": 5
|
||||
}]
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"display": false
|
||||
},
|
||||
"scales": {
|
||||
"yAxes": [{
|
||||
"ticks": {
|
||||
"min": ' . $range['min'] . ',
|
||||
"max": ' . $range['max'] . ',
|
||||
"steps": ' . $range['scale'] . '
|
||||
}
|
||||
}]
|
||||
},
|
||||
"tooltips": {
|
||||
"enabled": false
|
||||
},
|
||||
"hover": {
|
||||
"mode": null
|
||||
}
|
||||
}
|
||||
}';
|
||||
|
||||
echo $JSON;
|
||||
} else if (isset($_POST['action']) && $_POST['action'] == "getState") {
|
||||
//State Update
|
||||
$roomsData = RoomManager::getAllRooms();
|
||||
$subDevices = [];
|
||||
foreach ($roomsData as $roomKey => $roomsData) {
|
||||
$devicesData = DeviceManager::getAllDevicesInRoom($roomsData['room_id']);
|
||||
foreach ($devicesData as $deviceKey => $deviceData) {
|
||||
$subDevicesData = SubDeviceManager::getAllSubDevices($deviceData['device_id']);
|
||||
foreach ($subDevicesData as $subDeviceKey => $subDeviceData) {
|
||||
$lastRecord = RecordManager::getLastRecord($subDeviceData['subdevice_id']);
|
||||
$parsedValue = round($lastRecord['value']);
|
||||
//TODO: Předelat na switch snažší přidávání
|
||||
/*Value Parsing*/
|
||||
if ($subDeviceData['type'] == "on/off") {
|
||||
$parsedValue = ($parsedValue == 1 ? 'ON' : 'OFF');
|
||||
}
|
||||
if ($subDeviceData['type'] == "light") {
|
||||
$replacementTrue = 'Light';
|
||||
$replacementFalse = 'Dark';
|
||||
if ($parsedValue != 1){
|
||||
//Analog Reading
|
||||
$parsedValue = ($parsedValue <= 810 ? $replacementTrue : $replacementFalse);
|
||||
} else {
|
||||
//Digital Reading
|
||||
$parsedValue = ($parsedValue == 0 ? $replacementTrue : $replacementFalse);
|
||||
}
|
||||
}
|
||||
if ($subDeviceData['type'] == "door") {
|
||||
$replacementTrue = 'Closed';
|
||||
$replacementFalse = 'Opened';
|
||||
$parsedValue = ($parsedValue == 1 ? $replacementTrue : $replacementFalse);
|
||||
}
|
||||
$subDevices[$subDeviceData['subdevice_id']] = [
|
||||
'value' => $parsedValue .$subDeviceData['unit'],
|
||||
'time' => $lastRecord['time'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
echo json_encode($subDevices);
|
||||
die();
|
||||
} else if (isset($_POST['scene_id'])) {
|
||||
$sceneId = $_POST['scene_id'];
|
||||
if (isset($_POST['action']) && $_POST['action'] == 'delete') {
|
||||
SceneManager::delete($sceneId);
|
||||
}else {
|
||||
echo SceneManager::execScene($sceneId);
|
||||
}
|
||||
}
|
||||
|
||||
die();
|
||||
|
||||
}
|
||||
}
|
61
app/views/Automation.php
Normal file
61
app/views/Automation.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
$files = scandir('app/class/');
|
||||
$files = array_diff($files, array('.', '..'));
|
||||
foreach($files as $file) {
|
||||
include_once 'app/class/'. $file;
|
||||
}
|
||||
|
||||
class Automation extends Template
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
global $userManager;
|
||||
global $lang;
|
||||
|
||||
if (!$userManager->isLogin()){
|
||||
header('Location: ./login');
|
||||
}
|
||||
|
||||
$automations = [];
|
||||
$automationsData = AutomationManager::getAll();
|
||||
foreach ($automationsData as $automationKey => $automationData) {
|
||||
$doSomething = [];
|
||||
foreach (json_decode($automationData['do_something']) as $deviceId => $subDeviceState) {
|
||||
$subDeviceMasterDeviceData = DeviceManager::getDeviceById($deviceId);
|
||||
$doSomething[$deviceId] = [
|
||||
'name' => $subDeviceMasterDeviceData['name'],
|
||||
'state' => $subDeviceState,
|
||||
];
|
||||
}
|
||||
$automations[$automationData['automation_id']] = [
|
||||
'name' => '',
|
||||
'onDays' => json_decode($automationData['on_days']),
|
||||
'ifSomething' => $automationData['if_something'],
|
||||
'doSomething' => $doSomething,
|
||||
'active' => $automationData['active'],
|
||||
];
|
||||
}
|
||||
|
||||
$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'] . $allDevicesData[$deviceKey]['device_id'],
|
||||
'type' => $subDeviceValue['type'],
|
||||
'masterDevice' => $subDeviceValue['device_id'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$template = new Template('automation');
|
||||
$template->prepare('title', 'Automation');
|
||||
$template->prepare('lang', $lang);
|
||||
$template->prepare('automations', $automations);
|
||||
$template->prepare('subDevices', $approvedSubDevices);
|
||||
|
||||
$template->render();
|
||||
}
|
||||
}
|
90
app/views/Dashboard.php
Normal file
90
app/views/Dashboard.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
class Dashboard extends Template
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
global $userManager;
|
||||
global $lang;
|
||||
|
||||
if (!$userManager->isLogin()){
|
||||
header('Location: ./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('title', 'Nástěnka');
|
||||
$template->prepare('lang', $lang);
|
||||
$template->prepare('dashboard', $dashboard);
|
||||
$template->prepare('subDevices', $approvedSubDevices);
|
||||
|
||||
$template->render();
|
||||
}
|
||||
}
|
170
app/views/Home.php
Normal file
170
app/views/Home.php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Home extends Template
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
global $userManager;
|
||||
global $lang;
|
||||
|
||||
if (!$userManager->isLogin()){
|
||||
header('Location: ./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) {
|
||||
$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) {
|
||||
$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);
|
||||
//TODO: skontrolovat zdali se jedná o poslední (opravdu nejaktuálnější) záznam
|
||||
$lastRecord = $events[0];
|
||||
$parsedValue = round($lastRecord['value']);
|
||||
|
||||
/*Value Parsing*/
|
||||
if ($subDeviceData['type'] == "on/off") {
|
||||
$parsedValue = ($parsedValue == 1 ? 'ON' : 'OFF');
|
||||
}
|
||||
|
||||
if ($subDeviceData['type'] == "door") {
|
||||
$replacementTrue = 'Closed';
|
||||
$replacementFalse = 'Opened';
|
||||
foreach ($events as $key => $value) {
|
||||
$events[$key]['value'] = ($value['value'] == 1 ? $replacementTrue : $replacementFalse);
|
||||
}
|
||||
$parsedValue = ($parsedValue == 1 ? $replacementTrue : $replacementFalse);
|
||||
}
|
||||
|
||||
if ($subDeviceData['type'] == "light") {
|
||||
$replacementTrue = 'Light';
|
||||
$replacementFalse = 'Dark';
|
||||
foreach ($events as $key => $value) {
|
||||
if ($parsedValue != 1){
|
||||
//Analog Reading
|
||||
$events[$key]['value'] = ($value['value'] <= 810 ? $replacementTrue : $replacementFalse);
|
||||
} else {
|
||||
//Digital Reading
|
||||
$events[$key]['value'] = ($value['value'] == 0 ? $replacementTrue : $replacementFalse);
|
||||
}
|
||||
}
|
||||
if ($parsedValue != 1){
|
||||
//Analog Reading
|
||||
$parsedValue = ($parsedValue <= 810 ? $replacementTrue : $replacementFalse);
|
||||
} else {
|
||||
//Digital Reading
|
||||
$parsedValue = ($parsedValue == 0 ? $replacementTrue : $replacementFalse);
|
||||
}
|
||||
}
|
||||
|
||||
$date2 = new DateTime($lastRecord['time']);
|
||||
|
||||
$niceTime = $this->ago($date2);
|
||||
|
||||
$connectionError = false;
|
||||
|
||||
$startDate = date_create($lastRecord['time']);
|
||||
$interval = $startDate->diff(new DateTime());
|
||||
$hours = $interval->format('%h');
|
||||
$minutes = $interval->format('%i');
|
||||
$lastSeen = ($hours * 60 + $minutes);
|
||||
|
||||
if ($lastSeen > $deviceData['sleep_time'] && $subDeviceData['type'] != "on/off") {
|
||||
$connectionError = true;
|
||||
}
|
||||
|
||||
$subDevices[$subDeviceData['subdevice_id']] = [
|
||||
'events'=> $events,
|
||||
'type' => $subDeviceData['type'],
|
||||
'unit' => $subDeviceData['unit'],
|
||||
'comError' => $connectionError,
|
||||
'lastRecort' => [
|
||||
'value' => $parsedValue,
|
||||
'time' => $lastRecord['time'],
|
||||
'niceTime' => $niceTime,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$permissionArray = json_decode($deviceData['permission']);
|
||||
|
||||
$userIsDeviceAdmin = false;
|
||||
if($permissionArray[1] == 3) {
|
||||
$userIsDeviceAdmin = true;
|
||||
} else if ($permissionArray[0] == 3) {
|
||||
if ( $deviceData['owner'] == $userManager->getUserData('user_id')) {
|
||||
$userIsDeviceAdmin = true;
|
||||
}
|
||||
}
|
||||
|
||||
$devices[$deviceData['device_id']] = [
|
||||
'name' => $deviceData['name'],
|
||||
'icon' => $deviceData['icon'],
|
||||
'room' => $deviceData['room_id'],
|
||||
'token' => $deviceData['token'],
|
||||
'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('rooms', $rooms);
|
||||
$template->prepare('title', 'Home');
|
||||
$template->prepare('lang', $lang);
|
||||
$template->prepare('data', $roomsItems);
|
||||
|
||||
$template->render();
|
||||
|
||||
}
|
||||
|
||||
function ago( $datetime )
|
||||
{
|
||||
$interval = date_create('now')->diff( $datetime );
|
||||
$suffix = ( $interval->invert ? ' ago' : '' );
|
||||
if ( $v = $interval->y >= 1 ) return $this->pluralize( $interval->m, 'month' ) . $suffix;
|
||||
if ( $v = $interval->d >= 1 ) return $this->pluralize( $interval->d, 'day' ) . $suffix;
|
||||
if ( $v = $interval->h >= 1 ) return $this->pluralize( $interval->h, 'hour' ) . $suffix;
|
||||
if ( $v = $interval->i >= 1 ) return $this->pluralize( $interval->i, 'minute' ) . $suffix;
|
||||
return $this->pluralize( $interval->s, 'second' ) . $suffix;
|
||||
}
|
||||
|
||||
function pluralize( $count, $text )
|
||||
{
|
||||
return $count . ( ( $count == 1 ) ? ( " $text" ) : ( " ${text}s" ) );
|
||||
}
|
||||
}
|
34
app/views/Log.php
Normal file
34
app/views/Log.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Log extends Template
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
global $userManager;
|
||||
global $lang;
|
||||
|
||||
if (!$userManager->isLogin()){
|
||||
header('Location: ./login');
|
||||
}
|
||||
|
||||
$template = new Template('log');
|
||||
$template->prepare('title', 'Log');
|
||||
|
||||
$result = array();
|
||||
$cdir = scandir('./app/logs/');
|
||||
foreach ($cdir as $key => $value)
|
||||
{
|
||||
if (!in_array($value,array(".","..")))
|
||||
{
|
||||
$result[$value] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$template->prepare('logsFiles', $result);
|
||||
$template->prepare('lang', $lang);
|
||||
|
||||
$template->render();
|
||||
|
||||
}
|
||||
}
|
19
app/views/Login.php
Normal file
19
app/views/Login.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
class Login extends Template
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
global $userManager;
|
||||
global $lang;
|
||||
|
||||
if ($userManager->isLogin()){
|
||||
header('Location: ./');
|
||||
}
|
||||
|
||||
$template = new Template('login');
|
||||
$template->prepare('title', 'Home');
|
||||
$template->prepare('lang', $lang);
|
||||
|
||||
$template->render();
|
||||
}
|
||||
}
|
11
app/views/Logout.php
Normal file
11
app/views/Logout.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
class Logout extends Template
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
global $userManager;
|
||||
$userManager->logout();
|
||||
header('Location: /vasek/home/login', TRUE);
|
||||
die();
|
||||
}
|
||||
}
|
85
app/views/Rooms.php
Normal file
85
app/views/Rooms.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Rooms extends Template
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
global $userManager;
|
||||
global $lang;
|
||||
|
||||
if (!$userManager->isLogin()){
|
||||
header('Location: ./login');
|
||||
}
|
||||
|
||||
$template = new Template('rooms');
|
||||
|
||||
$template->prepare('title', 'Rooms');
|
||||
$template->prepare('lang', $lang);
|
||||
|
||||
$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();
|
||||
|
||||
}
|
||||
}
|
82
app/views/Scene.php
Normal file
82
app/views/Scene.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
class Scene extends Template
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
global $userManager;
|
||||
global $lang;
|
||||
|
||||
if (!$userManager->isLogin()){
|
||||
header('Location: ./');
|
||||
}
|
||||
|
||||
$template = new Template('scene');
|
||||
$template->prepare('title', 'Scény');
|
||||
$template->prepare('lang', $lang);
|
||||
|
||||
$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();
|
||||
}
|
||||
}
|
31
app/views/Setting.php
Normal file
31
app/views/Setting.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
class Setting extends Template
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
global $userManager;
|
||||
global $lang;
|
||||
|
||||
if (!$userManager->isLogin()){
|
||||
header('Location: ./login');
|
||||
}
|
||||
|
||||
$automations = [];
|
||||
$automationsData = AutomationManager::getAll();
|
||||
foreach ($automationsData as $automationKey => $automationData) {
|
||||
$automations[$automationData['automation_id']] = [
|
||||
'name' => '',
|
||||
'onDays' => $automationData['on_days'],
|
||||
'ifSomething' => $automationData['if_something'],
|
||||
'doSomething' => $automationData['do_something'],
|
||||
];
|
||||
}
|
||||
|
||||
$template = new Template('setting');
|
||||
$template->prepare('title', 'Automation');
|
||||
$template->prepare('lang', $lang);
|
||||
$template->prepare('automations', $automations);
|
||||
|
||||
$template->render();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user