240 lines
6.3 KiB
PHP
240 lines
6.3 KiB
PHP
<?php include 'header.php'; ?>
|
||
|
||
<?php
|
||
// login.php
|
||
|
||
ini_set('display_errors', 1);
|
||
ini_set('display_startup_errors', 1);
|
||
error_reporting(E_ALL);
|
||
|
||
session_start();
|
||
|
||
// 1) DB-Verbindung (einmal)
|
||
$servername = "localhost";
|
||
$port = 3306;
|
||
$username = "FSST";
|
||
$password = "L9wUNZZ9Qkbt";
|
||
$db = "FSST";
|
||
|
||
$conn = mysqli_connect($servername, $username, $password, $db, $port);
|
||
if (!$conn)
|
||
{
|
||
http_response_code(500);
|
||
die("Datenbankfehler");
|
||
}
|
||
?>
|
||
|
||
<?php
|
||
$productId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||
?>
|
||
|
||
<?php if ($productId <= 0): ?>
|
||
<section class="product-section">
|
||
<h2>Produkt nicht gefunden</h2>
|
||
<p>Bitte eine gueltige Produkt-ID mitgeben.</p>
|
||
</section>
|
||
|
||
<?php else: ?>
|
||
<?php
|
||
$stmt = $conn->prepare("
|
||
SELECT
|
||
a.name,
|
||
a.unit,
|
||
a.dataType,
|
||
pa.valueString,
|
||
pa.valueNumber,
|
||
pa.valueBool,
|
||
p.model,
|
||
p.description,
|
||
p.imagePath
|
||
FROM products p
|
||
|
||
INNER JOIN categoryAttributes ca
|
||
ON p.categoryID = ca.categoryID
|
||
|
||
INNER JOIN attributes a
|
||
ON ca.attributeID = a.attributeID
|
||
|
||
LEFT JOIN productAttributes pa
|
||
ON pa.productID = p.productID
|
||
AND pa.attributeID = a.attributeID
|
||
|
||
WHERE p.productID = ?
|
||
|
||
ORDER BY a.attributeID
|
||
");
|
||
|
||
|
||
$stmt->bind_param("i", $productId);
|
||
$stmt->execute();
|
||
|
||
$result = $stmt->get_result();
|
||
$product = $result->fetch_assoc();
|
||
?>
|
||
|
||
<?php
|
||
$alreadyInWishlist = null;
|
||
|
||
if (
|
||
$_SERVER['REQUEST_METHOD'] === 'POST' &&
|
||
isset($_POST['add_wishlist']) &&
|
||
isset($_SESSION['user_id'])
|
||
) {
|
||
|
||
$userId = (int)$_SESSION['user_id'];
|
||
$productIdPost = (int)$_POST['product_id'];
|
||
|
||
if ($productIdPost > 0 && $alreadyInWishlist == null) {
|
||
|
||
$stmtFav = mysqli_prepare(
|
||
$conn,
|
||
"INSERT IGNORE INTO userFavorites (productID, userID) VALUES (?, ?)"
|
||
);
|
||
|
||
if ($stmtFav) {
|
||
mysqli_stmt_bind_param($stmtFav, 'ii', $productIdPost, $userId);
|
||
mysqli_stmt_execute($stmtFav);
|
||
mysqli_stmt_close($stmtFav);
|
||
$alreadyInWishlist = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
?>
|
||
|
||
<div class="product-wrapper">
|
||
<!-- LINKER BEREICH – BILD -->
|
||
<div class="product-left">
|
||
<div class="product-image-box">
|
||
<img
|
||
src="<?= isset($product['imagePath']) ? $product['imagePath'] : 'assets/images/placeholder.png' ?>"
|
||
alt="<?= htmlspecialchars($product['model'] ?? 'Produktbild') ?>">
|
||
</div>
|
||
<?php if (isset($_SESSION['user_id'])): ?>
|
||
|
||
<?php if ($alreadyInWishlist): ?>
|
||
|
||
<div class="auth__actions">
|
||
<input class="auth__submit" type="button"
|
||
value="Bereits in Wunschliste"
|
||
disabled>
|
||
</div>
|
||
|
||
<?php else: ?>
|
||
|
||
<form method="POST">
|
||
<input type="hidden" name="product_id" value="<?= (int)$productId ?>">
|
||
<input type="hidden" name="add_wishlist" value="1">
|
||
|
||
<div class="auth__actions">
|
||
<input class="auth__submit"
|
||
type="submit"
|
||
value="Zur Wunschliste hinzufügen">
|
||
</div>
|
||
</form>
|
||
|
||
<?php endif; ?>
|
||
|
||
<?php else: ?>
|
||
|
||
<div class="auth__actions">
|
||
<a href="login.php">
|
||
<input class="auth__submit" type="button"
|
||
value="Zum Hinzufügen einloggen">
|
||
</a>
|
||
</div>
|
||
|
||
<?php endif; ?>
|
||
|
||
|
||
</div>
|
||
|
||
<!-- RECHTER BEREICH – DETAILS -->
|
||
<div class="product-right">
|
||
|
||
<h1 class="product-title">
|
||
<?= htmlspecialchars($product['model'] ?? 'Produkt') ?>
|
||
</h1>
|
||
|
||
<div class="product-specs">
|
||
|
||
<div class="product-desc">
|
||
<?= htmlspecialchars($product['description']) ?>
|
||
</div>
|
||
|
||
|
||
<?php
|
||
while ($row = $result->fetch_assoc()) {
|
||
|
||
echo "<p><strong>{$row['name']}:</strong> ";
|
||
|
||
if (!empty($row['valueString'])) echo $row['valueString'];
|
||
if (!empty($row['valueNumber'])) echo $row['valueNumber'] . " " . $row['unit'];
|
||
if (!is_null($row['valueBool'])) echo $row['valueBool'] ? "Ja" : "Nein";
|
||
|
||
echo "</p>";
|
||
}
|
||
?>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<?php
|
||
$stmt = mysqli_prepare($conn,
|
||
"SELECT price, shippingCost, inStock, shops.name, shops.website
|
||
FROM offers
|
||
INNER JOIN shops ON
|
||
offers.shopID = shops.shopID WHERE offers.productID = ?");
|
||
|
||
$stmt->bind_param("i", $productId);
|
||
$stmt->execute();
|
||
$result = $stmt->get_result();
|
||
|
||
$shopInfo = [];
|
||
|
||
while ($row = $result->fetch_assoc()) {
|
||
$shopInfo[] = $row;
|
||
}
|
||
|
||
|
||
|
||
?>
|
||
|
||
<div class="shop-offers">
|
||
|
||
<?php if (!empty($shopInfo)): ?>
|
||
|
||
<?php foreach ($shopInfo as $shop): ?>
|
||
|
||
<div class="shop-line">
|
||
<a href="<?= htmlspecialchars($shop['website']) ?>" target="_blank">
|
||
<?= htmlspecialchars($shop['name']) ?>
|
||
</a><br>
|
||
|
||
Preis: <?= htmlspecialchars($shop['price']) ?> € <br>
|
||
Versand: <?= htmlspecialchars($shop['shippingCost']) ?> € <br>
|
||
Lagernd: <?= $shop['inStock'] ? "Ja" : "Nein" ?>
|
||
</div>
|
||
|
||
<?php endforeach; ?>
|
||
|
||
<?php else: ?>
|
||
<p>Keine Shops bieten dieses Produkt an.</p>
|
||
<?php endif; ?>
|
||
|
||
</div>
|
||
|
||
<?php $stmt->close(); ?>
|
||
|
||
<?php endif; ?>
|
||
|
||
|
||
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
||
<link rel="stylesheet" href="assets/css/productpage.css">
|
||
</head>
|
||
|
||
<?php include 'footer.php'; ?>
|