index.php 6.7 KB

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