| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <?php
- require_once __DIR__ . '/../config.php';
- require_once __DIR__ . '/../includes/functions.php';
- // Check admin login
- if (!isset($_SESSION['admin_logged_in']) || !$_SESSION['admin_logged_in']) {
- header('Location: login.php');
- exit;
- }
- $pageTitle = 'Reservierungen verwalten';
- // Expire old reservations
- expireOldReservations();
- // Handle mark as picked up
- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['mark_picked_up'])) {
- $reservationId = sanitize($_POST['reservation_id']);
- markReservationPickedUp($reservationId);
- $message = 'Reservierung als abgeholt markiert.';
- $messageType = 'success';
- }
- $reservations = getReservations();
- $filter = isset($_GET['filter']) ? sanitize($_GET['filter']) : 'all';
- $searchCode = isset($_GET['code']) ? sanitize($_GET['code']) : '';
- // Filter reservations
- if ($searchCode) {
- $reservations = array_filter($reservations, function($r) use ($searchCode) {
- return stripos($r['code'], $searchCode) !== false || stripos($r['id'], $searchCode) !== false;
- });
- } else {
- switch ($filter) {
- case 'open':
- $reservations = array_filter($reservations, function($r) {
- return $r['status'] === 'open' && !$r['picked_up'];
- });
- break;
- case 'picked_up':
- $reservations = array_filter($reservations, function($r) {
- return $r['picked_up'];
- });
- break;
- case 'expired':
- $reservations = array_filter($reservations, function($r) {
- return $r['status'] === 'expired';
- });
- break;
- }
- }
- $reservations = array_reverse($reservations); // Newest first
- include __DIR__ . '/../includes/header.php';
- ?>
- <div class="admin-header">
- <h2>Reservierungen verwalten</h2>
- <div>
- <a href="index.php" class="btn btn-secondary">Zurück zum Dashboard</a>
- </div>
- </div>
- <?php if (isset($message)): ?>
- <div class="alert alert-<?php echo $messageType; ?>">
- <?php echo htmlspecialchars($message); ?>
- </div>
- <?php endif; ?>
- <div style="background: white; padding: 1.5rem; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin-bottom: 2rem;">
- <form method="GET" style="display: flex; gap: 1rem; align-items: end; flex-wrap: wrap;">
- <div style="flex: 1; min-width: 200px;">
- <label for="code">Code/ID suchen:</label>
- <input type="text" id="code" name="code" value="<?php echo htmlspecialchars($searchCode); ?>" placeholder="Abholcode oder Reservierungsnummer">
- </div>
- <div>
- <label for="filter">Filter:</label>
- <select id="filter" name="filter">
- <option value="all" <?php echo $filter === 'all' ? 'selected' : ''; ?>>Alle</option>
- <option value="open" <?php echo $filter === 'open' ? 'selected' : ''; ?>>Offen</option>
- <option value="picked_up" <?php echo $filter === 'picked_up' ? 'selected' : ''; ?>>Abgeholt</option>
- <option value="expired" <?php echo $filter === 'expired' ? 'selected' : ''; ?>>Abgelaufen</option>
- </select>
- </div>
- <div>
- <button type="submit" class="btn">Filtern</button>
- <a href="reservations.php" class="btn btn-secondary">Zurücksetzen</a>
- </div>
- </form>
- </div>
- <?php if (empty($reservations)): ?>
- <div class="alert alert-info">
- <p>Keine Reservierungen gefunden.</p>
- </div>
- <?php else: ?>
- <table>
- <thead>
- <tr>
- <th>Code</th>
- <th>Kunde</th>
- <th>E-Mail</th>
- <th>Artikel</th>
- <th>Erstellt</th>
- <th>Gültig bis</th>
- <th>Status</th>
- <th>Aktionen</th>
- </tr>
- </thead>
- <tbody>
- <?php foreach ($reservations as $reservation): ?>
- <tr>
- <td><strong><?php echo htmlspecialchars($reservation['code']); ?></strong></td>
- <td><?php echo htmlspecialchars($reservation['customer_name']); ?></td>
- <td><?php echo htmlspecialchars($reservation['customer_email']); ?></td>
- <td>
- <?php
- $itemCount = 0;
- foreach ($reservation['items'] as $item) {
- $itemCount += $item['quantity'];
- }
- echo $itemCount . ' Artikel';
- ?>
- </td>
- <td><?php echo formatDate($reservation['created']); ?></td>
- <td><?php echo formatDate($reservation['expires']); ?></td>
- <td>
- <?php
- if ($reservation['picked_up']) {
- echo '<span style="color: #28a745;">Abgeholt</span>';
- } elseif ($reservation['status'] === 'expired') {
- echo '<span style="color: #dc3545;">Abgelaufen</span>';
- } else {
- echo '<span style="color: #ffc107;">Offen</span>';
- }
- ?>
- </td>
- <td>
- <?php if (!$reservation['picked_up'] && $reservation['status'] === 'open'): ?>
- <form method="POST" style="display: inline;" onsubmit="return confirm('Reservierung als abgeholt markieren?');">
- <input type="hidden" name="reservation_id" value="<?php echo htmlspecialchars($reservation['id']); ?>">
- <button type="submit" name="mark_picked_up" class="btn btn-small">Als abgeholt markieren</button>
- </form>
- <?php endif; ?>
- <button onclick="showDetails('<?php echo htmlspecialchars($reservation['id']); ?>')" class="btn btn-secondary btn-small">Details</button>
- </td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <?php endif; ?>
- <!-- Details Modal -->
- <div id="detailsModal" style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center;">
- <div style="background: white; padding: 2rem; border-radius: 8px; max-width: 600px; max-height: 80vh; overflow-y: auto; position: relative;">
- <button onclick="closeDetails()" style="position: absolute; top: 1rem; right: 1rem; background: #dc3545; color: white; border: none; border-radius: 4px; padding: 0.5rem 1rem; cursor: pointer;">Schließen</button>
- <div id="detailsContent"></div>
- </div>
- </div>
- <script>
- function showDetails(reservationId) {
- const reservations = <?php echo json_encode(getReservations()); ?>;
- const reservation = reservations.find(r => r.id === reservationId);
-
- if (!reservation) return;
-
- let itemsHtml = '<h3>Artikel:</h3><ul>';
- reservation.items.forEach(item => {
- const product = <?php echo json_encode(getProducts()); ?>.find(p => p.id == item.product_id);
- if (product) {
- let sizeInfo = '';
- if (item.size && item.size !== '') {
- sizeInfo = ` - Größe: ${item.size}`;
- }
- itemsHtml += `<li>${product.name}${sizeInfo} - Menge: ${item.quantity}</li>`;
- }
- });
- itemsHtml += '</ul>';
-
- const html = `
- <h2>Reservierungsdetails</h2>
- <p><strong>Reservierungsnummer:</strong> ${reservation.id}</p>
- <p><strong>Abholcode:</strong> <strong style="font-size: 1.5rem; color: #c41e3a;">${reservation.code}</strong></p>
- <p><strong>Kunde:</strong> ${reservation.customer_name}</p>
- <p><strong>E-Mail:</strong> ${reservation.customer_email}</p>
- <p><strong>Erstellt:</strong> ${reservation.created}</p>
- <p><strong>Gültig bis:</strong> ${reservation.expires}</p>
- <p><strong>Status:</strong> ${reservation.picked_up ? 'Abgeholt' : (reservation.status === 'expired' ? 'Abgelaufen' : 'Offen')}</p>
- ${itemsHtml}
- `;
-
- document.getElementById('detailsContent').innerHTML = html;
- document.getElementById('detailsModal').style.display = 'flex';
- }
- function closeDetails() {
- document.getElementById('detailsModal').style.display = 'none';
- }
- </script>
- <?php include __DIR__ . '/../includes/footer.php'; ?>
|