diff --git a/phpInterface/shoppingList.php b/phpInterface/shoppingList.php index f92ce5f..24e2b77 100644 --- a/phpInterface/shoppingList.php +++ b/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 @@ 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; $isetID($_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 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 ""; else echo ""; @@ -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 "
@@ -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 "
@@ -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 "
@@ -1518,6 +1544,8 @@

Train Rhasspy

+ WARNING: This can take up to 2 minutes.

+
@@ -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.
"; } + + + 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; + } + ?> \ No newline at end of file