diff --git a/offerAdder.php b/offerAdder.php index c961c74..5e6d002 100644 --- a/offerAdder.php +++ b/offerAdder.php @@ -22,28 +22,44 @@ $conn = db_connect(); $message = ''; $messageType = ''; -if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'add_offer') { - $productID = (int)$_POST['product_id']; - $shopID = (int)$_POST['shop_id']; - $price = (float)$_POST['price']; - $shippingCost = isset($_POST['shipping_cost']) && $_POST['shipping_cost'] !== '' ? (float)$_POST['shipping_cost'] : 0.00; - $inStock = isset($_POST['in_stock']) ? 1 : 0; - $offerURL = trim($_POST['offer_url']); +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { + if ($_POST['action'] === 'add_offer') { + $productID = (int)$_POST['product_id']; + $shopID = (int)$_POST['shop_id']; + $price = (float)$_POST['price']; + $shippingCost = isset($_POST['shipping_cost']) && $_POST['shipping_cost'] !== '' ? (float)$_POST['shipping_cost'] : 0.00; + $inStock = isset($_POST['in_stock']) ? 1 : 0; + $offerURL = trim($_POST['offer_url']); - if ($productID > 0 && $shopID > 0 && $price >= 0) { - $stmt = $conn->prepare("INSERT INTO offers (productID, shopID, price, shippingCost, inStock, offerURL) VALUES (?, ?, ?, ?, ?, ?)"); - $stmt->bind_param("iiddis", $productID, $shopID, $price, $shippingCost, $inStock, $offerURL); - if ($stmt->execute()) { - $message = 'Angebot erfolgreich hinzugefügt!'; - $messageType = 'success'; + if ($productID > 0 && $shopID > 0 && $price >= 0) { + $stmt = $conn->prepare("INSERT INTO offers (productID, shopID, price, shippingCost, inStock, offerURL) VALUES (?, ?, ?, ?, ?, ?)"); + $stmt->bind_param("iiddis", $productID, $shopID, $price, $shippingCost, $inStock, $offerURL); + if ($stmt->execute()) { + $message = 'Angebot erfolgreich hinzugefügt!'; + $messageType = 'success'; + } else { + $message = 'Fehler beim Hinzufügen des Angebots.'; + $messageType = 'error'; + } + $stmt->close(); } else { - $message = 'Fehler beim Hinzufügen des Angebots.'; + $message = 'Bitte alle Pflichtfelder korrekt ausfüllen.'; $messageType = 'error'; } - $stmt->close(); - } else { - $message = 'Bitte alle Pflichtfelder korrekt ausfüllen.'; - $messageType = 'error'; + } elseif ($_POST['action'] === 'delete_offer') { + $offerID = (int)$_POST['offer_id']; + if ($offerID > 0) { + $stmt = $conn->prepare("DELETE FROM offers WHERE offerID = ?"); + $stmt->bind_param("i", $offerID); + if ($stmt->execute()) { + $message = 'Angebot erfolgreich gelöscht!'; + $messageType = 'success'; + } else { + $message = 'Fehler beim Löschen des Angebots.'; + $messageType = 'error'; + } + $stmt->close(); + } } } @@ -65,6 +81,21 @@ if ($shopsResult) { } } +// Get existing offers to manage +$offersResult = $conn->query(" + SELECT o.offerID, p.model AS productName, s.name AS shopName, o.price + FROM offers o + JOIN products p ON o.productID = p.productID + JOIN shops s ON o.shopID = s.shopID + ORDER BY o.offerID DESC +"); +$existingOffers = []; +if ($offersResult) { + while ($row = $offersResult->fetch_assoc()) { + $existingOffers[] = $row; + } +} + include 'header.php'; ?>
@@ -133,6 +164,51 @@ include 'header.php'; + +
+
+

Bestehende Angebote verwalten

+
+ + 0): ?> +
+ + + + + + + + + + + + + + + + + + + +
ProduktShopPreisAktion
+
+ + + +
+
+
+ +

Keine Angebote vorhanden.

+ +
+