285 lines
15 KiB
PHP
285 lines
15 KiB
PHP
<?php
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
session_start();
|
|
}
|
|
require_once 'includes/auth.php';
|
|
require_login();
|
|
require_once 'includes/helpers.php';
|
|
|
|
$product_id = $_GET['id'] ?? null;
|
|
|
|
if (!$product_id) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT p.*,
|
|
COALESCE(cp.price, p.price_gross) as final_price,
|
|
p.price_net as final_price_net
|
|
FROM products p
|
|
LEFT JOIN users u ON u.id = :user_id
|
|
LEFT JOIN client_prices cp ON cp.product_id = p.id AND cp.client_id = u.client_id
|
|
WHERE p.id = :product_id");
|
|
$stmt->execute(['user_id' => $_SESSION['user_id'], 'product_id' => $product_id]);
|
|
$product = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$product) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
// If client-specific price is used, re-calculate net price from it
|
|
if (!empty($product['final_price']) && empty($product['final_price_net'])) {
|
|
$product['final_price_net'] = round($product['final_price'] / 1.23, 2);
|
|
}
|
|
|
|
|
|
// Fetch product images
|
|
$img_stmt = $pdo->prepare("SELECT * FROM product_images WHERE product_id = ? ORDER BY is_primary DESC, id ASC");
|
|
$img_stmt->execute([$product_id]);
|
|
$product_images = $img_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
$primary_image = $product_images[0] ?? null;
|
|
|
|
} catch (PDOException $e) {
|
|
die('Błąd połączenia z bazą danych: ' . $e->getMessage());
|
|
}
|
|
|
|
$page_title = htmlspecialchars($product['name']);
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="pl">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?php echo $page_title; ?> - ExtraB2B</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
<?php
|
|
// Note: This header is a modified, inline version for product.php to remove language features.
|
|
$user_role = get_user_role();
|
|
?>
|
|
<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="Przełącz nawigację">
|
|
<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">
|
|
<a href="index.php" class="btn btn-outline-secondary mb-3"> ← Wróć do listy produktów </a>
|
|
<div class="row">
|
|
<!-- Product Image Gallery -->
|
|
<div class="col-lg-6 mb-4 mb-lg-0">
|
|
<div class="text-center">
|
|
<?php
|
|
$primary_image_url = 'https://placehold.co/600x400/EEE/31343C?text=Brak+zdj%C4%99cia';
|
|
if (!empty($product_images)) {
|
|
$primary_image_url = 'uploads/products/' . htmlspecialchars($product_images[0]['file_path']);
|
|
}
|
|
?>
|
|
<img src="<?= $primary_image_url ?>" alt="<?= htmlspecialchars($product['name']) ?>" class="img-fluid rounded shadow-sm mb-3" id="main-product-image">
|
|
</div>
|
|
|
|
<?php if (count($product_images) > 1): ?>
|
|
<div class="row gx-2 justify-content-center">
|
|
<?php foreach ($product_images as $image): ?>
|
|
<div class="col-2">
|
|
<a href="uploads/products/<?= htmlspecialchars($image['file_path']) ?>" class="product-thumbnail d-block border rounded">
|
|
<img src="uploads/products/<?= htmlspecialchars($image['file_path']) ?>" alt="Miniatura produktu" class="img-fluid">
|
|
</a>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<!-- Product Details -->
|
|
<div class="col-lg-6">
|
|
<h1 class="mb-3"><?= htmlspecialchars($product['name']) ?></h1>
|
|
|
|
<div class="bg-light p-4 rounded mb-4">
|
|
<h2 class="h4 fw-bold"><?= htmlspecialchars(number_format($product['final_price'], 2, ',', ' ')) ?> PLN / <?= htmlspecialchars($product['unit']) ?></h2>
|
|
<small class="text-muted">Cena brutto</small>
|
|
<p class="mb-0"><?= htmlspecialchars(number_format($product['final_price_net'], 2, ',', ' ')) ?> PLN netto</p>
|
|
</div>
|
|
|
|
<form action="cart_actions.php" method="post" class="d-flex align-items-center">
|
|
<input type="hidden" name="action" value="add">
|
|
<input type="hidden" name="product_id" value="<?= $product['id'] ?>">
|
|
<div style="max-width: 200px;" class="me-3">
|
|
<label for="quantity" class="form-label">Ilość (<?= htmlspecialchars($product['unit']) ?>):</label>
|
|
<input type="number" id="quantity" name="quantity" class="form-control" value="1" min="1">
|
|
</div>
|
|
<button type="submit" class="btn btn-primary mt-4">
|
|
<i class="bi bi-cart-plus"></i> Dodaj do koszyka
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Additional Info Tabs -->
|
|
<div class="mt-5">
|
|
<ul class="nav nav-tabs" id="productTabs" role="tablist">
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link active" id="description-tab" data-bs-toggle="tab" data-bs-target="#description" type="button" role="tab" aria-controls="description" aria-selected="true">Opis</button>
|
|
</li>
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link" id="specs-tab" data-bs-toggle="tab" data-bs-target="#specs" type="button" role="tab" aria-controls="specs" aria-selected="false">Dane techniczne</button>
|
|
</li>
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link" id="documents-tab" data-bs-toggle="tab" data-bs-target="#documents" type="button" role="tab" aria-controls="documents" aria-selected="false">Dokumenty</button>
|
|
</li>
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link" id="related-tab" data-bs-toggle="tab" data-bs-target="#related" type="button" role="tab" aria-controls="related" aria-selected="false">Produkty powiązane</button>
|
|
</li>
|
|
</ul>
|
|
<div class="tab-content p-3 border border-top-0" id="productTabsContent">
|
|
<div class="tab-pane fade show active" id="description" role="tabpanel" aria-labelledby="description-tab">
|
|
<p class="lead mb-4"><?= nl2br(htmlspecialchars($product['description'])) ?></p>
|
|
</div>
|
|
<div class="tab-pane fade" id="specs" role="tabpanel" aria-labelledby="specs-tab">
|
|
<?php
|
|
$attrs_stmt = $pdo->prepare("SELECT ak.name, pa.value FROM product_attributes pa JOIN attribute_keys ak ON pa.attribute_key_id = ak.id WHERE pa.product_id = ? AND pa.value IS NOT NULL AND pa.value != '' ORDER BY ak.name");
|
|
$attrs_stmt->execute([$product_id]);
|
|
$product_attributes = $attrs_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if ($product_attributes) {
|
|
echo '<table class="table table-striped">';
|
|
echo '<tbody>';
|
|
foreach ($product_attributes as $attr) {
|
|
echo '<tr>';
|
|
echo '<th>' . htmlspecialchars($attr['name']) . '</th>';
|
|
echo '<td>' . htmlspecialchars($attr['value']) . '</td>';
|
|
echo '</tr>';
|
|
}
|
|
echo '</tbody>';
|
|
echo '</table>';
|
|
} else {
|
|
echo '<p>Brak dodatkowych danych technicznych.</p>';
|
|
}
|
|
?>
|
|
</div>
|
|
<div class="tab-pane fade" id="documents" role="tabpanel" aria-labelledby="documents-tab">
|
|
<?php
|
|
$docs_stmt = $pdo->prepare("SELECT * FROM product_documents WHERE product_id = ?");
|
|
$docs_stmt->execute([$product_id]);
|
|
$product_documents = $docs_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if ($product_documents) {
|
|
echo '<ul class="list-group list-group-flush">';
|
|
foreach ($product_documents as $doc) {
|
|
echo '<li class="list-group-item"><a href="uploads/documents/' . htmlspecialchars($doc['file_path']) . '" download><i class="bi bi-file-earmark-arrow-down"></i> ' . htmlspecialchars($doc['file_name']) . '</a></li>';
|
|
}
|
|
echo '</ul>';
|
|
} else {
|
|
echo '<p class="mb-0">Brak dokumentów do pobrania.</p>';
|
|
}
|
|
?>
|
|
</div>
|
|
<div class="tab-pane fade" id="related" role="tabpanel" aria-labelledby="related-tab">
|
|
<div class="row">
|
|
<?php
|
|
$related_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
|
|
JOIN product_relations pr ON p.id = pr.related_product_id
|
|
WHERE pr.product_id = ?";
|
|
$related_products_stmt = $pdo->prepare($related_sql);
|
|
$related_products_stmt->execute([$product_id]);
|
|
$related_products = $related_products_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if ($related_products) {
|
|
foreach ($related_products as $related_product) {
|
|
$related_image_url = !empty($related_product['image_path'])
|
|
? 'uploads/products/' . htmlspecialchars($related_product['image_path'])
|
|
: 'https://placehold.co/300x300/EEE/31343C?text=Brak+zdj%C4%99cia';
|
|
|
|
echo '<div class="col-md-3 mb-3">';
|
|
echo '<div class="card h-100 product-card shadow-sm">';
|
|
echo '<a href="product.php?id=' . $related_product['id'] . '">';
|
|
echo '<img src="' . $related_image_url . '" class="card-img-top" alt="' . htmlspecialchars($related_product['name']) . '" style="height: 150px; object-fit: cover;">';
|
|
echo '</a>';
|
|
echo '<div class="card-body">';
|
|
echo '<h6 class="card-title"><a href="product.php?id=' . $related_product['id'] . '" class="text-decoration-none text-dark stretched-link">' . htmlspecialchars($related_product['name']) . '</a></h6>';
|
|
echo '</div>';
|
|
echo '</div>';
|
|
echo '</div>';
|
|
}
|
|
} else {
|
|
echo '<p class="mb-0">Brak produktów powiązanych.</p>';
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</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>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const mainImage = document.getElementById('main-product-image');
|
|
const thumbnails = document.querySelectorAll('.product-thumbnail');
|
|
|
|
thumbnails.forEach(thumbnail => {
|
|
thumbnail.addEventListener('click', function(event) {
|
|
event.preventDefault();
|
|
mainImage.src = this.href;
|
|
|
|
thumbnails.forEach(t => t.classList.remove('active'));
|
|
this.classList.add('active');
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|