229 lines
11 KiB
PHP
229 lines
11 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
require_once 'includes/auth.php';
|
|
require_login();
|
|
|
|
require_once 'includes/helpers.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Fetch products and their primary images
|
|
$sql = "SELECT
|
|
p.*,
|
|
(SELECT file_path
|
|
FROM product_images
|
|
WHERE product_id = p.id
|
|
ORDER BY is_primary DESC, id ASC
|
|
LIMIT 1) AS image_path
|
|
FROM
|
|
products p
|
|
WHERE
|
|
p.is_active = 1
|
|
ORDER BY
|
|
CASE p.product_role WHEN 'membrana' THEN 1 WHEN 'akcesoria' THEN 2 ELSE 3 END, p.name ASC";
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute();
|
|
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// Separate products into main and accessories
|
|
$main_products = [];
|
|
$accessories = [];
|
|
foreach ($products as $product) {
|
|
if ($product['product_role'] === 'akcesoria') {
|
|
$accessories[] = $product;
|
|
} else {
|
|
$main_products[] = $product;
|
|
}
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
$error = "Błąd bazy danych: " . $e->getMessage();
|
|
$products = [];
|
|
$main_products = [];
|
|
$accessories = [];
|
|
}
|
|
|
|
$user_role = get_user_role();
|
|
$page_title = 'Katalog';
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="pl">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?= htmlspecialchars($page_title) ?> - B2B Commerce</title>
|
|
|
|
<!-- SEO Meta Tags -->
|
|
<meta name="description" content="<?= htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'A B2B E-commerce Platform') ?>">
|
|
|
|
<!-- Open Graph / Twitter Meta Tags (managed by the platform) -->
|
|
<meta property="og:title" content="<?= htmlspecialchars($page_title) ?>">
|
|
<meta property="og:description" content="<?= htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'A B2B E-commerce Platform') ?>">
|
|
<meta property="og:image" content="<?= htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? '') ?>">
|
|
<meta name="twitter:card" content="summary_large_image">
|
|
|
|
<!-- Bootstrap 5.3 CSS -->
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
|
|
<!-- Bootstrap Icons -->
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
|
|
<!-- Custom CSS -->
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?= time() ?>">
|
|
</head>
|
|
<body>
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
|
<div class="container-fluid">
|
|
<a class="navbar-brand" href="index.php">
|
|
<img src="assets/pasted-20251209-065617-6bf1b4e6.png" alt="Logo" style="height: 40px;">
|
|
</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
|
<ul class="navbar-nav ms-auto mb-2 mb-lg-0 align-items-center">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="index.php">Katalog</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="cart.php">
|
|
<i class="bi bi-cart"></i> Koszyk
|
|
<span class="badge bg-primary rounded-pill"><?= count($_SESSION['cart'] ?? []) ?></span>
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="orders.php">Zamówienia</a>
|
|
</li>
|
|
<?php if ($user_role === 'admin'): ?>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="/admin/products.php">Admin</a>
|
|
</li>
|
|
<?php endif; ?>
|
|
<li class="nav-item dropdown">
|
|
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<i class="bi bi-person-circle"></i> Witaj, <?= isset($_SESSION['username']) ? htmlspecialchars($_SESSION['username']) : '' ?>
|
|
</a>
|
|
<ul class="dropdown-menu dropdown-menu-end">
|
|
<li><a class="dropdown-item p-2" href="profile.php">Profil</a></li>
|
|
<li><hr class="dropdown-divider"></li>
|
|
<li><a class="dropdown-item p-2" href="logout.php">Wyloguj</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container my-5">
|
|
<h1 class="mb-4">Katalog</h1>
|
|
|
|
<?php if (!empty($error)): ?>
|
|
<div class="alert alert-danger"><?= htmlspecialchars($error) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 g-4">
|
|
<?php foreach ($main_products as $product):
|
|
$prices = getEffectivePrice($pdo, $product['id'], $_SESSION['client_id']);
|
|
$image_url = !empty($product['image_path'])
|
|
? 'uploads/products/' . htmlspecialchars($product['image_path'])
|
|
: 'https://placehold.co/600x400/EEE/31343C?text=Brak+zdj%C4%99cia';
|
|
?>
|
|
<div class="col">
|
|
<div class="card h-100 product-card shadow-sm">
|
|
<a href="product.php?id=<?= (int)$product['id'] ?>">
|
|
<img src="<?= $image_url ?>" class="card-img-top" alt="<?= htmlspecialchars($product['name']) ?>" style="height: 200px; object-fit: cover;">
|
|
</a>
|
|
<div class="card-body d-flex flex-column">
|
|
<h5 class="card-title">
|
|
<a href="product.php?id=<?= (int)$product['id'] ?>" class="text-decoration-none text-dark">
|
|
<?= htmlspecialchars($product['name']) ?>
|
|
</a>
|
|
</h5>
|
|
<p class="card-text text-secondary small flex-grow-1"><?php
|
|
$desc = $product['description'];
|
|
echo htmlspecialchars(strlen($desc) > 100 ? substr($desc, 0, 100) . '...' : $desc);
|
|
?></p>
|
|
<div class="mt-auto">
|
|
<p class="card-text text-muted small mb-0"><?= htmlspecialchars(number_format($prices['net'], 2, ',', ' ')) ?> zł netto</p>
|
|
<p class="card-text fw-bold fs-5"><?= htmlspecialchars(number_format($prices['gross'], 2, ',', ' ')) ?> zł brutto</p>
|
|
</div>
|
|
</div>
|
|
<div class="card-footer bg-white border-top-0 pb-3">
|
|
<form action="cart_actions.php" method="POST" class="d-grid">
|
|
<input type="hidden" name="action" value="add">
|
|
<input type="hidden" name="product_id" value="<?= $product['id'] ?>">
|
|
<input type="hidden" name="redirect_to" value="index.php">
|
|
<div class="input-group">
|
|
<input type="number" class="form-control" name="quantity" value="1" min="1" aria-label="Ilość" step="1">
|
|
<button type="submit" class="btn btn-primary">
|
|
<i class="bi bi-cart-plus"></i>
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<?php if (!empty($accessories)): ?>
|
|
<hr class="my-5">
|
|
<h2 class="mb-4">Akcesoria i produkty uzupełniające</h2>
|
|
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-4 row-cols-lg-5 g-4">
|
|
<?php foreach ($accessories as $product):
|
|
$prices = getEffectivePrice($pdo, $product['id'], $_SESSION['client_id']);
|
|
$image_url = !empty($product['image_path'])
|
|
? 'uploads/products/' . htmlspecialchars($product['image_path'])
|
|
: 'https://placehold.co/600x400/EEE/31343C?text=Brak+zdj%C4%99cia';
|
|
?>
|
|
<div class="col">
|
|
<div class="card h-100 product-card shadow-sm">
|
|
<a href="product.php?id=<?= (int)$product['id'] ?>">
|
|
<img src="<?= $image_url ?>" class="card-img-top" alt="<?= htmlspecialchars($product['name']) ?>" style="height: 150px; object-fit: cover;">
|
|
</a>
|
|
<div class="card-body d-flex flex-column">
|
|
<h6 class="card-title">
|
|
<a href="product.php?id=<?= (int)$product['id'] ?>" class="text-decoration-none text-dark">
|
|
<?= htmlspecialchars($product['name']) ?>
|
|
</a>
|
|
</h6>
|
|
<div class="mt-auto">
|
|
<p class="card-text text-muted small mb-0"><?= htmlspecialchars(number_format($prices['net'], 2, ',', ' ')) ?> zł netto</p>
|
|
<p class="card-text fw-bold"><?= htmlspecialchars(number_format($prices['gross'], 2, ',', ' ')) ?> zł brutto</p>
|
|
</div>
|
|
</div>
|
|
<div class="card-footer bg-white border-top-0 pb-3">
|
|
<form action="cart_actions.php" method="POST" class="d-grid">
|
|
<input type="hidden" name="action" value="add">
|
|
<input type="hidden" name="product_id" value="<?= $product['id'] ?>">
|
|
<input type="hidden" name="redirect_to" value="index.php">
|
|
<div class="input-group">
|
|
<input type="number" class="form-control form-control-sm" name="quantity" value="1" min="1" aria-label="Ilość" step="1">
|
|
<button type="submit" class="btn btn-sm btn-primary">
|
|
<i class="bi bi-cart-plus"></i>
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
</main>
|
|
|
|
<footer class="text-center py-4 mt-auto text-muted bg-light">
|
|
<div class="container">
|
|
<p class="mb-0">© <?php echo date("Y"); ?> powered by LEA24. All Rights Reserved.</p>
|
|
</div>
|
|
</footer>
|
|
|
|
<!-- Bootstrap 5.3 JS -->
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|