| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- require_once __DIR__ . '/../config.php';
- require_once __DIR__ . '/../includes/functions.php';
- // Check admin login
- if (!isset($_SESSION['admin_logged_in']) || !$_SESSION['admin_logged_in']) {
- header('Location: login.php');
- exit;
- }
- $pageTitle = 'Admin Dashboard';
- // Get statistics
- $products = getProducts();
- $reservations = getReservations();
- // Expire old reservations
- expireOldReservations();
- $reservations = getReservations(); // Refresh after expiry
- $regularReservations = array_filter($reservations, function($r) {
- return !isset($r['type']) || $r['type'] !== 'backorder';
- });
- $totalProducts = count($products);
- $totalStock = 0;
- foreach ($products as $product) {
- $totalStock += getTotalStock($product);
- }
- $openReservations = count(array_filter($regularReservations, function($r) {
- return $r['status'] === 'open' && !$r['picked_up'];
- }));
- $pickedUpReservations = count(array_filter($regularReservations, function($r) {
- return $r['picked_up'];
- }));
- include __DIR__ . '/../includes/header.php';
- ?>
- <div class="admin-header">
- <h2>Admin Dashboard</h2>
- <div>
- <a href="products.php" class="btn">Produkte verwalten</a>
- <a href="reservations.php" class="btn">Reservierungen</a>
- <a href="backorders.php" class="btn">Nachbestellungen</a>
- <a href="login.php?logout=1" class="btn btn-secondary">Abmelden</a>
- </div>
- </div>
- <div class="admin-stats">
- <div class="stat-card">
- <h3>Produkte</h3>
- <div class="stat-value"><?php echo $totalProducts; ?></div>
- </div>
-
- <div class="stat-card">
- <h3>Gesamtbestand</h3>
- <div class="stat-value"><?php echo $totalStock; ?></div>
- </div>
-
- <div class="stat-card">
- <h3>Offene Reservierungen</h3>
- <div class="stat-value"><?php echo $openReservations; ?></div>
- </div>
-
- <div class="stat-card">
- <h3>Abgeholt</h3>
- <div class="stat-value"><?php echo $pickedUpReservations; ?></div>
- </div>
- </div>
- <h3 style="margin-top: 2rem;">Letzte Reservierungen</h3>
- <?php
- $recentReservations = array_slice(array_reverse($regularReservations), 0, 5);
- if (empty($recentReservations)):
- ?>
- <p>Keine Reservierungen vorhanden.</p>
- <?php else: ?>
- <table>
- <thead>
- <tr>
- <th>Code</th>
- <th>Kunde</th>
- <th>Erstellt</th>
- <th>Status</th>
- <th>Aktionen</th>
- </tr>
- </thead>
- <tbody>
- <?php foreach ($recentReservations as $reservation): ?>
- <tr>
- <td><strong><?php echo htmlspecialchars($reservation['code']); ?></strong></td>
- <td><?php echo htmlspecialchars($reservation['customer_name']); ?></td>
- <td><?php echo formatDate($reservation['created']); ?></td>
- <td>
- <?php
- if ($reservation['picked_up']) {
- echo '<span style="color: #28a745;">Abgeholt</span>';
- } elseif ($reservation['status'] === 'expired') {
- echo '<span style="color: #dc3545;">Abgelaufen</span>';
- } else {
- echo '<span style="color: #ffc107;">Offen</span>';
- }
- ?>
- </td>
- <td>
- <a href="reservations.php?code=<?php echo urlencode($reservation['code']); ?>" class="btn btn-small">Details</a>
- </td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <?php endif; ?>
- <?php include __DIR__ . '/../includes/footer.php'; ?>
|