1
0

a lot of bugs corrected\nrdc_wc_eclairage

This commit is contained in:
2022-03-13 22:33:26 +01:00
parent 9dde1c2d53
commit c8772aeda0
24 changed files with 534 additions and 191 deletions

View File

@ -1,7 +1,7 @@
<?php
require_once "events.php";
function webDashboard($socket, $n="Général", $page="/")
function webDashboard($socket, $n="Général")
{
global $dashboards, $indexDevices;
require_once "webserver/javascript.php";
@ -18,13 +18,8 @@ function webDashboard($socket, $n="Général", $page="/")
$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))
@ -33,17 +28,15 @@ function webDashboard($socket, $n="Général", $page="/")
if(($propertyObject["access"] & 2))
{
logger(DEBUG, _("Write Access OK ") . ($propertyObject["access"] & 2), __FILE__ . ":" . __LINE__);
$response .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . displayChoice($device, $property) . EOL;
$response .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . displayChoice($device, $property);
}
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;
$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"] . "')\">";
}
}else
{
$response .= EOLH;
}
$response .= EOLH;
}else
{
logger(ERROR, _("Property do not exist"), __FILE__ . ":" . __LINE__);
@ -167,25 +160,7 @@ function webBrowse($socket, $argList, $page="/browse")
$response .= insertJavascript();
foreach($device->properties as $key => $value)
{
$response .= $key . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
if (array_key_exists("access", $value))
{
if(($value["access"] & 2))
{
logger(DEBUG, _("Write Access OK ") . ($value["access"] & 2), __FILE__ . ":" . __LINE__);
$response .= displayChoice($device, $key);
}
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 . "', '" . $device->friendlyName . "', '" . $key . "')\">";
}
}
$response .= "<br>\n" . $tab . "[<br>\n";
//echo memory_get_usage();
//$response = value($key, $value, $response);
iterateProperty($device, $key, $value, $response, $tab);
$response .= $tab . "]<br>\n";
$response = displayProperty($device, $key, $value, $response);
}
/*foreach($device->properties as $key => $value)
{
@ -228,6 +203,30 @@ function webBrowse($socket, $argList, $page="/browse")
htmlSend($socket, $response);
}
function displayProperty($device, $key, $value, $response)
{
$response .= $key . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
if (array_key_exists("access", $value))
{
if(($value["access"] & 2))
{
logger(DEBUG, _("Write Access OK ") . ($value["access"] & 2), __FILE__ . ":" . __LINE__);
$response .= displayChoice($device, $key);
}
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 . "', '" . $device->friendlyName . "', '" . $key . "')\">";
}
}
$response .= "<br>\n" . $tab . "[<br>\n";
//echo memory_get_usage();
//$response = value($key, $value, $response);
iterateProperty($device, $key, $value, $response, $tab);
$response .= $tab . "]<br>\n";
return $response;
}
function iterateProperty($device, $property, $value, &$response, $tab="")
{
$tab .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
@ -367,5 +366,21 @@ function webNotify($argList)
$response = _("notify command have been set");
$monitored[] = new watch($argList["topic"], $argList["fn"], $argList["property"], $argList["condition"], $argList["value"]);
}
return $response;
}
/*
function webDisplayByType($argList)
{
global $indexTypes, $config;
require_once $config . "porpertiesbytype.php";
require_once "webserver/javascript.php";
$response .= insertJavascript();
foreach($indexTypes[$argList["type"]] as $device)
{
foreach($)
displayProperty($device, $device->, $value, $response)
}
}
*/
?>

View File

@ -28,7 +28,6 @@ function htmlSend($socket, $text, $meta="")
"Connection: close" . EOLR .
"Content-Type: text/html; charset=UTF-8" . EOLR . EOLR;
$response = $httpHeader . '<!doctype html>' . EOL . '<html lang="fr">' . EOL . '<head>' . EOL . $meta . EOL . '<meta charset="utf-8">' . EOL . '<title>Moha</title>' . EOL . '</head><body>' . EOL . $text . "</body></html>";
stream_socket_sendto($socket, $response);
}
@ -62,11 +61,13 @@ function askWebServer($read)
$argList["cmd"] = trim($tmp);
}else
{
$argList[trim(strchr($tmp, "=", true))] = trim(substr(strchr($tmp, "="), 1));
$key = trim(strchr($tmp, "=", true));
$argList[$key] = trim(substr(strchr($tmp, "="), 1));
if (count($argTmp) == 1) $argList["cmd"] = $key;
}
}
logger(DEBUG, print_r($argList, true), __FILE__ . ":" . __LINE__);
logger(DEBUG, print_r($argList, true), __FILE__ . ":" . __LINE__);
if(array_key_exists("cmd", $argList))
{
$command = strtolower($argList["cmd"]);
@ -74,11 +75,11 @@ function askWebServer($read)
switch($command)
{
case "dashboard":
webDashboard($spawn, $argList["dashboard"], $argList["page"]);
webDashboard($spawn, $argList["dashboard"]);
break;
case "browse":
logger(DEBUG, _("Browsing"), __FILE__ . ":" . __LINE__);
webBrowse($spawn, $argList, $argList["page"]);
webBrowse($spawn, $argList);
//return true;
break;
case "get":
@ -99,6 +100,9 @@ function askWebServer($read)
htmlSend($spawn, webNotify($argList));
logger(DEBUG, print_r($monitored, true), __FILE__ . ":" . __LINE__);
break;
case "type":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, webDisplayByType($argList));
default:
if (is_numeric(array_key_first($argList)))
{