Add offer deletion functionality and display existing offers in offerAdder
This commit is contained in:
parent
b907ce3d81
commit
b967e060c8
@ -22,7 +22,8 @@ $conn = db_connect();
|
|||||||
$message = '';
|
$message = '';
|
||||||
$messageType = '';
|
$messageType = '';
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'add_offer') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
||||||
|
if ($_POST['action'] === 'add_offer') {
|
||||||
$productID = (int)$_POST['product_id'];
|
$productID = (int)$_POST['product_id'];
|
||||||
$shopID = (int)$_POST['shop_id'];
|
$shopID = (int)$_POST['shop_id'];
|
||||||
$price = (float)$_POST['price'];
|
$price = (float)$_POST['price'];
|
||||||
@ -45,6 +46,21 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
|
|||||||
$message = 'Bitte alle Pflichtfelder korrekt ausfüllen.';
|
$message = 'Bitte alle Pflichtfelder korrekt ausfüllen.';
|
||||||
$messageType = 'error';
|
$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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all products for dropdown
|
// Get all products for dropdown
|
||||||
@ -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';
|
include 'header.php';
|
||||||
?>
|
?>
|
||||||
<main class="auth">
|
<main class="auth">
|
||||||
@ -133,6 +164,51 @@ include 'header.php';
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="auth__card" style="margin-top: 2rem;">
|
||||||
|
<header class="auth__header">
|
||||||
|
<h2 class="auth__title">Bestehende Angebote verwalten</h2>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<?php if (count($existingOffers) > 0): ?>
|
||||||
|
<div style="overflow-x: auto; margin-top: 1rem;">
|
||||||
|
<table style="width: 100%; border-collapse: collapse; min-width: 500px;">
|
||||||
|
<thead>
|
||||||
|
<tr style="border-bottom: 2px solid var(--border-color); text-align: left;">
|
||||||
|
<th style="padding: 0.75rem 0.5rem; color: var(--text-muted); font-weight: 600;">Produkt</th>
|
||||||
|
<th style="padding: 0.75rem 0.5rem; color: var(--text-muted); font-weight: 600;">Shop</th>
|
||||||
|
<th style="padding: 0.75rem 0.5rem; color: var(--text-muted); font-weight: 600;">Preis</th>
|
||||||
|
<th style="padding: 0.75rem 0.5rem; text-align: right; color: var(--text-muted); font-weight: 600;">Aktion</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($existingOffers as $offer): ?>
|
||||||
|
<tr style="border-bottom: 1px solid var(--border-light);">
|
||||||
|
<td style="padding: 1rem 0.5rem; vertical-align: middle;"><?php echo htmlspecialchars($offer['productName']); ?></td>
|
||||||
|
<td style="padding: 1rem 0.5rem; vertical-align: middle;"><?php echo htmlspecialchars($offer['shopName']); ?></td>
|
||||||
|
<td style="padding: 1rem 0.5rem; vertical-align: middle; font-weight: 600;">€<?php echo number_format($offer['price'], 2, ',', '.'); ?></td>
|
||||||
|
<td style="padding: 1rem 0.5rem; text-align: right; vertical-align: middle;">
|
||||||
|
<form method="POST" action="offerAdder.php" onsubmit="return confirm('Möchtest du dieses Angebot wirklich löschen?');" style="display: inline-block; margin: 0;">
|
||||||
|
<input type="hidden" name="action" value="delete_offer">
|
||||||
|
<input type="hidden" name="offer_id" value="<?php echo $offer['offerID']; ?>">
|
||||||
|
<button type="submit" style="background: none; border: none; color: #ef4444; cursor: pointer; display: flex; align-items: center; justify-content: flex-end; padding: 0.5rem; border-radius: 4px;" title="Angebot löschen" onmouseover="this.style.backgroundColor='#fee2e2';" onmouseout="this.style.backgroundColor='transparent';">
|
||||||
|
<svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" viewBox="0 0 24 24">
|
||||||
|
<polyline points="3 6 5 6 21 6"></polyline>
|
||||||
|
<path d="M19 6V20a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php else: ?>
|
||||||
|
<p style="margin-top: 1rem; color: var(--text-muted); text-align: center; padding: 2rem 0;">Keine Angebote vorhanden.</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
<?php include 'footer.php'; ?>
|
<?php include 'footer.php'; ?>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user