Added feature to create new list on phpInterface

This commit is contained in:
Jens Schröder 2021-02-22 15:36:21 +01:00
parent 131ffa55a4
commit e7c5df6416

View File

@ -24,9 +24,9 @@
} }
} }
if(isset($_GET['command']) && $_GET['command'] == "printRhasspyProductList") if(isset($_GET['command']) && $_GET['command'] == "printProductList")
{ {
printRhasspyProductList(); displayProductList();
exit(0); exit(0);
} }
@ -64,13 +64,16 @@
$productId = $_POST['productToRemove']; $productId = $_POST['productToRemove'];
removeFromList($productId); removeFromList($productId);
break; break;
case "printShoppingList": case "displayShoppingList":
printShoppingList(); displayShoppingList();
break;
case "createNewShoppingList":
createNewShoppingList();
break; break;
} }
} }
printShoppingList(); displayShoppingList();
echo "</body></html>"; echo "</body></html>";
@ -118,7 +121,6 @@
} }
function oneListExists() function oneListExists()
{ {
$SQL_command = "SELECT COUNT(id) as listAmount FROM lists"; $SQL_command = "SELECT COUNT(id) as listAmount FROM lists";
@ -133,10 +135,14 @@
} }
function displayShoppingList()
function printShoppingList()
{ {
echo " <form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\" onSubmit=\"if(!confirm('Are you sure you want to create a new list?')){return false;}\">
<input type=\"hidden\" id=\"command\" name=\"command\" value=\"createNewShoppingList\" />
<input type=\"submit\" value=\"Create new list\" />
</form>";
echo " <form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\"> echo " <form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">
<input type=\"hidden\" id=\"command\" name=\"command\" value=\"addToList\" /> <input type=\"hidden\" id=\"command\" name=\"command\" value=\"addToList\" />
<select name=\"productToAdd\" id=\"productToAdd\"> <select name=\"productToAdd\" id=\"productToAdd\">
@ -192,7 +198,7 @@
} }
function printRhasspyProductList() function displayProductList()
{ {
$SQL_Befehl = "SELECT name, synonyms FROM products ORDER BY products.name ASC"; $SQL_Befehl = "SELECT name, synonyms FROM products ORDER BY products.name ASC";
@ -209,4 +215,17 @@
} }
} }
function createNewShoppingList()
{
$date = new DateTime();
$SQL_command = "INSERT INTO lists (creationTime) VALUES (".($date->getTimestamp() * 1000).")";
if (DBLink::getDbLink()->query($SQL_command))
echo "New list has been created.<br>";
else
echo "Error creating new list.<br>";
}
?> ?>