index.php 3.4 KB

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