index.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 = 'Admin Dashboard';
  10. // Get statistics
  11. $products = getProducts();
  12. $reservations = getReservations();
  13. // Expire old reservations
  14. expireOldReservations();
  15. $reservations = getReservations(); // Refresh after expiry
  16. $regularReservations = array_filter($reservations, function($r) {
  17. return (!isset($r['type']) || $r['type'] !== 'backorder') && !isReservationHidden($r);
  18. });
  19. $backorderReservations = array_filter($reservations, function($r) {
  20. return isset($r['type']) && $r['type'] === 'backorder' && !isReservationHidden($r);
  21. });
  22. $totalProducts = count($products);
  23. $totalStock = 0;
  24. foreach ($products as $product) {
  25. $totalStock += getTotalStock($product);
  26. }
  27. $openReservations = count(array_filter($regularReservations, function($r) {
  28. return $r['status'] === 'open' && !$r['picked_up'];
  29. }));
  30. $pickedUpReservations = count(array_filter($regularReservations, function($r) {
  31. return $r['picked_up'];
  32. }));
  33. $openRegularReservations = array_values(array_filter($regularReservations, function($r) {
  34. return $r['status'] === 'open' && !$r['picked_up'];
  35. }));
  36. $openPreorders = array_values(array_filter($backorderReservations, function($r) {
  37. return !isset($r['backorder_status']) || $r['backorder_status'] !== 'notified';
  38. }));
  39. $openBackorders = count($openPreorders);
  40. $bodyClass = 'admin-page';
  41. include __DIR__ . '/../includes/header.php';
  42. ?>
  43. <div class="admin-header">
  44. <h2>Admin Dashboard</h2>
  45. <div>
  46. <a href="products.php" class="btn">Produkte verwalten</a>
  47. <a href="reservations.php" class="btn">Reservierungen</a>
  48. <a href="backorders.php" class="btn">Vorbestellungen</a>
  49. <a href="login.php?logout=1" class="btn btn-secondary">Abmelden</a>
  50. </div>
  51. </div>
  52. <div class="admin-stats">
  53. <div class="stat-card">
  54. <h3>Produkte</h3>
  55. <div class="stat-value"><?php echo $totalProducts; ?></div>
  56. </div>
  57. <div class="stat-card">
  58. <h3>Gesamtbestand</h3>
  59. <div class="stat-value"><?php echo $totalStock; ?></div>
  60. </div>
  61. <div class="stat-card">
  62. <h3>Offene Reservierungen</h3>
  63. <div class="stat-value"><?php echo $openReservations; ?></div>
  64. </div>
  65. <div class="stat-card">
  66. <h3>Abgeholt</h3>
  67. <div class="stat-value"><?php echo $pickedUpReservations; ?></div>
  68. </div>
  69. <div class="stat-card">
  70. <h3>Offene Vorbestellungen</h3>
  71. <div class="stat-value"><?php echo $openBackorders; ?></div>
  72. </div>
  73. </div>
  74. <h3 style="margin-top: 2rem;">Offene Reservierungen</h3>
  75. <?php
  76. $openReservationsList = array_slice(array_reverse($openRegularReservations), 0, 5);
  77. if (empty($openReservationsList)):
  78. ?>
  79. <p>Keine offenen Reservierungen vorhanden.</p>
  80. <?php else: ?>
  81. <div class="table-responsive">
  82. <table class="responsive-table">
  83. <thead>
  84. <tr>
  85. <th>Bestellnummer</th>
  86. <th>Kunde</th>
  87. <th>Erstellt</th>
  88. <th>Status</th>
  89. <th>Aktionen</th>
  90. </tr>
  91. </thead>
  92. <tbody>
  93. <?php foreach ($openReservationsList as $reservation): ?>
  94. <tr>
  95. <td data-label="Bestellnummer"><strong><?php echo htmlspecialchars($reservation['id']); ?></strong></td>
  96. <td data-label="Kunde"><?php echo htmlspecialchars($reservation['customer_name']); ?></td>
  97. <td data-label="Erstellt"><?php echo formatDate($reservation['created']); ?></td>
  98. <td data-label="Status">
  99. <?php
  100. if ($reservation['picked_up']) {
  101. echo '<span class="status status-picked">Abgeholt</span>';
  102. } elseif ($reservation['status'] === 'expired') {
  103. echo '<span class="status status-expired">Abgelaufen</span>';
  104. } else {
  105. echo '<span class="status status-open">Offen</span>';
  106. }
  107. ?>
  108. </td>
  109. <td data-label="Aktionen">
  110. <a href="reservations.php?order_number=<?php echo urlencode($reservation['id']); ?>" class="btn btn-small">Details</a>
  111. </td>
  112. </tr>
  113. <?php endforeach; ?>
  114. </tbody>
  115. </table>
  116. </div>
  117. <?php endif; ?>
  118. <h3 style="margin-top: 2rem;">Offene Vorbestellungen</h3>
  119. <?php
  120. $openPreordersList = array_slice(array_reverse($openPreorders), 0, 5);
  121. if (empty($openPreordersList)):
  122. ?>
  123. <p>Keine offenen Vorbestellungen vorhanden.</p>
  124. <?php else: ?>
  125. <div class="table-responsive">
  126. <table class="responsive-table">
  127. <thead>
  128. <tr>
  129. <th>Bestellnummer</th>
  130. <th>Kunde</th>
  131. <th>Erstellt</th>
  132. <th>Status</th>
  133. <th>Aktionen</th>
  134. </tr>
  135. </thead>
  136. <tbody>
  137. <?php foreach ($openPreordersList as $reservation): ?>
  138. <tr>
  139. <td data-label="Bestellnummer"><strong><?php echo htmlspecialchars($reservation['id']); ?></strong></td>
  140. <td data-label="Kunde"><?php echo htmlspecialchars($reservation['customer_name']); ?></td>
  141. <td data-label="Erstellt"><?php echo formatDate($reservation['created']); ?></td>
  142. <td data-label="Status">
  143. <?php
  144. if (isset($reservation['backorder_status']) && $reservation['backorder_status'] === 'notified') {
  145. echo '<span class="status status-notified">Informiert</span>';
  146. } else {
  147. echo '<span class="status status-open">Offen</span>';
  148. }
  149. ?>
  150. </td>
  151. <td data-label="Aktionen">
  152. <a href="backorders.php?order_number=<?php echo urlencode($reservation['id']); ?>" class="btn btn-small">Details</a>
  153. </td>
  154. </tr>
  155. <?php endforeach; ?>
  156. </tbody>
  157. </table>
  158. </div>
  159. <?php endif; ?>
  160. <?php include __DIR__ . '/../includes/footer.php'; ?>