reservations.php 8.5 KB

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