Errors fixed when creating/managing products

This commit is contained in:
jens 2021-05-08 15:07:52 +02:00
parent 84e73a9ec5
commit 0971e3cfaf

View File

@ -5,9 +5,15 @@
See https://server47.de for more information. See https://server47.de for more information.
*/ */
// ini_set('display_errors', 0);
// error_reporting(0);
error_reporting(E_ALL & E_NOTICE);
ini_set("display_errors","on");
require_once("shoppingListConfig.php"); require_once("shoppingListConfig.php");
$justCreatedProductId; $justCreatedProductId = null;
$iconDelete = ""; $iconDelete = "";
$iconSave = "💾"; $iconSave = "💾";
@ -1003,8 +1009,9 @@
<?php <?php
$command = $_POST['command']; if(isset($_POST['command']))
$listId; $command = $_POST['command'];
$listId = null;
if(isset($command)) if(isset($command))
{ {
@ -1050,12 +1057,11 @@
case "createProduct": case "createProduct":
$p = new Product(); $p = new Product();
$p->setID($_POST['oldProductId']);
if(strpos($_POST['productName'], ";") !== false) if(strpos($_POST['productName'], ";") !== false)
{ {
$terms = explode(";", $_POST['productName']); $terms = explode(";", $_POST['productName']);
$p->setName = $terms[0]; $p->setName(trim($terms[0]));
$syns = ""; $syns = "";
for($i=1; $i<count($terms); $i++) for($i=1; $i<count($terms); $i++)
@ -1088,8 +1094,25 @@
case "manageProduct": case "manageProduct":
$p = new Product(); $p = new Product();
$p->setID($_POST['oldProductId']); $p->setID($_POST['oldProductId']);
$p->setName($_POST['productName']); if(strpos($_POST['productName'], ";") !== false)
$p->setSynonyms($_POST['productSynonyms']); {
$terms = explode(";", $_POST['productName']);
$p->setName(trim($terms[0]));
$syns = "";
for($i=1; $i<count($terms); $i++)
{
$currentWord = trim($terms[$i]);
if(strlen($currentWord) > 0)
$syns .= ";".$currentWord;
}
$syns = ltrim($syns, ';');
$p->setSynonyms($syns);
}
else
$p->setName($_POST['productName']);
$p->setStoreType(StoreType::getById($_POST['productStoreTypeId'])); $p->setStoreType(StoreType::getById($_POST['productStoreTypeId']));
GLOBAL $iconDelete; GLOBAL $iconDelete;
@ -1200,7 +1223,10 @@
echo "Invalid command."; echo "Invalid command.";
break; break;
case "trainRhasspy": case "trainRhasspy":
echo "Triggering training in Rhasspy has not been implemented, yet."; if(triggerRhasspyTraining())
echo "Rhasspy training has completed successfully.";
else
echo "Rhasspy training has failed.";
break; break;
} }
} }
@ -1311,7 +1337,7 @@
{ {
$currentId = (int)$product->getID(); $currentId = (int)$product->getID();
if(isset($justCreatedProductId) && $justCreatedProductId === $currentId) if(isset($justCreatedProductId) && $justCreatedProductId != null && $justCreatedProductId === $currentId)
echo "<option value=\"".$product->getID()."\" name=\"".$product->getName()."\" selected=\"selected\">".$product->getName()."</option>"; echo "<option value=\"".$product->getID()."\" name=\"".$product->getName()."\" selected=\"selected\">".$product->getName()."</option>";
else else
echo "<option value=\"".$product->getID()."\" name=\"".$product->getName()."\">".$product->getName()."</option>"; echo "<option value=\"".$product->getID()."\" name=\"".$product->getName()."\">".$product->getName()."</option>";
@ -1441,7 +1467,7 @@
$detailsName = "detailsMaintenance"; $detailsName = "detailsMaintenance";
$openString = ""; $openString = "";
if(in_array($detailsName, explode(";", $_POST['openDetailsElements']))) if(isset($_POST['openDetailsElements']) && in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
$openString = " open=\"\""; $openString = " open=\"\"";
echo "<details id=\"".$detailsName."\"".$openString." ontoggle=\"rememberToggleState(this)\"> echo "<details id=\"".$detailsName."\"".$openString." ontoggle=\"rememberToggleState(this)\">
@ -1454,7 +1480,7 @@
$detailsName = "detailsLists"; $detailsName = "detailsLists";
$openString = ""; $openString = "";
if(in_array($detailsName, explode(";", $_POST['openDetailsElements']))) if(isset($_POST['openDetailsElements']) && in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
$openString = " open=\"\""; $openString = " open=\"\"";
echo " <details id=\"".$detailsName."\"".$openString." ontoggle=\"rememberToggleState(this)\"> echo " <details id=\"".$detailsName."\"".$openString." ontoggle=\"rememberToggleState(this)\">
@ -1508,7 +1534,7 @@
$detailsName = "detailsRhasspy"; $detailsName = "detailsRhasspy";
$openString = ""; $openString = "";
if(in_array($detailsName, explode(";", $_POST['openDetailsElements']))) if(isset($_POST['openDetailsElements']) && in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
$openString = " open=\"\""; $openString = " open=\"\"";
echo " <details id=\"".$detailsName."\"".$openString." ontoggle=\"rememberToggleState(this)\"> echo " <details id=\"".$detailsName."\"".$openString." ontoggle=\"rememberToggleState(this)\">
@ -1518,6 +1544,8 @@
<h3>Train Rhasspy</h3> <h3>Train Rhasspy</h3>
WARNING: This can take up to 2 minutes.<br><br>
<form id=\"trainRhasspyForm\" action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\" onSubmit=\"addToggleStates(this)\"> <form id=\"trainRhasspyForm\" action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\" onSubmit=\"addToggleStates(this)\">
<input type=\"hidden\" id=\"command\" name=\"command\" value=\"trainRhasspy\" /> <input type=\"hidden\" id=\"command\" name=\"command\" value=\"trainRhasspy\" />
<input type=\"submit\" value=\"🚂\" style=\"font-size : 25px;\" /> <input type=\"submit\" value=\"🚂\" style=\"font-size : 25px;\" />
@ -1526,7 +1554,7 @@
$detailsName = "detailsManageProducts"; $detailsName = "detailsManageProducts";
$openString = ""; $openString = "";
if(in_array($detailsName, explode(";", $_POST['openDetailsElements']))) if(isset($_POST['openDetailsElements']) && in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
$openString = " open=\"\""; $openString = " open=\"\"";
GLOBAL $iconSave; GLOBAL $iconSave;
@ -1618,7 +1646,7 @@
$detailsName = "detailsManageUnits"; $detailsName = "detailsManageUnits";
$openString = ""; $openString = "";
if(in_array($detailsName, explode(";", $_POST['openDetailsElements']))) if(isset($_POST['openDetailsElements']) && in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
$openString = " open=\"\""; $openString = " open=\"\"";
echo " echo "
@ -1691,7 +1719,7 @@
$detailsName = "detailsManageStoreTypes"; $detailsName = "detailsManageStoreTypes";
$openString = ""; $openString = "";
if(in_array($detailsName, explode(";", $_POST['openDetailsElements']))) if(isset($_POST['openDetailsElements']) && in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
$openString = " open=\"\""; $openString = " open=\"\"";
GLOBAL $iconSave; GLOBAL $iconSave;
@ -1839,4 +1867,35 @@
echo "Error deleting list.<br>"; echo "Error deleting list.<br>";
} }
function triggerRhasspyTraining()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, Configuration::$rhasspyMasterUrl."/api/train");
curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, "postvar1=value1&postvar2=value2&postvar3=value3");
curl_setopt($ch, CURLOPT_POSTFIELDS, ""); // Send empty data to force POST
// In real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS,
// http_build_query(array('postvar1' => 'value1')));
// Receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);
// Further processing ...
if (strpos($server_output, 'Training completed') !== false)
{
return true;
}
return false;
}
?> ?>