index.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. $totalProducts = count($products);
  20. $totalStock = 0;
  21. foreach ($products as $product) {
  22. $totalStock += getTotalStock($product);
  23. }
  24. $openReservations = count(array_filter($regularReservations, function($r) {
  25. return $r['status'] === 'open' && !$r['picked_up'];
  26. }));
  27. $pickedUpReservations = count(array_filter($regularReservations, function($r) {
  28. return $r['picked_up'];
  29. }));
  30. include __DIR__ . '/../includes/header.php';
  31. ?>
  32. <div class="admin-header">
  33. <h2>Admin Dashboard</h2>
  34. <div>
  35. <a href="products.php" class="btn">Produkte verwalten</a>
  36. <a href="reservations.php" class="btn">Reservierungen</a>
  37. <a href="backorders.php" class="btn">Nachbestellungen</a>
  38. <a href="login.php?logout=1" class="btn btn-secondary">Abmelden</a>
  39. </div>
  40. </div>
  41. <div class="admin-stats">
  42. <div class="stat-card">
  43. <h3>Produkte</h3>
  44. <div class="stat-value"><?php echo $totalProducts; ?></div>
  45. </div>
  46. <div class="stat-card">
  47. <h3>Gesamtbestand</h3>
  48. <div class="stat-value"><?php echo $totalStock; ?></div>
  49. </div>
  50. <div class="stat-card">
  51. <h3>Offene Reservierungen</h3>
  52. <div class="stat-value"><?php echo $openReservations; ?></div>
  53. </div>
  54. <div class="stat-card">
  55. <h3>Abgeholt</h3>
  56. <div class="stat-value"><?php echo $pickedUpReservations; ?></div>
  57. </div>
  58. </div>
  59. <h3 style="margin-top: 2rem;">Letzte Reservierungen</h3>
  60. <?php
  61. $recentReservations = array_slice(array_reverse($regularReservations), 0, 5);
  62. if (empty($recentReservations)):
  63. ?>
  64. <p>Keine Reservierungen vorhanden.</p>
  65. <?php else: ?>
  66. <table>
  67. <thead>
  68. <tr>
  69. <th>Code</th>
  70. <th>Kunde</th>
  71. <th>Erstellt</th>
  72. <th>Status</th>
  73. <th>Aktionen</th>
  74. </tr>
  75. </thead>
  76. <tbody>
  77. <?php foreach ($recentReservations as $reservation): ?>
  78. <tr>
  79. <td><strong><?php echo htmlspecialchars($reservation['code']); ?></strong></td>
  80. <td><?php echo htmlspecialchars($reservation['customer_name']); ?></td>
  81. <td><?php echo formatDate($reservation['created']); ?></td>
  82. <td>
  83. <?php
  84. if ($reservation['picked_up']) {
  85. echo '<span style="color: #28a745;">Abgeholt</span>';
  86. } elseif ($reservation['status'] === 'expired') {
  87. echo '<span style="color: #dc3545;">Abgelaufen</span>';
  88. } else {
  89. echo '<span style="color: #ffc107;">Offen</span>';
  90. }
  91. ?>
  92. </td>
  93. <td>
  94. <a href="reservations.php?code=<?php echo urlencode($reservation['code']); ?>" class="btn btn-small">Details</a>
  95. </td>
  96. </tr>
  97. <?php endforeach; ?>
  98. </tbody>
  99. </table>
  100. <?php endif; ?>
  101. <?php include __DIR__ . '/../includes/footer.php'; ?>