| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?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';
- });
- $backorderReservations = 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'];
- }));
- $openRegularReservations = array_values(array_filter($regularReservations, function($r) {
- return $r['status'] === 'open' && !$r['picked_up'];
- }));
- $openPreorders = array_values(array_filter($backorderReservations, function($r) {
- return !isset($r['backorder_status']) || $r['backorder_status'] !== 'notified';
- }));
- $openBackorders = count($openPreorders);
- 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">Vorbestellungen</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 class="stat-card">
- <h3>Offene Vorbestellungen</h3>
- <div class="stat-value"><?php echo $openBackorders; ?></div>
- </div>
-
- </div>
- <h3 style="margin-top: 2rem;">Offene Reservierungen</h3>
- <?php
- $openReservationsList = array_slice(array_reverse($openRegularReservations), 0, 5);
- if (empty($openReservationsList)):
- ?>
- <p>Keine offenen Reservierungen vorhanden.</p>
- <?php else: ?>
- <table>
- <thead>
- <tr>
- <th>Bestellnummer</th>
- <th>Kunde</th>
- <th>Erstellt</th>
- <th>Status</th>
- <th>Aktionen</th>
- </tr>
- </thead>
- <tbody>
- <?php foreach ($openReservationsList as $reservation): ?>
- <tr>
- <td><strong><?php echo htmlspecialchars($reservation['id']); ?></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 class="status status-picked">Abgeholt</span>';
- } elseif ($reservation['status'] === 'expired') {
- echo '<span class="status status-expired">Abgelaufen</span>';
- } else {
- echo '<span class="status status-open">Offen</span>';
- }
- ?>
- </td>
- <td>
- <a href="reservations.php?order_number=<?php echo urlencode($reservation['id']); ?>" class="btn btn-small">Details</a>
- </td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <?php endif; ?>
- <h3 style="margin-top: 2rem;">Offene Vorbestellungen</h3>
- <?php
- $openPreordersList = array_slice(array_reverse($openPreorders), 0, 5);
- if (empty($openPreordersList)):
- ?>
- <p>Keine offenen Vorbestellungen vorhanden.</p>
- <?php else: ?>
- <table>
- <thead>
- <tr>
- <th>Bestellnummer</th>
- <th>Kunde</th>
- <th>Erstellt</th>
- <th>Status</th>
- <th>Aktionen</th>
- </tr>
- </thead>
- <tbody>
- <?php foreach ($openPreordersList as $reservation): ?>
- <tr>
- <td><strong><?php echo htmlspecialchars($reservation['id']); ?></strong></td>
- <td><?php echo htmlspecialchars($reservation['customer_name']); ?></td>
- <td><?php echo formatDate($reservation['created']); ?></td>
- <td>
- <?php
- if (isset($reservation['backorder_status']) && $reservation['backorder_status'] === 'notified') {
- echo '<span class="status status-notified">Informiert</span>';
- } else {
- echo '<span class="status status-open">Offen</span>';
- }
- ?>
- </td>
- <td>
- <a href="backorders.php?order_number=<?php echo urlencode($reservation['id']); ?>" class="btn btn-small">Details</a>
- </td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <?php endif; ?>
- <?php include __DIR__ . '/../includes/footer.php'; ?>
|