index.php 5.9 KB

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