0) $justCreatedProductId = $rc; break; case "oldList": $listId = $_POST['oldListId']; $subCommand = $_POST['bSubmit']; if($subCommand == "remove") { removeShoppingList($listId); $listId = null; } break; case "trainRhasspy": echo "Triggering training in Rhasspy has not been implemented, yet."; break; } } displayShoppingList($listId, $justCreatedProductId); showDataMaintenance(); echo ""; mysqli_close(DBLink::getDbLink()); function createList() { $SQL_command = "INSERT INTO `lists` (creationTime) VALUES (".round(microtime(true) * 1000).")"; if (DBLink::getDbLink()->query($SQL_command)) { echo "List created.
"; return true; } return false; } function addToList($productId, $amount, $unitId) { if($productId > 0 && $amount != 0 && isset($unitId) && strlen($unitId) > 0) { if(!oneListExists()) createList(); if(!entryCombinationExists($productId, $unitId)) { $SQL_command = "INSERT IGNORE INTO listEntries (listId, productId, amount, unit) VALUES ((SELECT id FROM `lists` ORDER BY creationTime DESC LIMIT 1), ".$productId.", ".$amount.", ".$unitId.")"; if (DBLink::getDbLink()->query($SQL_command)) echo "Product added to list.
"; else echo "Product could not be added to list.
"; } else { /* update command that adds the amount to the already existing amount if amount is negative -> subtract from existing amount. if resulting amount <= 0 -> */ $SQL_command = "SELECT amount FROM listEntries WHERE listId=(SELECT id FROM `lists` ORDER BY creationTime DESC LIMIT 1) AND productId=".$productId." AND unit=".$unitId; $mysqli_result = DBLink::getDbLink()->query($SQL_command); if ($row = mysqli_fetch_object($mysqli_result)) { if($row->amount + $amount > 0) { $SQL_command = "UPDATE listEntries set amount=".($row->amount + $amount)." WHERE listId=(SELECT id FROM `lists` ORDER BY creationTime DESC LIMIT 1) AND productId=".$productId." AND unit=".$unitId; if (DBLink::getDbLink()->query($SQL_command)) echo "Product added to existing entry on list.
"; else echo "Product could not be added to existing entry on list.
"; } else { $SQL_command = "DELETE FROM listEntries WHERE listId=(SELECT id FROM `lists` ORDER BY creationTime DESC LIMIT 1) AND productId=".$productId." AND unit=".$unitId; if (DBLink::getDbLink()->query($SQL_command)) echo "Product removed from list as too many pieces of this item have been removed.
"; else echo "Product could not be removed from list (too many pieces of this itme have been removed).
"; } } } } else echo "Specifiy product, amount and unit."; } function removeFromList($productId, $listId, $amount, $unitId) { if($productId > 0 && $amount != null && $unitId > 0) { if(oneListExists()) { $SQL_command = "DELETE FROM listEntries WHERE listId=".$listId." AND productId=".$productId." AND amount=".$amount." AND unit=".$unitId; if (DBLink::getDbLink()->query($SQL_command)) echo "Product removed from list.
"; else echo "Product could not be removed from list.
"; } } else echo "Select a product."; } function entryCombinationExists($productId, $unitId) { $SQL_command = "SELECT COUNT(listId) as entryAmount FROM listEntries WHERE listId=(SELECT id FROM `lists` ORDER BY creationTime DESC LIMIT 1) AND productId=".$productId." AND unit=".$unitId; $mysqli_result = DBLink::getDbLink()->query($SQL_command); if ($row = mysqli_fetch_object($mysqli_result)) { if($row->entryAmount > 0) return true; } return false; } function oneListExists() { $SQL_command = "SELECT COUNT(id) as listAmount FROM lists"; $mysqli_result = DBLink::getDbLink()->query($SQL_command); if ($row = mysqli_fetch_object($mysqli_result)) { if($row->listAmount > 0) return true; } return false; } function twoListsExist() { $SQL_command = "SELECT COUNT(id) as listAmount FROM lists"; $mysqli_result = DBLink::getDbLink()->query($SQL_command); if ($row = mysqli_fetch_object($mysqli_result)) { if($row->listAmount > 1) return true; } return false; } function displayShoppingList($listId, $justCreatedProductId) { echo "

Shopping list

"; if(oneListExists()) { $list_SQL_command; if(isset($listId)) { $list_SQL_command = "SELECT * FROM lists WHERE id=".$listId; } else { $list_SQL_command = "SELECT * FROM lists ORDER BY creationTime DESC LIMIT 0,1"; $SQL_command_listId = "SELECT id FROM lists ORDER BY creationTime DESC LIMIT 0,1"; $mysqli_result = DBLink::getDbLink()->query($SQL_command_listId); if ($row = mysqli_fetch_object($mysqli_result)) $listId = $row->id; } $mysqli_result = DBLink::getDbLink()->query($list_SQL_command); if ($row = mysqli_fetch_object($mysqli_result)) { echo "List created on ".date("l, d.m.Y", ($row->creationTime)/1000)." at ".date("G:i:s", ($row->creationTime)/1000)."
"; if(isset($row->comment) && strlen($row->comment) > 0) echo "".$row->comment."
"; echo "
"; } $SQL_command = "SELECT * FROM listEntries INNER JOIN products ON listEntries.productId=products.id INNER JOIN storeTypes ON products.storeTypeId = storeTypes.id INNER JOIN units ON units.id = listEntries.unit WHERE listEntries.listId=".$listId." ORDER BY storeTypes.name, products.name ASC"; $mysqli_result = DBLink::getDbLink()->query($SQL_command); $lastShop=""; $found = false; while ($row = mysqli_fetch_array($mysqli_result)) { if(!$found) $found = true; if(isset($lastShop) && $lastShop != "" && $row[9] != $lastShop) echo ""; if(!isset($lastShop) || $row[9] != $lastShop) { $lastShop = $row[9]; echo $lastShop."
================"; echo ""; } echo ""; if($row[14] == 1) echo ""; else echo " "; echo " "; } if($found) echo "
".$row[5]."".$row[2]." ".$row[12]." ".$row[5]."
"; else echo "No entries in this list, yet."; } else echo "No list exists, yet."; } function showDataMaintenance() { echo "
"; echo "

Data maintenance

Create new list

Create new product

You can enter synonyms. Separate all terms with semikolons."; if(twoListsExist()) { $SQL_command = "SELECT * FROM lists ORDER BY creationTime DESC"; $mysqli_result = DBLink::getDbLink()->query($SQL_command); echo "

Show specific list

"; echo "
"; } echo "

Train Rhasspy

"; } function displayProductList() { $SQL_Befehl = "SELECT name, synonyms FROM products ORDER BY products.name ASC"; $mysqli_result = DBLink::getDbLink()->query($SQL_Befehl); $lastShop=""; while ($row = mysqli_fetch_array($mysqli_result)) { if(is_null($row[1])) echo $row[0]."\n"; else echo "(".str_replace(";", "|", $row[1])."|".$row[0]."):".$row[0]."\n"; } } function displayUnitList() { $SQL_Befehl = "SELECT name FROM units ORDER BY name ASC"; $mysqli_result = DBLink::getDbLink()->query($SQL_Befehl); $lastShop=""; while ($row = mysqli_fetch_object($mysqli_result)) { $unitArray = explode(";", $row->name); if(count($unitArray) == 1) echo $unitArray[0]."\n"; else { $tbp = ""; for($i=1; $igetTimestamp() * 1000).")"; if (DBLink::getDbLink()->query($SQL_command)) echo "New list has been created.
"; else echo "Error creating new list.
"; } function removeShoppingList($listId) { $date = new DateTime(); $SQL_command = "DELETE FROM lists WHERE id=".$listId; if (DBLink::getDbLink()->query($SQL_command)) echo "List has been deleted.
"; else echo "Error deleting list.
"; } function createProduct($productNames, $storeTypeId) { $date = new DateTime(); $SQL_command; if(strpos($productNames, ";") !== false) { $terms = explode(";", $productNames); $mainName = $terms[0]; $syns = ""; for($i=1; $i 0) $syns .= ";".$currentWord; } $syns = ltrim($syns, ';'); } if(strlen($syns) > 0) $SQL_command = "INSERT INTO products (name, synonyms, storeTypeId) VALUES (\"".$mainName."\", \"".$syns."\",".$storeTypeId.")"; else $SQL_command = "INSERT INTO products (name, storeTypeId) VALUES (\"".$productNames."\", ".$storeTypeId.")"; if (DBLink::getDbLink()->query($SQL_command)) { echo "New product has been created.
"; return DBLink::getDbLink()->insert_id; } else echo "Error creating new product.
"; return -1; } ?>