reservations.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. require_once __DIR__ . '/../config.php';
  3. require_once __DIR__ . '/../includes/functions.php';
  4. // Check admin login
  5. if (!isset($_SESSION['admin_logged_in']) || !$_SESSION['admin_logged_in']) {
  6. header('Location: login.php');
  7. exit;
  8. }
  9. $pageTitle = 'Reservierungen verwalten';
  10. // Expire old reservations
  11. expireOldReservations();
  12. // Handle mark as picked up
  13. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['mark_picked_up'])) {
  14. $reservationId = sanitize($_POST['reservation_id']);
  15. markReservationPickedUp($reservationId);
  16. $message = 'Reservierung als abgeholt markiert.';
  17. $messageType = 'success';
  18. }
  19. $reservations = getReservations();
  20. $filter = isset($_GET['filter']) ? sanitize($_GET['filter']) : 'all';
  21. $searchCode = isset($_GET['code']) ? sanitize($_GET['code']) : '';
  22. // Filter reservations
  23. if ($searchCode) {
  24. $reservations = array_filter($reservations, function($r) use ($searchCode) {
  25. return stripos($r['code'], $searchCode) !== false || stripos($r['id'], $searchCode) !== false;
  26. });
  27. } else {
  28. switch ($filter) {
  29. case 'open':
  30. $reservations = array_filter($reservations, function($r) {
  31. return $r['status'] === 'open' && !$r['picked_up'];
  32. });
  33. break;
  34. case 'picked_up':
  35. $reservations = array_filter($reservations, function($r) {
  36. return $r['picked_up'];
  37. });
  38. break;
  39. case 'expired':
  40. $reservations = array_filter($reservations, function($r) {
  41. return $r['status'] === 'expired';
  42. });
  43. break;
  44. }
  45. }
  46. $reservations = array_reverse($reservations); // Newest first
  47. include __DIR__ . '/../includes/header.php';
  48. ?>
  49. <div class="admin-header">
  50. <h2>Reservierungen verwalten</h2>
  51. <div>
  52. <a href="index.php" class="btn btn-secondary">Zurück zum Dashboard</a>
  53. </div>
  54. </div>
  55. <?php if (isset($message)): ?>
  56. <div class="alert alert-<?php echo $messageType; ?>">
  57. <?php echo htmlspecialchars($message); ?>
  58. </div>
  59. <?php endif; ?>
  60. <div style="background: white; padding: 1.5rem; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin-bottom: 2rem;">
  61. <form method="GET" style="display: flex; gap: 1rem; align-items: end; flex-wrap: wrap;">
  62. <div style="flex: 1; min-width: 200px;">
  63. <label for="code">Code/ID suchen:</label>
  64. <input type="text" id="code" name="code" value="<?php echo htmlspecialchars($searchCode); ?>" placeholder="Abholcode oder Reservierungsnummer">
  65. </div>
  66. <div>
  67. <label for="filter">Filter:</label>
  68. <select id="filter" name="filter">
  69. <option value="all" <?php echo $filter === 'all' ? 'selected' : ''; ?>>Alle</option>
  70. <option value="open" <?php echo $filter === 'open' ? 'selected' : ''; ?>>Offen</option>
  71. <option value="picked_up" <?php echo $filter === 'picked_up' ? 'selected' : ''; ?>>Abgeholt</option>
  72. <option value="expired" <?php echo $filter === 'expired' ? 'selected' : ''; ?>>Abgelaufen</option>
  73. </select>
  74. </div>
  75. <div>
  76. <button type="submit" class="btn">Filtern</button>
  77. <a href="reservations.php" class="btn btn-secondary">Zurücksetzen</a>
  78. </div>
  79. </form>
  80. </div>
  81. <?php if (empty($reservations)): ?>
  82. <div class="alert alert-info">
  83. <p>Keine Reservierungen gefunden.</p>
  84. </div>
  85. <?php else: ?>
  86. <table>
  87. <thead>
  88. <tr>
  89. <th>Code</th>
  90. <th>Kunde</th>
  91. <th>E-Mail</th>
  92. <th>Artikel</th>
  93. <th>Erstellt</th>
  94. <th>Gültig bis</th>
  95. <th>Status</th>
  96. <th>Aktionen</th>
  97. </tr>
  98. </thead>
  99. <tbody>
  100. <?php foreach ($reservations as $reservation): ?>
  101. <tr>
  102. <td><strong><?php echo htmlspecialchars($reservation['code']); ?></strong></td>
  103. <td><?php echo htmlspecialchars($reservation['customer_name']); ?></td>
  104. <td><?php echo htmlspecialchars($reservation['customer_email']); ?></td>
  105. <td>
  106. <?php
  107. $itemCount = 0;
  108. foreach ($reservation['items'] as $item) {
  109. $itemCount += $item['quantity'];
  110. }
  111. echo $itemCount . ' Artikel';
  112. ?>
  113. </td>
  114. <td><?php echo formatDate($reservation['created']); ?></td>
  115. <td><?php echo formatDate($reservation['expires']); ?></td>
  116. <td>
  117. <?php
  118. if ($reservation['picked_up']) {
  119. echo '<span style="color: #28a745;">Abgeholt</span>';
  120. } elseif ($reservation['status'] === 'expired') {
  121. echo '<span style="color: #dc3545;">Abgelaufen</span>';
  122. } else {
  123. echo '<span style="color: #ffc107;">Offen</span>';
  124. }
  125. ?>
  126. </td>
  127. <td>
  128. <?php if (!$reservation['picked_up'] && $reservation['status'] === 'open'): ?>
  129. <form method="POST" style="display: inline;" onsubmit="return confirm('Reservierung als abgeholt markieren?');">
  130. <input type="hidden" name="reservation_id" value="<?php echo htmlspecialchars($reservation['id']); ?>">
  131. <button type="submit" name="mark_picked_up" class="btn btn-small">Als abgeholt markieren</button>
  132. </form>
  133. <?php endif; ?>
  134. <button onclick="showDetails('<?php echo htmlspecialchars($reservation['id']); ?>')" class="btn btn-secondary btn-small">Details</button>
  135. </td>
  136. </tr>
  137. <?php endforeach; ?>
  138. </tbody>
  139. </table>
  140. <?php endif; ?>
  141. <!-- Details Modal -->
  142. <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;">
  143. <div style="background: white; padding: 2rem; border-radius: 8px; max-width: 600px; max-height: 80vh; overflow-y: auto; position: relative;">
  144. <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>
  145. <div id="detailsContent"></div>
  146. </div>
  147. </div>
  148. <script>
  149. function showDetails(reservationId) {
  150. const reservations = <?php echo json_encode(getReservations()); ?>;
  151. const reservation = reservations.find(r => r.id === reservationId);
  152. if (!reservation) return;
  153. let itemsHtml = '<h3>Artikel:</h3><ul>';
  154. reservation.items.forEach(item => {
  155. const product = <?php echo json_encode(getProducts()); ?>.find(p => p.id == item.product_id);
  156. if (product) {
  157. let sizeInfo = '';
  158. if (item.size && item.size !== '') {
  159. sizeInfo = ` - Größe: ${item.size}`;
  160. }
  161. itemsHtml += `<li>${product.name}${sizeInfo} - Menge: ${item.quantity}</li>`;
  162. }
  163. });
  164. itemsHtml += '</ul>';
  165. const html = `
  166. <h2>Reservierungsdetails</h2>
  167. <p><strong>Reservierungsnummer:</strong> ${reservation.id}</p>
  168. <p><strong>Abholcode:</strong> <strong style="font-size: 1.5rem; color: #c41e3a;">${reservation.code}</strong></p>
  169. <p><strong>Kunde:</strong> ${reservation.customer_name}</p>
  170. <p><strong>E-Mail:</strong> ${reservation.customer_email}</p>
  171. <p><strong>Erstellt:</strong> ${reservation.created}</p>
  172. <p><strong>Gültig bis:</strong> ${reservation.expires}</p>
  173. <p><strong>Status:</strong> ${reservation.picked_up ? 'Abgeholt' : (reservation.status === 'expired' ? 'Abgelaufen' : 'Offen')}</p>
  174. ${itemsHtml}
  175. `;
  176. document.getElementById('detailsContent').innerHTML = html;
  177. document.getElementById('detailsModal').style.display = 'flex';
  178. }
  179. function closeDetails() {
  180. document.getElementById('detailsModal').style.display = 'none';
  181. }
  182. </script>
  183. <?php include __DIR__ . '/../includes/footer.php'; ?>