| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- require_once __DIR__ . '/config.php';
- require_once __DIR__ . '/includes/functions.php';
- $pageTitle = 'Reservierung';
- $cart = $_SESSION['cart'] ?? [];
- if (empty($cart)) {
- header('Location: cart.php');
- exit;
- }
- // Validate cart items and stock
- $cartItems = [];
- $errors = [];
- $total = 0;
- foreach ($cart as $item) {
- $product = getProductById($item['product_id']);
- if (!$product) {
- $errors[] = 'Ein Produkt wurde nicht gefunden.';
- continue;
- }
-
- $size = isset($item['size']) ? $item['size'] : null;
- if (!checkStock($item['product_id'], $item['quantity'], $size)) {
- $sizeInfo = $size ? " (Größe: $size)" : '';
- $errors[] = 'Nicht genügend Lagerbestand für: ' . $product['name'] . $sizeInfo;
- continue;
- }
-
- $itemTotal = $product['price'] * $item['quantity'];
- $total += $itemTotal;
- $cartItems[] = [
- 'product' => $product,
- 'quantity' => $item['quantity'],
- 'total' => $itemTotal,
- 'size' => isset($item['size']) ? $item['size'] : null
- ];
- }
- // Handle form submission
- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['create_reservation'])) {
- $customerName = sanitize($_POST['customer_name'] ?? '');
- $customerEmail = sanitize($_POST['customer_email'] ?? '');
-
- if (empty($customerName)) {
- $errors[] = 'Bitte geben Sie Ihren Namen ein.';
- }
-
- if (empty($customerEmail) || !filter_var($customerEmail, FILTER_VALIDATE_EMAIL)) {
- $errors[] = 'Bitte geben Sie eine gültige E-Mail-Adresse ein.';
- }
-
- if (empty($errors)) {
- // Create reservation
- $items = [];
- foreach ($cart as $cartItem) {
- $item = [
- 'product_id' => $cartItem['product_id'],
- 'quantity' => $cartItem['quantity']
- ];
- if (isset($cartItem['size']) && !empty($cartItem['size'])) {
- $item['size'] = $cartItem['size'];
- }
- $items[] = $item;
- }
-
- $result = createReservation($customerName, $customerEmail, $items);
-
- if ($result['success']) {
- // Clear cart
- $_SESSION['cart'] = [];
- // Redirect to reservation confirmation
- header('Location: reservation.php?code=' . urlencode($result['reservation']['code']));
- exit;
- } else {
- $errors[] = $result['message'];
- }
- }
- }
- include __DIR__ . '/includes/header.php';
- ?>
- <h2>Reservierung abschließen</h2>
- <?php if (!empty($errors)): ?>
- <div class="alert alert-error">
- <ul style="margin-left: 1.5rem;">
- <?php foreach ($errors as $error): ?>
- <li><?php echo htmlspecialchars($error); ?></li>
- <?php endforeach; ?>
- </ul>
- </div>
- <?php endif; ?>
- <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; margin-top: 2rem;">
- <div>
- <h3>Ihre Bestellung</h3>
- <?php foreach ($cartItems as $cartItem): ?>
- <div style="background: white; padding: 1rem; margin-bottom: 1rem; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
- <strong><?php echo htmlspecialchars($cartItem['product']['name']); ?></strong><br>
- <?php if (isset($cartItem['size']) && !empty($cartItem['size'])): ?>
- Größe: <?php echo htmlspecialchars($cartItem['size']); ?><br>
- <?php endif; ?>
- Menge: <?php echo $cartItem['quantity']; ?><br>
- Preis: <?php echo formatPrice($cartItem['total']); ?>
- </div>
- <?php endforeach; ?>
-
- <div style="background: white; padding: 1rem; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin-top: 1rem;">
- <strong style="font-size: 1.2rem;">Gesamtsumme: <?php echo formatPrice($total); ?></strong>
- </div>
- </div>
-
- <div>
- <h3>Ihre Daten</h3>
- <form method="POST">
- <div class="form-group">
- <label for="customer_name">Name *</label>
- <input type="text" id="customer_name" name="customer_name" required
- value="<?php echo isset($_POST['customer_name']) ? htmlspecialchars($_POST['customer_name']) : ''; ?>">
- </div>
-
- <div class="form-group">
- <label for="customer_email">E-Mail-Adresse *</label>
- <input type="email" id="customer_email" name="customer_email" required
- value="<?php echo isset($_POST['customer_email']) ? htmlspecialchars($_POST['customer_email']) : ''; ?>">
- </div>
-
- <div class="alert alert-info">
- <strong>Hinweis:</strong> Nach der Reservierung erhalten Sie einen Abholcode, den Sie bei der Abholung vorzeigen müssen.
- Die Reservierung ist <?php echo RESERVATION_EXPIRY_DAYS; ?> Tage gültig.
- </div>
-
- <button type="submit" name="create_reservation" class="btn" style="width: 100%;">Reservierung abschließen</button>
- </form>
-
- <div style="margin-top: 1rem;">
- <a href="cart.php" class="btn btn-secondary">Zurück zum Warenkorb</a>
- </div>
- </div>
- </div>
- <?php include __DIR__ . '/includes/footer.php'; ?>
|