Browse Source

Errors fixed when creating/managing products

development
jens 5 months ago
parent
commit
0971e3cfaf
  1. 89
      phpInterface/shoppingList.php

89
phpInterface/shoppingList.php

@ -5,9 +5,15 @@
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");
$justCreatedProductId;
$justCreatedProductId = null;
$iconDelete = "❌";
$iconSave = "💾";
@ -1003,8 +1009,9 @@
<?php
$command = $_POST['command'];
$listId;
if(isset($_POST['command']))
$command = $_POST['command'];
$listId = null;
if(isset($command))
{
@ -1050,12 +1057,11 @@
case "createProduct":
$p = new Product();
$p->setID($_POST['oldProductId']);
if(strpos($_POST['productName'], ";") !== false)
{
$terms = explode(";", $_POST['productName']);
$p->setName = $terms[0];
$p->setName(trim($terms[0]));
$syns = "";
for($i=1; $i<count($terms); $i++)
@ -1088,8 +1094,25 @@
case "manageProduct":
$p = new Product();
$p->setID($_POST['oldProductId']);
$p->setName($_POST['productName']);
$p->setSynonyms($_POST['productSynonyms']);
if(strpos($_POST['productName'], ";") !== false)
{
$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']));
GLOBAL $iconDelete;
@ -1200,7 +1223,10 @@
echo "Invalid command.";
break;
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;
}
}
@ -1311,7 +1337,7 @@
{
$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>";
else
echo "<option value=\"".$product->getID()."\" name=\"".$product->getName()."\">".$product->getName()."</option>";
@ -1441,7 +1467,7 @@
$detailsName = "detailsMaintenance";
$openString = "";
if(in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
if(isset($_POST['openDetailsElements']) && in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
$openString = " open=\"\"";
echo "<details id=\"".$detailsName."\"".$openString." ontoggle=\"rememberToggleState(this)\">
@ -1454,7 +1480,7 @@
$detailsName = "detailsLists";
$openString = "";
if(in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
if(isset($_POST['openDetailsElements']) && in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
$openString = " open=\"\"";
echo " <details id=\"".$detailsName."\"".$openString." ontoggle=\"rememberToggleState(this)\">
@ -1508,7 +1534,7 @@
$detailsName = "detailsRhasspy";
$openString = "";
if(in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
if(isset($_POST['openDetailsElements']) && in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
$openString = " open=\"\"";
echo " <details id=\"".$detailsName."\"".$openString." ontoggle=\"rememberToggleState(this)\">
@ -1518,6 +1544,8 @@
<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)\">
<input type=\"hidden\" id=\"command\" name=\"command\" value=\"trainRhasspy\" />
<input type=\"submit\" value=\"🚂\" style=\"font-size : 25px;\" />
@ -1526,7 +1554,7 @@
$detailsName = "detailsManageProducts";
$openString = "";
if(in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
if(isset($_POST['openDetailsElements']) && in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
$openString = " open=\"\"";
GLOBAL $iconSave;
@ -1618,7 +1646,7 @@
$detailsName = "detailsManageUnits";
$openString = "";
if(in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
if(isset($_POST['openDetailsElements']) && in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
$openString = " open=\"\"";
echo "
@ -1691,7 +1719,7 @@
$detailsName = "detailsManageStoreTypes";
$openString = "";
if(in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
if(isset($_POST['openDetailsElements']) && in_array($detailsName, explode(";", $_POST['openDetailsElements'])))
$openString = " open=\"\"";
GLOBAL $iconSave;
@ -1839,4 +1867,35 @@
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;
}
?>
Loading…
Cancel
Save