index.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. require_once __DIR__ . '/config.php';
  3. require_once __DIR__ . '/includes/functions.php';
  4. $pageTitle = 'Startseite';
  5. $products = getProducts();
  6. $categories = getCategories();
  7. // Filter by category if provided
  8. $category = isset($_GET['category']) ? normalizeCategoryId($_GET['category']) : '';
  9. if ($category !== '' && getCategoryById($category) !== null) {
  10. $products = array_filter($products, function($product) use ($category) {
  11. return productHasCategory($product, $category);
  12. });
  13. } else {
  14. $category = '';
  15. }
  16. include __DIR__ . '/includes/header.php';
  17. ?>
  18. <h2>Unsere Produkte</h2>
  19. <div class="disclaimer-box">
  20. <?php foreach (DISCLAIMER_LINES as $line): ?>
  21. <p><?php echo htmlspecialchars($line); ?></p>
  22. <?php endforeach; ?>
  23. </div>
  24. <div class="category-filter-bar" aria-label="Produktkategorien">
  25. <a href="?category=" class="btn btn-small <?php echo $category === '' ? '' : 'btn-secondary'; ?>">Alle</a>
  26. <?php foreach ($categories as $categoryOption): ?>
  27. <a href="?category=<?php echo urlencode($categoryOption['id']); ?>" class="btn btn-small <?php echo $category === $categoryOption['id'] ? '' : 'btn-secondary'; ?>">
  28. <?php echo htmlspecialchars($categoryOption['label']); ?>
  29. </a>
  30. <?php endforeach; ?>
  31. </div>
  32. <?php if (empty($products)): ?>
  33. <div class="alert alert-info">
  34. <p>Keine Produkte gefunden.</p>
  35. </div>
  36. <?php else: ?>
  37. <div class="products-grid">
  38. <?php foreach ($products as $product): ?>
  39. <div class="product-card">
  40. <a href="product.php?id=<?php echo $product['id']; ?>">
  41. <?php if (!empty($product['image']) && file_exists(__DIR__ . '/assets/images/' . $product['image'])): ?>
  42. <img src="<?php echo SITE_URL; ?>/assets/images/<?php echo htmlspecialchars($product['image']); ?>" alt="<?php echo htmlspecialchars($product['name']); ?>">
  43. <?php else: ?>
  44. <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='200'%3E%3Crect fill='%23e9ecef' width='250' height='200'/%3E%3Ctext x='50%25' y='50%25' text-anchor='middle' dy='.3em' fill='%236c757d'%3EKein Bild%3C/text%3E%3C/svg%3E" alt="Kein Bild">
  45. <?php endif; ?>
  46. </a>
  47. <div class="product-card-content">
  48. <h3><a href="product.php?id=<?php echo $product['id']; ?>" style="text-decoration: none; color: inherit;"><?php echo htmlspecialchars($product['name']); ?></a></h3>
  49. <div class="price"><?php echo formatPrice($product['price']); ?></div>
  50. <?php
  51. $totalStock = getTotalStock($product);
  52. ?>
  53. <div class="stock <?php echo $totalStock > 0 ? 'in-stock' : 'out-of-stock'; ?>">
  54. <?php if ($totalStock > 0): ?>
  55. Verfügbar (<?php echo $totalStock; ?> Stück)
  56. <?php else: ?>
  57. Ausverkauft - Vorbestellung möglich
  58. <?php endif; ?>
  59. </div>
  60. <a href="product.php?id=<?php echo $product['id']; ?>" class="btn" style="width: 100%; text-align: center; margin-top: 1rem;">Details ansehen</a>
  61. </div>
  62. </div>
  63. <?php endforeach; ?>
  64. </div>
  65. <?php endif; ?>
  66. <?php include __DIR__ . '/includes/footer.php'; ?>