AutoAction-Editor: Speichern, Laden und Loeschen
Der Editor las seine Geraete aus homeMesh, schrieb aber nach solarLog in
Tabellen, deren Fremdschluessel auf solarLog.actors/sensors zeigten. Jedes
INSERT lief damit gegen den Fremdschluessel - autoactionsSensors und
autoactionsActors sind deshalb leer geblieben, und die Aktor-Schleife war
ohnehin nie geschrieben worden.
Die Automatiken liegen jetzt in homeMesh neben dem Geraetemodell
(homeMesh_automations.sql). Eine Bedingung verweist mit einem einzigen
Fremdschluessel auf actor_states statt auf Geraet, State-URL und ein
unklares valID; Kommandoparameter stehen zeilenweise statt in vier festen
Spalten "Wert 1" bis "Wert 4". Verknuepft wird ueber group_no: gleiche
Nummer UND, verschiedene ODER, ausgewertet als any(all(gruppe)).
Im Editor ist eine Gruppe ein gerahmter Block mit eigenem "+ Bedingung",
dazwischen steht ODER - die Klammerung ist damit gezeichnet und nicht
vereinbart, und darunter steht derselbe Satz noch einmal in Worten. Die
Uebersicht zeigt ihn in der Spalte "Ausloeser" und ersetzt die bisher fest
verdrahtete Beispielzeile.
Nebenbei behoben: die Operator-Knoepfe schickten ihr innerHTML ("≠",
">") an eine Whitelist, die "!=" erwartete - jede Bedingung "ungleich"
wurde still zu "gleich". Ausgeblendete Wertfelder sendeten ihren Inhalt
trotzdem mit. Beides entfaellt, weil der Editor jetzt JSON aus einem
Modell schickt statt durchnummerierter Formularfelder.
Die vier Endpunkte fillSensorDD, fillActorDD, sensorDetails und
actorDetails entfallen: der Geraetekatalog reist einmal mit dem Editor
mit, statt je Bedingungszeile zwei Anfragen nachzuladen.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+239
-263
@@ -1,263 +1,239 @@
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
$close = 0;
|
||||
|
||||
if (checkLogin()) {
|
||||
if (isset($_POST["sensorSelect1"])) { //if form war sent add an action
|
||||
if(isset($_POST["floor"])){
|
||||
switch($_POST["floor"]){
|
||||
case "UG":
|
||||
$floor = "UG";
|
||||
break;
|
||||
case "EG":
|
||||
$floor = "EG";
|
||||
break;
|
||||
case "OG":
|
||||
$floor = "OG";
|
||||
break;
|
||||
default:
|
||||
$floor = "";
|
||||
}
|
||||
}else{
|
||||
$floor = "";
|
||||
}
|
||||
if(isset($_POST["tSpanFrom"])){
|
||||
$tFrom = date("Y-m-d H:i:s",strtotime($_POST["tSpanFrom"]));
|
||||
}else{
|
||||
$tFrom = "00:10:00";
|
||||
}
|
||||
if(isset($_POST["tSpanTo"])){
|
||||
$tTo = date("Y-m-d H:i:s",strtotime($_POST["tSpanTo"]));
|
||||
}else{
|
||||
$tTo = "23:59:00";
|
||||
}
|
||||
if(isset($_POST["runOnce"])){
|
||||
$force = true;
|
||||
}else{
|
||||
$force = false;
|
||||
}
|
||||
if(isset($_POST["actMo"])){$mo = true;}else{$mo = false;}
|
||||
if(isset($_POST["actDi"])){$di = true;}else{$di = false;}
|
||||
if(isset($_POST["actMi"])){$mi = true;}else{$mi = false;}
|
||||
if(isset($_POST["actDo"])){$do = true;}else{$do = false;}
|
||||
if(isset($_POST["actFr"])){$fr = true;}else{$fr = false;}
|
||||
if(isset($_POST["actSa"])){$sa = true;}else{$sa = false;}
|
||||
if(isset($_POST["actSo"])){$so = true;}else{$so = false;}
|
||||
if(isset($_POST["actFerien"])){$ferien = true;}else{$ferien = false;}
|
||||
if(isset($_POST["actFeier"])){$feiertag = true;}else{$feiertag = false;}
|
||||
$close = 0;
|
||||
if(isset($_POST["changeID"])){
|
||||
$id = intval($_POST["changeID"]);
|
||||
if($_POST["changeID"] != "0" && $id == 0){
|
||||
$id = -1;
|
||||
}
|
||||
}else{
|
||||
$id = -1;
|
||||
}
|
||||
$id = 2;
|
||||
$mysql = new mysqli($mysql_server, $mysql_solarUser, $mysql_solarPass, $mysql_solarDB);
|
||||
|
||||
if($id > -1){
|
||||
$qry = "UPDATE autoActions SET
|
||||
`floor` = '".$floor."', `window_from`= '".$tFrom."', `window_to` = '".$tTo."',
|
||||
`force_once` = '".$force."', `mo` = '".$mo."', `di` = '".$di."', `mi` = '".$mi."',
|
||||
`do` = '".$do."', `fr` = '".$fr."', `sa` = '".$sa."', `so` = '".$so."',
|
||||
`ferien` = '".$ferien."', `feiertag` = '".$feiertag."' WHERE id=".$id.";";
|
||||
mysqli_query($mysql, $qry);
|
||||
mysqli_query($mysql, "DELETE FROM autoactionsActors WHERE actionID=".$id.";");
|
||||
mysqli_query($mysql, "DELETE FROM autoactionsSensors WHERE actionID=".$id.";");
|
||||
$actionID = $id;
|
||||
}else{
|
||||
$qry = "INSERT into autoActions
|
||||
(`id`, `floor`, `window_from`, `window_to`, `force_once`, `mo`, `di`, `mi`, `do`, `fr`, `sa`, `so`, `ferien`, `feiertag`, `last_run`)
|
||||
VALUES (NULL, '".$floor."', '".$tFrom."', '".$tTo."', '".$force."', '".$mo."', '".$di."', '".$mi."', '".$do."', '".$fr."', '".$sa."', '".$so."', '".$ferien."', '".$feiertag."', '2020-01-01 12:00:00.000000')";
|
||||
mysqli_query($mysql, $qry);
|
||||
$actionID = mysqli_insert_id($mysql);
|
||||
}
|
||||
|
||||
//Get all Sensors:
|
||||
$num=1;
|
||||
while(isset($_POST["sensorSelect".$num])){
|
||||
$id = intval($_POST["sensorSelect".$num]);
|
||||
if($_POST["sensorSelect".$num] != "0" && $id == 0){
|
||||
$id = -1;
|
||||
}
|
||||
if(isset($_POST["btnLogic".$num])){
|
||||
if(strtolower($_POST["btnLogic".$num]) == "oder"){
|
||||
$weight = "or";
|
||||
}else{
|
||||
$weight = "and";
|
||||
}
|
||||
}else{
|
||||
$weight = "and";
|
||||
}
|
||||
if (in_array($_POST["btnOperator".$num], array('+','-','=','<','>','!='))) {
|
||||
$cond = $_POST["btnOperator".$num];
|
||||
}else{
|
||||
$cond = "=";
|
||||
echo $_POST["btnOperator".$num];
|
||||
}
|
||||
echo $_POST["btnOperator".$num];
|
||||
$valID = intval($_POST["paramSelect".$num]);
|
||||
if($_POST["paramSelect".$num] != "0" && $id == 0){
|
||||
$valID = -1;
|
||||
}
|
||||
$state = mysqli_real_escape_string($mysql, $_POST["threshold".$num]);
|
||||
|
||||
$qry = "INSERT INTO `autoactionsSensors`
|
||||
(`id`, `sensorID`, `state`, `valID`, `condType`, `link`, `actionID`)
|
||||
VALUES (NULL, '".$id."', '".$state."', '".$valID."', '".$cond."', '".$weight."', '".$actionID."')";
|
||||
mysqli_query($mysql, $qry);
|
||||
$num++;
|
||||
}
|
||||
$close=1;
|
||||
}
|
||||
} else {
|
||||
$close = 1;
|
||||
}
|
||||
if (!$close) {
|
||||
echo <<<ENDE
|
||||
<!--begin::Form-->
|
||||
<form id="heater_form">
|
||||
<div class="accordion" id="actionAccordion">
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="headingOne">
|
||||
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
|
||||
<i class="bi bi-lightning-fill"></i> Auslöser
|
||||
</button>
|
||||
</h2>
|
||||
<div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#actionAccordion">
|
||||
<div class="accordion-body" id="sensorsList">
|
||||
<div class="input-group mb-1" id="sensorSettings1">
|
||||
<div class="form-floating">
|
||||
<select class="form-select" id="sensorSelect1" name="sensorSelect1" aria-label="Default select example">
|
||||
</select>
|
||||
<label for="sensorSelect1">Sensor</label>
|
||||
</div>
|
||||
<div class="form-floating" id="paramBlock1">
|
||||
<select class="form-select" id="paramSelect1" name="paramSelect1" aria-label="Default select example">
|
||||
</select>
|
||||
<label for="paramSelect1">Messwert</label>
|
||||
</div>
|
||||
<button class="btn btn-outline-secondary" style="min-width: 40px;" type="button" id="btnOperator1" name="btnOperator1">></button>
|
||||
<div class="form-floating" id="valBlock1">
|
||||
<input type="number" class="form-control" id="threshold1" placeholder="0" value="0" name="threshold1"></input>
|
||||
<select class="form-select" id="thresholdOpt1" name="thresholdOpt1" placeholder="0" value="0"></select>
|
||||
<label for="threshold1">Wert/Schwelle</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-outline-success btn-sm" type="button" id="btnAddSensor"><i class="bi bi-plus-lg"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="headingTwo">
|
||||
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
|
||||
<i class="bi bi-calendar-check-fill"></i> Bedingungen
|
||||
</button>
|
||||
</h2>
|
||||
<div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#actionAccordion">
|
||||
<div class="accordion-body">
|
||||
<div class="input-group mb-3" id="timespan">
|
||||
<span class="input-group-text">Aktiver Zeitraum: </span>
|
||||
<div class="form-floating">
|
||||
<input type="time" class="form-control" id="tSpanFrom" name="tSpanFrom" placeholder="0" value="00:00"></input>
|
||||
<label>Von</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input type="time" class="form-control" id="tSpanTo" name="tSpanTo" placeholder="0" value="23:59"></input>
|
||||
<label>Bis</label>
|
||||
</div>
|
||||
</div>
|
||||
Aktive Wochentage:
|
||||
<div class="input-group mb-3" id="timespan">
|
||||
<div class="input-group-text">
|
||||
<input class="form-check-input mt-0 me-1" type="checkbox" value="1" id="actMo" name="actMo"><label class="form-check-label" for="actMo">Mo</label>
|
||||
</div>
|
||||
<div class="input-group-text">
|
||||
<input class="form-check-input mt-0 me-1" type="checkbox" value="1" id="actDi" name="actDi"><label class="form-check-label" for="actDi">Di</label>
|
||||
</div>
|
||||
<div class="input-group-text">
|
||||
<input class="form-check-input mt-0 me-1" type="checkbox" value="1" id="actMi" name="actMi"><label class="form-check-label" for="actMi">Mi</label>
|
||||
</div>
|
||||
<div class="input-group-text">
|
||||
<input class="form-check-input mt-0 me-1" type="checkbox" value="1" id="actDo" name="actDo"><label class="form-check-label" for="actDo">Do</label>
|
||||
</div>
|
||||
<div class="input-group-text">
|
||||
<input class="form-check-input mt-0 me-1" type="checkbox" value="1" id="actFr" name="actFr"><label class="form-check-label" for="actFr">Fr</label>
|
||||
</div>
|
||||
<div class="input-group-text">
|
||||
<input class="form-check-input mt-0 me-1" type="checkbox" value="1" id="actSa" name="actSa"><label class="form-check-label" for="actSa">Sa</label>
|
||||
</div>
|
||||
<div class="input-group-text">
|
||||
<input class="form-check-input mt-0 me-1" type="checkbox" value="1" id="actSo" name="actSo"><label class="form-check-label" for="actSo">So</label>
|
||||
</div>
|
||||
</div>
|
||||
Ferien/Feiertage:
|
||||
<div class="input-group mb-3" id="timespan">
|
||||
<div class="input-group-text">
|
||||
<input class="form-check-input mt-0 me-2" type="checkbox" value="1" id="actFerien" name="actFerien"><label class="form-check-label" for="actFerien">In den Ferien ausführen</label>
|
||||
</div>
|
||||
<div class="input-group-text">
|
||||
<input class="form-check-input mt-0 me-2" type="checkbox" value="1" id="actFeier" name="actFeier"><label class="form-check-label" for="actFeier">An Feiertagen ausführen</label>
|
||||
</div>
|
||||
</div>
|
||||
Falls die Bedingung bis zuletzt nicht erfüllt wurde:
|
||||
<div class="input-group mb-3" id="timespan">
|
||||
<div class="input-group-text">
|
||||
<input class="form-check-input mt-0 me-2" type="checkbox" value="1" id="runOnce" name="runOnce"><label class="form-check-label" for="runOnce">Auf jeden Fall zu Ende des aktiven Zeitraums ausführen</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="headingThree">
|
||||
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
|
||||
<i class="bi bi-play-fill"></i> Aktionen
|
||||
</button>
|
||||
</h2>
|
||||
<div id="collapseThree" class="accordion-collapse collapse" aria-labelledby="headingThree" data-bs-parent="#actionAccordion">
|
||||
<div class="accordion-body">
|
||||
<div class="accordion-body" id="actorsList">
|
||||
<div class="input-group mb-3" id="actorSettings1">
|
||||
<div class="form-floating">
|
||||
<select class="form-select" id="actorSelect1" name="actorSelect1">
|
||||
</select>
|
||||
<label for="actorSelect1">Aktor</label>
|
||||
</div>
|
||||
<div class="form-floating" id="actParamBlock1">
|
||||
<select class="form-select" id="actParamSelect1" name="actParamSelect1">
|
||||
</select>
|
||||
<label for="paramSelect1">Eigenschaft</label>
|
||||
</div>
|
||||
<button class="btn btn-outline-secondary" style="min-width: 40px;" type="button" id="btnActOperator1" name="btnActOperator1">></button>
|
||||
<div class="form-floating" id="act1ValBlock1">
|
||||
<input type="number" class="form-control" id="act1Value1" name="act1Value1" value="0"></input>
|
||||
<select class="form-select" id="act1ValueOpt1" name="act1ValueOpt1"></select>
|
||||
<label for="act1Value1">Wert 1</label>
|
||||
</div>
|
||||
<div class="form-floating" id="act2ValBlock1">
|
||||
<input type="number" class="form-control" id="act2Value1" name="act2Value1" value="0"></input>
|
||||
<label for="act2Value1">Wert 2</label>
|
||||
</div>
|
||||
<div class="form-floating" id="act3ValBlock1">
|
||||
<input type="number" class="form-control" id="act3Value1" name="act3Value1" value="0"></input>
|
||||
<label for="act3Value1">Wert 3</label>
|
||||
</div>
|
||||
<div class="form-floating" id="act4ValBlock1">
|
||||
<input type="number" class="form-control" id="act4Value1" name="act4Value1" value="0"></input>
|
||||
<label for="act4Value1">Wert 4</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-outline-success btn-sm" type="button" id="btnAddActor"><i class="bi bi-plus-lg"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
ENDE;
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Endpunkt fuer die Automatiken: Editor, Uebersicht, Speichern, Loeschen.
|
||||
*
|
||||
* Alles laeuft ueber ?action=... , damit Formular und Uebersicht dieselbe
|
||||
* Modell-Schicht (restricted/automations.php) benutzen und nicht zwei
|
||||
* Wahrheiten ueber denselben Datensatz entstehen.
|
||||
*
|
||||
* GET ?action=editor&id=N Editor fuer eine vorhandene Automatik
|
||||
* GET ?action=editor&floor=OG Editor fuer eine neue Automatik
|
||||
* GET ?action=list&floor=OG Tabelle fuer die Karte "Automatismen"
|
||||
* POST ?action=save JSON-Rumpf, legt an oder ueberschreibt
|
||||
* POST ?action=delete {"id": N}
|
||||
* POST ?action=toggle {"id": N} - pausieren / fortsetzen
|
||||
*/
|
||||
|
||||
require_once("../helper.php");
|
||||
require_once("../restricted/automations.php");
|
||||
|
||||
if (!checkLogin()) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
function jsonAntwort($data, $code = 200)
|
||||
{
|
||||
http_response_code($code);
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$action = $_GET["action"] ?? "editor";
|
||||
$floor = in_array($_GET["floor"] ?? "", ["UG", "EG", "OG"], true) ? $_GET["floor"] : "";
|
||||
|
||||
// --- Schreibende Aufrufe -------------------------------------------------
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$body = json_decode(file_get_contents("php://input"), true);
|
||||
if (!is_array($body)) {
|
||||
jsonAntwort(["error" => "Konnte die Anfrage nicht lesen."], 400);
|
||||
}
|
||||
try {
|
||||
switch ($action) {
|
||||
case "save":
|
||||
$id = saveAutomation($body);
|
||||
jsonAntwort(["id" => $id]);
|
||||
case "delete":
|
||||
deleteAutomation(intval($body["id"] ?? 0));
|
||||
jsonAntwort(["ok" => true]);
|
||||
case "toggle":
|
||||
jsonAntwort(["enabled" => toggleAutomation(intval($body["id"] ?? 0))]);
|
||||
default:
|
||||
jsonAntwort(["error" => "Unbekannte Aktion."], 400);
|
||||
}
|
||||
} catch (InvalidArgumentException $e) {
|
||||
jsonAntwort(["error" => $e->getMessage()], 400);
|
||||
} catch (Throwable $e) {
|
||||
jsonAntwort(["error" => "Speichern fehlgeschlagen: " . $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// --- Uebersichtstabelle --------------------------------------------------
|
||||
if ($action === "list") {
|
||||
$tage = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"];
|
||||
$list = listAutomations($floor);
|
||||
if (!$list) {
|
||||
echo "<p class='text-body-secondary mb-2'>Für diese Etage ist noch nichts eingerichtet.</p>";
|
||||
} else {
|
||||
echo "<div class='table-responsive'><table class='table table-hover align-middle'>";
|
||||
echo "<thead><tr><th>Name</th><th>Auslöser</th><th>Aktion</th><th>Wann</th>"
|
||||
. "<th>Zuletzt</th><th></th></tr></thead><tbody>";
|
||||
foreach ($list as $a) {
|
||||
// Nur die aktiven Tage nennen. Sieben Haekchen untereinander
|
||||
// haben die Zeile frueher unnoetig hoch gemacht.
|
||||
$aktiveTage = [];
|
||||
for ($i = 0; $i < 7; $i++) {
|
||||
if ($a["weekdays"] & (1 << $i)) {
|
||||
$aktiveTage[] = $tage[$i];
|
||||
}
|
||||
}
|
||||
$wann = count($aktiveTage) === 7 ? "täglich" : implode(" ", $aktiveTage);
|
||||
if ($a["window_from"] !== "00:00" || $a["window_to"] !== "23:59") {
|
||||
$wann .= ", " . $a["window_from"] . "–" . $a["window_to"];
|
||||
}
|
||||
if (!$a["on_holiday"]) {
|
||||
$wann .= ", nicht an Feiertagen";
|
||||
}
|
||||
if (!$a["on_vacation"]) {
|
||||
$wann .= ", nicht in den Ferien";
|
||||
}
|
||||
|
||||
$zuletzt = $a["last_run"] ? date("d.m. H:i", strtotime($a["last_run"])) : "–";
|
||||
$klasse = $a["enabled"] ? "" : " class='opacity-50'";
|
||||
$pause = $a["enabled"] ? "bi-pause-fill" : "bi-play-fill";
|
||||
$titel = $a["enabled"] ? "Pausieren" : "Fortsetzen";
|
||||
$id = intval($a["id"]);
|
||||
|
||||
echo "<tr" . $klasse . ">";
|
||||
echo "<td>" . htmlspecialchars($a["name"]) . "</td>";
|
||||
echo "<td>" . htmlspecialchars($a["conditionText"]) . "</td>";
|
||||
echo "<td>" . htmlspecialchars($a["actionText"]) . "</td>";
|
||||
echo "<td class='text-nowrap'>" . htmlspecialchars($wann) . "</td>";
|
||||
echo "<td class='text-nowrap'>" . $zuletzt . "</td>";
|
||||
echo "<td class='text-nowrap'>"
|
||||
. "<button type='button' class='btn btn-info btn-sm' title='" . $titel . "'"
|
||||
. " onclick='toggleAutomation(" . $id . ")'><i class='bi " . $pause . "'></i></button> "
|
||||
. "<button type='button' class='btn btn-warning btn-sm' title='Bearbeiten'"
|
||||
. " onclick=\"openAutoActionModal('?action=editor&id=" . $id . "')\"><i class='bi bi-pencil-square'></i></button> "
|
||||
. "<button type='button' class='btn btn-danger btn-sm' title='Löschen'"
|
||||
. " onclick='deleteAutomation(" . $id . ", \"" . htmlspecialchars($a["name"], ENT_QUOTES) . "\")'><i class='bi bi-trash3'></i></button>"
|
||||
. "</td></tr>";
|
||||
}
|
||||
echo "</tbody></table></div>";
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
// --- Editor --------------------------------------------------------------
|
||||
$id = intval($_GET["id"] ?? 0);
|
||||
$auto = $id > 0 ? loadAutomation($id) : null;
|
||||
if (!$auto) {
|
||||
$auto = emptyAutomation($floor);
|
||||
}
|
||||
|
||||
// Geraetekatalog und Datensatz reisen im selben Dokument mit. Frueher holte
|
||||
// der Editor die Geraeteliste und je Zeile noch einmal deren Details nach -
|
||||
// zwei zusaetzliche Anfragen pro Bedingung, und die Dropdowns fuellten sich
|
||||
// asynchron, weshalb ein gespeicherter Wert nicht zuverlaessig ankam.
|
||||
$nutzdaten = json_encode([
|
||||
"automation" => $auto,
|
||||
"devices" => deviceCatalog(),
|
||||
], JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);
|
||||
|
||||
?>
|
||||
<script type="application/json" id="autoActionData"><?= $nutzdaten ?></script>
|
||||
<form id="autoActionForm" class="p-2">
|
||||
<div class="row g-2 mb-2">
|
||||
<div class="col-8">
|
||||
<div class="form-floating">
|
||||
<input type="text" class="form-control" id="autoName" placeholder="Name" maxlength="100">
|
||||
<label for="autoName">Name der Automatik</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<div class="form-floating">
|
||||
<select class="form-select" id="autoFloor">
|
||||
<option value="">–</option>
|
||||
<option value="UG">UG</option>
|
||||
<option value="EG">EG</option>
|
||||
<option value="OG">OG</option>
|
||||
</select>
|
||||
<label for="autoFloor">Etage</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="accordion" id="actionAccordion">
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header">
|
||||
<button class="accordion-button" type="button" data-bs-toggle="collapse"
|
||||
data-bs-target="#collapseOne" aria-expanded="true">
|
||||
<i class="bi bi-lightning-fill"></i> Auslöser
|
||||
</button>
|
||||
</h2>
|
||||
<div id="collapseOne" class="accordion-collapse collapse show" data-bs-parent="#actionAccordion">
|
||||
<div class="accordion-body">
|
||||
<!-- Ein Block ist eine UND-Gruppe, zwischen den Bloecken steht ODER.
|
||||
Die Klammerung ist damit gezeichnet und nicht bloss vereinbart. -->
|
||||
<div id="condBlocks"></div>
|
||||
<button class="btn btn-outline-secondary btn-sm mt-2" type="button" id="btnAddGroup">
|
||||
<i class="bi bi-plus-lg"></i> Alternative (oder)
|
||||
</button>
|
||||
<div class="alert alert-secondary mt-3 mb-0 py-2 small" id="condSummary"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header">
|
||||
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
|
||||
data-bs-target="#collapseTwo" aria-expanded="false">
|
||||
<i class="bi bi-calendar-check-fill"></i> Bedingungen
|
||||
</button>
|
||||
</h2>
|
||||
<div id="collapseTwo" class="accordion-collapse collapse" data-bs-parent="#actionAccordion">
|
||||
<div class="accordion-body">
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">Aktiver Zeitraum</span>
|
||||
<div class="form-floating">
|
||||
<input type="time" class="form-control" id="tSpanFrom" value="00:00">
|
||||
<label for="tSpanFrom">Von</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input type="time" class="form-control" id="tSpanTo" value="23:59">
|
||||
<label for="tSpanTo">Bis</label>
|
||||
</div>
|
||||
</div>
|
||||
Aktive Wochentage:
|
||||
<div class="input-group mb-3" id="weekdayGroup"></div>
|
||||
<div class="input-group mb-3">
|
||||
<div class="input-group-text">
|
||||
<input class="form-check-input mt-0 me-2" type="checkbox" id="actFerien">
|
||||
<label class="form-check-label" for="actFerien">In den Ferien ausführen</label>
|
||||
</div>
|
||||
<div class="input-group-text">
|
||||
<input class="form-check-input mt-0 me-2" type="checkbox" id="actFeier">
|
||||
<label class="form-check-label" for="actFeier">An Feiertagen ausführen</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-group mb-0">
|
||||
<div class="input-group-text">
|
||||
<input class="form-check-input mt-0 me-2" type="checkbox" id="runOnce">
|
||||
<label class="form-check-label" for="runOnce">
|
||||
Am Ende des Zeitraums auf jeden Fall ausführen, falls der Auslöser nie zutraf
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header">
|
||||
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
|
||||
data-bs-target="#collapseThree" aria-expanded="false">
|
||||
<i class="bi bi-play-fill"></i> Aktionen
|
||||
</button>
|
||||
</h2>
|
||||
<div id="collapseThree" class="accordion-collapse collapse" data-bs-parent="#actionAccordion">
|
||||
<div class="accordion-body">
|
||||
<div id="actionList"></div>
|
||||
<button class="btn btn-outline-success btn-sm mt-2" type="button" id="btnAddActor">
|
||||
<i class="bi bi-plus-lg"></i> Aktion
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
require_once("../helper.php");
|
||||
|
||||
// Der Endpunkt gibt Geraetenamen und Steuer-URLs aus der homeMesh-
|
||||
// Datenbank aus und war bisher ohne Anmeldung erreichbar.
|
||||
if (!checkLogin()) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
if(isset($_GET["actorID"])){
|
||||
$actorID = intval($_GET["actorID"]);
|
||||
$qry = "SELECT command_name, command_url, parameter_type, min_value, max_value, possible_values, command_parameters.url AS parameter_url, parameter_name FROM actor_commands LEFT JOIN command_parameters ON actor_commands.id = command_id LEFT JOIN state_types ON parameter_type = state_types.id WHERE actor_id=".$actorID;
|
||||
$qry = "SELECT id, command_name, command_url FROM actor_commands WHERE actor_id = ".$actorID;
|
||||
$mysql = new mysqli($mysql_server, $mysql_MeshUser, $mysql_MeshPass, $mysql_MeshDB);
|
||||
$result = mysqli_query($mysql, $qry);
|
||||
$operators = "";
|
||||
//while($row = $result->fetch_assoc()){
|
||||
// print_r($row);
|
||||
// echo "<br />";
|
||||
//}
|
||||
echo '{"commands": [';
|
||||
$iterated = 0;
|
||||
while($row = $result->fetch_assoc()){
|
||||
$items = "[]";
|
||||
$qry2 = "SELECT parameter_type, min_value, max_value, possible_values, command_parameters.url AS parameter_url, parameter_name FROM actor_commands LEFT JOIN command_parameters ON actor_commands.id = command_id LEFT JOIN state_types ON parameter_type = state_types.id WHERE command_id = ".$row["id"];
|
||||
$result2 = mysqli_query($mysql, $qry2);
|
||||
if($iterated++){
|
||||
echo ", ";
|
||||
}
|
||||
echo '{"name" : "'.$row["command_name"].'", "operators" : ["="], "parameters": [';
|
||||
$iterated2 = 0;
|
||||
$type = "hidden";
|
||||
while($row2 = $result2->fetch_assoc()){
|
||||
switch($row2["parameter_type"]){
|
||||
case "integer":
|
||||
if($row2["possible_values"]){
|
||||
$items = $row2["possible_values"];
|
||||
$type = "dropdown";
|
||||
}else{
|
||||
$type = "number";
|
||||
}
|
||||
break;
|
||||
case "float":
|
||||
$type = "number";
|
||||
break;
|
||||
case "time":
|
||||
$type = "time";
|
||||
break;
|
||||
case "bool":
|
||||
$type = "button";
|
||||
break;
|
||||
case "string":
|
||||
if($row2["possible_values"]){
|
||||
$items = $row2["possible_values"];
|
||||
$type = "dropdown";
|
||||
}else{
|
||||
$type = "text";
|
||||
}
|
||||
break;
|
||||
case "":
|
||||
$type = "hidden";
|
||||
default:
|
||||
$type = "text";
|
||||
break;
|
||||
}
|
||||
if($iterated2++){
|
||||
echo ", ";
|
||||
}
|
||||
echo '{"name" : "'.$row2["parameter_name"].'", "url" : "'.$row2["parameter_url"].'", "type" : "'.$type.'", "options" : '.$items.'}';
|
||||
}
|
||||
echo '], "type" : "'.$type.'"}';
|
||||
}
|
||||
echo "]}";
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
require_once("../helper.php");
|
||||
if(isset($_GET["actorID"])){
|
||||
$ID = intval($_GET["actorID"]);
|
||||
$qry = "SELECT parameters FROM actors WHERE id=".$ID;
|
||||
$mysql = new mysqli($mysql_server, $mysql_solarUser, $mysql_solarPass, $mysql_solarDB);
|
||||
$result = mysqli_query($mysql, $qry);
|
||||
echo $result->fetch_array()[0];
|
||||
}
|
||||
|
||||
*/
|
||||
?>
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
require_once("../helper.php");
|
||||
|
||||
// Der Endpunkt gibt Geraetenamen und Steuer-URLs aus der homeMesh-
|
||||
// Datenbank aus und war bisher ohne Anmeldung erreichbar.
|
||||
if (!checkLogin()) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
$qry = "SELECT name, actors.id FROM actors INNER JOIN actor_commands ON actor_id = actors.id GROUP BY actors.id";
|
||||
$mysql = new mysqli($mysql_server, $mysql_MeshUser, $mysql_MeshPass, $mysql_MeshDB);
|
||||
$result = mysqli_query($mysql, $qry);
|
||||
|
||||
while($row = $result->fetch_assoc()){
|
||||
echo "<option value='".$row["id"]."'>".$row["name"]."</option>";
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
require_once("../helper.php");
|
||||
|
||||
// Der Endpunkt gibt Geraetenamen und Steuer-URLs aus der homeMesh-
|
||||
// Datenbank aus und war bisher ohne Anmeldung erreichbar.
|
||||
if (!checkLogin()) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
$qry = "SELECT name, actors.id FROM actors INNER JOIN actor_states ON actor_id = actors.id GROUP BY actors.id";
|
||||
$mysql = new mysqli($mysql_server, $mysql_MeshUser, $mysql_MeshPass, $mysql_MeshDB);
|
||||
$result = mysqli_query($mysql, $qry);
|
||||
|
||||
while($row = $result->fetch_assoc()){
|
||||
echo "<option value='".$row["id"]."'>".$row["name"]."</option>";
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
require_once("../helper.php");
|
||||
|
||||
// Der Endpunkt gibt Geraetenamen und Steuer-URLs aus der homeMesh-
|
||||
// Datenbank aus und war bisher ohne Anmeldung erreichbar.
|
||||
if (!checkLogin()) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
if(isset($_GET["sensorID"])){
|
||||
$sensorID = intval($_GET["sensorID"]);
|
||||
$qry = "SELECT state_name, url, state_types.type, unit, current_value, possible_values FROM actor_states LEFT JOIN state_types ON state_type = state_types.id WHERE actor_id=".$sensorID;
|
||||
$mysql = new mysqli($mysql_server, $mysql_MeshUser, $mysql_MeshPass, $mysql_MeshDB);
|
||||
$result = mysqli_query($mysql, $qry);
|
||||
$operators = "";
|
||||
echo '{"parameters": [';
|
||||
$iterated = 0;
|
||||
$items = "[]";
|
||||
while($row = $result->fetch_assoc()){
|
||||
switch($row["type"]){
|
||||
case "integer":
|
||||
$operators = '["=","≠",">","<"]';
|
||||
$type = "number";
|
||||
break;
|
||||
case "float":
|
||||
$operators = '["=","≠",">","<"]';
|
||||
$type = "number";
|
||||
break;
|
||||
case "time":
|
||||
$operators = '["=","≠"]';
|
||||
$type = "time";
|
||||
break;
|
||||
case "deltatime":
|
||||
$operators = '["+","-"]';
|
||||
$type = "time";
|
||||
break;
|
||||
case "date":
|
||||
$operators = '["=","≠"]';
|
||||
$type = "date";
|
||||
break;
|
||||
case "datetime":
|
||||
$operators = '["=","≠"]';
|
||||
$type = "datetime-local";
|
||||
break;
|
||||
case "bool":
|
||||
$operators = '["= JA","= NEIN"]';
|
||||
$type = "button";
|
||||
break;
|
||||
case "string":
|
||||
$operators = '["=","≠"]';
|
||||
if($row["possible_values"]){
|
||||
$items = $row["possible_values"];
|
||||
$type = "dropdown";
|
||||
}else{
|
||||
$operators = '["=","≠"]';
|
||||
$type = "text";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$operators = '["=","≠"]';
|
||||
$type = "text";
|
||||
break;
|
||||
}
|
||||
if($iterated++){
|
||||
echo ", ";
|
||||
}
|
||||
if($row["current_value"]){
|
||||
$row["state_name"] .= " (=".$row["current_value"].")";
|
||||
}
|
||||
echo '{"name" : "'.$row["state_name"].'", "operators" : '.$operators.', "url" : "'.$row["url"].'", "type" : "'.$type.'", "options" : '.$items.'}';
|
||||
}
|
||||
echo "]}";
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user