1
0

added some javascript to webserver\nsome debugging

This commit is contained in:
2022-03-06 01:30:33 +01:00
parent a2d2909a23
commit 9dde1c2d53
13 changed files with 230 additions and 179 deletions

View File

@ -1,40 +1,56 @@
<?php
require_once "events.php";
function webDashboard($socket, $n = 0, $page="/")
function webDashboard($socket, $n="Général", $page="/")
{
global $dashboards, $indexDevices;
require_once "webserver/javascript.php";
logger(DEBUG, _("webDashboard function"));
$response = ''; //<form action="action.php" method="get">
$response = insertJavascript();
if(array_key_exists($n, $dashboards))
{
foreach ($dashboards[$n] as $array)
{
print_r($array);
$device = $indexDevices[$array[0]];
$property = $array[1];
$propertyObject = $device->properties[$property];
$value = $propertyObject["value"];
if ($value === null)
if (array_key_exists($array[0], $indexDevices))
{
$value = "null";
}
logger(DEBUG, $device->friendlyName . " => " . bool2string(_($value)));
$response .= $device->friendlyName . aliases($device->friendlyName, $property) . " => " . bool2string(_($value)) . EOL;
if (array_key_exists("access", $propertyObject))
$device = $indexDevices[$array[0]];
$property = $array[1];
if (array_key_exists($array[1], $device->properties))
{
$propertyObject = $device->properties[$property];
$value = $propertyObject["value"];
if ($value === null)
{
$value = "null";
}
logger(DEBUG, $device->friendlyName . " => " . bool2string(_($value)));
$response .= $device->friendlyName . aliases($device->friendlyName, $property) . " => " . bool2string(_($value)) . EOL;
if (array_key_exists("access", $propertyObject))
{
logger(DEBUG, _("Access = ") . $propertyObject["access"], __FILE__ . ":" . __LINE__);
if(($propertyObject["access"] & 2))
{
logger(DEBUG, _("Write Access OK ") . ($propertyObject["access"] & 2), __FILE__ . ":" . __LINE__);
$response .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . displayChoice($device, $property) . EOL;
}
if(($propertyObject["access"] & 4))
{
logger(DEBUG, _("can get value") . ($propertyObject["access"] & 4), __FILE__ . ":" . __LINE__);
$response .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $propertyObject["name"] . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "','" . $device->friendlyName . "','" . $propertyObject["name"] . "')\"><br>" . EOL;
}
}else
{
$response .= EOLH;
}
}else
{
logger(ERROR, _("Property do not exist"), __FILE__ . ":" . __LINE__);
}
}else
{
logger(DEBUG, _("Access = ") . $propertyObject["access"], __FILE__ . ":" . __LINE__);
if(($propertyObject["access"] & 2))
{
logger(DEBUG, _("Write Access OK ") . ($propertyObject["access"] & 2), __FILE__ . ":" . __LINE__);
$response .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . displayChoice($device, $property) . EOL;
}
if(($propertyObject["access"] & 4))
{
logger(DEBUG, _("can get value") . ($propertyObject["access"] & 4), __FILE__ . ":" . __LINE__);
$response .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $propertyObject["name"] . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "','" . $propertyObject["name"] . "')\"><br>" . EOL;
}
logger(ERROR, _("Device do not exist"), __FILE__ . ":" . __LINE__);
}
}
}else
@ -79,7 +95,7 @@ function displayChoice($device, $propertyName)
{
$formHTML .= ' step="' . $propertyObject["value_step"] . '"';
}
$formHTML .= " onchange=\"setPropertyValue('" . $device->topic . "', this.value, '" . $propertyObject["name"] . "')\">";
$formHTML .= " onchange=\"setPropertyValue('" . $device->topic . "', '" . $device->friendlyName . "', this.value, '" . $propertyObject["name"] . "')\">";
break;
case "enum":
@ -98,7 +114,7 @@ function mkHTML($device, $propertyName, $choice)
logger(DEBUG, _("function mkHTML"), __FILE__ . ":" . __LINE__);
foreach ($choice as $key => $value)
{
$html .= '<input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $propertyName . "/" . $key . '" value="' . $value . "\" onmouseup=\"setPropertyValue('" . $device->topic . "', '" . $value . "', '" . $propertyName . "')\">";
$html .= '<input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $propertyName . "/" . $key . '" value="' . $value . "\" onmouseup=\"setPropertyValue('" . $device->topic . "', '" . $device->friendlyName . "', '" . $value . "', '" . $propertyName . "')\">";
}
return $html;
}
@ -147,29 +163,8 @@ function webBrowse($socket, $argList, $page="/browse")
if (is_a($device, "device"))
{
$response .= '<script language="javascript">
<!--
function setPropertyValue(topic, value, property)
{
let xhr = new XMLHttpRequest();
xhr.open("GET", "http://192.168.1.253:' . $listenPort . '/set&fn=' . $device->friendlyName . '&property="+property+"&topic="+topic+"&value="+value);
xhr.onload = function () {};
xhr.send();
}
function getPropertyValue(topic,property)
{
let xhr = new XMLHttpRequest();
xhr.open("GET", "http://192.168.1.253:' . $listenPort . '/get&fn=' . $device->friendlyName . '&property="+property+"&topic="+topic );
xhr.onload = function () {};
xhr.send();
setTimeout(function()
{
location.reload();
}, 1000);
}
// -->
</script>';
require_once "webserver/javascript.php";
$response .= insertJavascript();
foreach($device->properties as $key => $value)
{
$response .= $key . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
@ -183,7 +178,7 @@ function webBrowse($socket, $argList, $page="/browse")
if(($value["access"] & 4))
{
logger(DEBUG, _("can get value") . ($value["access"] & 4), __FILE__ . ":" . __LINE__);
$response .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $key . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "', '" . $key . "')\">";
$response .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $key . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "', '" . $device->friendlyName . "', '" . $key . "')\">";
}
}
$response .= "<br>\n" . $tab . "[<br>\n";

29
webserver/javascript.php Normal file
View File

@ -0,0 +1,29 @@
<?php
function insertJavascript()
{
global $listenPort;
return '<script language="javascript">
<!--
function setPropertyValue(topic, fn, value, property)
{
let xhr = new XMLHttpRequest();
xhr.open("GET", "http://192.168.1.253:' . $listenPort . '/set&fn="+fn+"&property="+property+"&topic="+topic+"&value="+value);
xhr.onload = function () {};
xhr.send();
}
function getPropertyValue(topic, fn, property)
{
let xhr = new XMLHttpRequest();
xhr.open("GET", "http://192.168.1.253:' . $listenPort . '/get&fn="+fn+"&property="+property+"&topic="+topic );
xhr.onload = function () {};
xhr.send();
setTimeout(function()
{
location.reload();
}, 1000);
}
// -->
</script>';
}
?>

View File

@ -1,8 +0,0 @@
<script>
function sendRange(value, property)
{
let xhr = new XMLHttpRequest();
xhr.open("GET", "http://localhost:' . $listenPort . '/set&fn=' . $device->friendlyName . '&property="+property+"&topic=' . $device->topic . '&value=" + value);
xhr.send();
}
<script>