index.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. $startpageIntroLines = getStartpageIntroLines();
  8. $category = isset($_GET['category'])
  9. ? normalizeCategoryId($_GET['category'])
  10. : "";
  11. if ($category !== "" && getCategoryById($category) !== null) {
  12. $products = array_values(
  13. array_filter($products, function ($product) use ($category) {
  14. return productHasCategory($product, $category);
  15. }),
  16. );
  17. } else {
  18. $category = "";
  19. }
  20. include __DIR__ . "/includes/header.php";
  21. ?>
  22. <h2><?php echo escape(SITE_SERVICE_HEADER); ?></h2>
  23. <div class="disclaimer-box">
  24. <?php foreach ($startpageIntroLines as $line): ?>
  25. <p><?php echo escape($line); ?></p>
  26. <?php endforeach; ?>
  27. </div>
  28. <div class="category-filter-bar" aria-label="Produktkategorien">
  29. <a href="?category=" class="btn btn-small <?php echo $category === ""
  30. ? ""
  31. : "btn-secondary"; ?>">Alle</a>
  32. <?php foreach ($categories as $categoryOption): ?>
  33. <a href="?category=<?php echo urlencode(
  34. $categoryOption["id"],
  35. ); ?>" class="btn btn-small <?php echo $category ===
  36. $categoryOption["id"]
  37. ? ""
  38. : "btn-secondary"; ?>">
  39. <?php echo escape($categoryOption["label"]); ?>
  40. </a>
  41. <?php endforeach; ?>
  42. </div>
  43. <?php if (empty($products)): ?>
  44. <div class="alert alert-info">
  45. <p>Keine Produkte gefunden.</p>
  46. </div>
  47. <?php else: ?>
  48. <div class="products-grid">
  49. <?php foreach ($products as $product): ?>
  50. <div class="product-card">
  51. <a href="product.php?id=<?php echo (int) $product["id"]; ?>">
  52. <?php $imagePath = getUploadPath(
  53. $product["image"] ?? "",
  54. ); ?>
  55. <?php $imageUrl = getUploadUrl($product["image"] ?? ""); ?>
  56. <?php if (
  57. $imagePath !== null &&
  58. $imageUrl !== null &&
  59. file_exists($imagePath)
  60. ): ?>
  61. <img src="<?php echo escape(
  62. $imageUrl,
  63. ); ?>" alt="<?php echo escape($product["name"]); ?>">
  64. <?php else: ?>
  65. <img src="assets/no-image.jpg" alt="Kein Bild verfügbar">
  66. <?php endif; ?>
  67. </a>
  68. <div class="product-card-content">
  69. <h3><a href="product.php?id=<?php echo (int) $product[
  70. "id"
  71. ]; ?>" class="product-card-title-link"><?php echo escape(
  72. $product["name"],
  73. ); ?></a></h3>
  74. <?php $productCategoryIds = getProductCategoryIds($product); ?>
  75. <?php if (!empty($productCategoryIds)): ?>
  76. <div class="product-card-categories" aria-label="Kategorien">
  77. <?php foreach ($productCategoryIds as $productCategoryId): ?>
  78. <?php $chipPalette = getCategoryChipPalette(
  79. $productCategoryId,
  80. ); ?>
  81. <span class="category-chip" style="background-color: <?php echo escape(
  82. $chipPalette["background"],
  83. ); ?>; border-color: <?php echo escape(
  84. $chipPalette["border"],
  85. ); ?>; color: <?php echo escape($chipPalette["text"]); ?>;">
  86. <?php echo escape(
  87. getCategoryLabel($productCategoryId),
  88. ); ?>
  89. </span>
  90. <?php endforeach; ?>
  91. </div>
  92. <?php endif; ?>
  93. <a href="product.php?id=<?php echo (int) $product[
  94. "id"
  95. ]; ?>" class="btn btn-block mt-2">Details ansehen</a>
  96. </div>
  97. </div>
  98. <?php endforeach; ?>
  99. </div>
  100. <?php endif; ?>
  101. <?php include __DIR__ . "/includes/footer.php"; ?>