index.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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"])
  8. ? normalizeCategoryId($_GET["category"])
  9. : "";
  10. if ($category !== "" && getCategoryById($category) !== null) {
  11. $products = array_values(
  12. array_filter($products, function ($product) use ($category) {
  13. return productHasCategory($product, $category);
  14. }),
  15. );
  16. } else {
  17. $category = "";
  18. }
  19. include __DIR__ . "/includes/header.php";
  20. ?>
  21. <h2><?php echo escape(SITE_SERVICE_HEADER); ?></h2>
  22. <div class="disclaimer-box">
  23. <?php foreach (DISCLAIMER_LINES as $line): ?>
  24. <p><?php echo escape($line); ?></p>
  25. <?php endforeach; ?>
  26. </div>
  27. <div class="category-filter-bar" aria-label="Produktkategorien">
  28. <a href="?category=" class="btn btn-small <?php echo $category === ""
  29. ? ""
  30. : "btn-secondary"; ?>">Alle</a>
  31. <?php foreach ($categories as $categoryOption): ?>
  32. <a href="?category=<?php echo urlencode(
  33. $categoryOption["id"],
  34. ); ?>" class="btn btn-small <?php echo $category ===
  35. $categoryOption["id"]
  36. ? ""
  37. : "btn-secondary"; ?>">
  38. <?php echo escape($categoryOption["label"]); ?>
  39. </a>
  40. <?php endforeach; ?>
  41. </div>
  42. <?php if (empty($products)): ?>
  43. <div class="alert alert-info">
  44. <p>Keine Produkte gefunden.</p>
  45. </div>
  46. <?php else: ?>
  47. <div class="products-grid">
  48. <?php foreach ($products as $product): ?>
  49. <div class="product-card">
  50. <a href="product.php?id=<?php echo (int) $product["id"]; ?>">
  51. <?php $imagePath = getUploadPath(
  52. $product["image"] ?? "",
  53. ); ?>
  54. <?php $imageUrl = getUploadUrl($product["image"] ?? ""); ?>
  55. <?php if (
  56. $imagePath !== null &&
  57. $imageUrl !== null &&
  58. file_exists($imagePath)
  59. ): ?>
  60. <img src="<?php echo escape(
  61. $imageUrl,
  62. ); ?>" alt="<?php echo escape($product["name"]); ?>">
  63. <?php else: ?>
  64. <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">
  65. <?php endif; ?>
  66. </a>
  67. <div class="product-card-content">
  68. <h3><a href="product.php?id=<?php echo (int) $product[
  69. "id"
  70. ]; ?>" class="product-card-title-link"><?php echo escape(
  71. $product["name"],
  72. ); ?></a></h3>
  73. <a href="product.php?id=<?php echo (int) $product[
  74. "id"
  75. ]; ?>" class="btn btn-block mt-2">Details ansehen</a>
  76. </div>
  77. </div>
  78. <?php endforeach; ?>
  79. </div>
  80. <?php endif; ?>
  81. <?php include __DIR__ . "/includes/footer.php"; ?>