index.php 5.6 KB

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