index.php 7.0 KB

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