index.php 6.0 KB

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