index.php 6.9 KB

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