"; $command = $_POST['command']; if(isset($command)) { switch($command) { case "addToList": $productId = $_POST['productToAdd']; addToList($productId); break; case "removeFromList": $productId = $_POST['productToRemove']; removeFromList($productId); break; case "printShoppingList": printShoppingList(); break; } } printShoppingList(); echo ""; mysqli_close(DBLink::getDbLink()); function addToList($productId) { if($productId > 0) { $SQL_command; if(oneListExists()) $SQL_command = "INSERT IGNORE INTO listEntries (listId, productId) VALUES ((SELECT id FROM `lists` ORDER BY creationTime DESC LIMIT 1), ".$productId.")"; else $SQL_command = "INSERT IGNORE INTO listEntries (listId, productId) VALUES ((INSERT INTO `lists` (creationTime) VALUES (".round(microtime(true) * 1000).") RETURN @id, ".$productId."))"; if (DBLink::getDbLink()->query($SQL_command)) echo "Product added to list.
"; else echo "Product could not be added to list.
"; } else echo "Select a product."; } function removeFromList($productId) { if($productId > 0) { if(oneListExists()) { $SQL_command = "DELETE FROM listEntries WHERE listId=(SELECT id FROM `lists` ORDER BY creationTime DESC LIMIT 1) AND productId=".$productId; 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 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 printShoppingList() { echo "
"; if(oneListExists()) { $SQL_command = "SELECT * FROM listEntries INNER JOIN products ON listEntries.productId=products.id INNER JOIN storeTypes ON products.storeTypeId = storeTypes.id WHERE listEntries.listId=(SELECT id FROM `lists` ORDER BY creationTime DESC LIMIT 1) ORDER BY storeTypes.name, products.name ASC"; $mysqli_result = DBLink::getDbLink()->query($SQL_command); $lastShop=""; while ($row = mysqli_fetch_array($mysqli_result)) { if(isset($lastShop) && $lastShop != "" && $row[7] != $lastShop) echo ""; if(!isset($lastShop) || $row[7] != $lastShop) { $lastShop = $row[7]; echo $lastShop."
================"; echo ""; } echo ""; } echo "
".$row[3]."
"; } else echo "No list exists, yet."; } function printRhasspyProductList() { $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"; } } ?>