index.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. $category = isset($_GET['category']) ? normalizeCategoryId($_GET['category']) : '';
  8. if ($category !== '' && getCategoryById($category) !== null) {
  9. $products = array_values(array_filter($products, function ($product) use ($category) {
  10. return productHasCategory($product, $category);
  11. }));
  12. } else {
  13. $category = '';
  14. }
  15. include __DIR__ . '/includes/header.php';
  16. ?>
  17. <h2><?php echo escape(SITE_SERVICE_HEADER); ?></h2>
  18. <div class="disclaimer-box">
  19. <?php foreach (DISCLAIMER_LINES as $line): ?>
  20. <p><?php echo escape($line); ?></p>
  21. <?php endforeach; ?>
  22. </div>
  23. <div class="category-filter-bar" aria-label="Produktkategorien">
  24. <a href="?category=" class="btn btn-small <?php echo $category === '' ? '' : 'btn-secondary'; ?>">Alle</a>
  25. <?php foreach ($categories as $categoryOption): ?>
  26. <a href="?category=<?php echo urlencode($categoryOption['id']); ?>" class="btn btn-small <?php echo $category === $categoryOption['id'] ? '' : 'btn-secondary'; ?>">
  27. <?php echo escape($categoryOption['label']); ?>
  28. </a>
  29. <?php endforeach; ?>
  30. </div>
  31. <?php if (empty($products)): ?>
  32. <div class="alert alert-info">
  33. <p>Keine Produkte gefunden.</p>
  34. </div>
  35. <?php else: ?>
  36. <div class="products-grid">
  37. <?php foreach ($products as $product): ?>
  38. <div class="product-card">
  39. <a href="product.php?id=<?php echo (int) $product['id']; ?>">
  40. <?php $imagePath = getUploadPath($product['image'] ?? ''); ?>
  41. <?php $imageUrl = getUploadUrl($product['image'] ?? ''); ?>
  42. <?php if ($imagePath !== null && $imageUrl !== null && file_exists($imagePath)): ?>
  43. <img src="<?php echo escape($imageUrl); ?>" alt="<?php echo escape($product['name']); ?>">
  44. <?php else: ?>
  45. <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='200'%3E%3Crect fill='%233a4150' width='250' height='200'/%3E%3Ctext x='50%25' y='50%25' text-anchor='middle' dy='.3em' fill='%23c7ccd6'%3EKein Bild%3C/text%3E%3C/svg%3E" alt="Kein Bild">
  46. <?php endif; ?>
  47. </a>
  48. <div class="product-card-content">
  49. <h3><a href="product.php?id=<?php echo (int) $product['id']; ?>" class="product-card-title-link"><?php echo escape($product['name']); ?></a></h3>
  50. <p class="product-summary"><?php echo escape(implode(', ', getProductSizes($product))); ?></p>
  51. <a href="product.php?id=<?php echo (int) $product['id']; ?>" class="btn btn-block mt-2">Details ansehen</a>
  52. </div>
  53. </div>
  54. <?php endforeach; ?>
  55. </div>
  56. <?php endif; ?>
  57. <?php include __DIR__ . '/includes/footer.php'; ?>