add product addition functionality with category selection and attribute handling
This commit is contained in:
parent
797febafe0
commit
eb088ab7e5
10
account.php
10
account.php
@ -88,6 +88,9 @@ include 'header.php';
|
||||
<?php if (isset($_GET['upload']) && $_GET['upload'] === 'err'): ?>
|
||||
<p class="auth__alert__error" role="alert">Upload fehlgeschlagen. Bitte eine gültige Bilddatei auswählen.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="auth__card">
|
||||
|
||||
<form class="auth__form" action="upload.php" method="post" enctype="multipart/form-data">
|
||||
<div class="auth__field">
|
||||
@ -101,6 +104,13 @@ include 'header.php';
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="auth__card">
|
||||
<form>
|
||||
<a href="productAdder.php" class="auth__actions"> <br>
|
||||
<button class="auth__submit" type="button"">Produkt hinzufügen</button>
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
|
||||
@ -185,30 +185,28 @@
|
||||
box-shadow: var(--gh-focus);
|
||||
}
|
||||
|
||||
/* Leicht dezenter Hinweistext unter Feldern (z.B. Upload) */
|
||||
.auth__hint {
|
||||
margin: 8px 0 0;
|
||||
font-size: 0.9rem;
|
||||
color: rgba(255, 255, 255, 0.75);
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
/* Optional: File-Button im Input anfarblich etwas angleichen (Browser support variiert) */
|
||||
.auth__field input[type="file"]::file-selector-button {
|
||||
margin-right: 10px;
|
||||
padding: 10px 12px;
|
||||
border: 0;
|
||||
border-radius: 5px;
|
||||
background: rgba(39, 74, 151, 0.35);
|
||||
background: var(--gh-primary);
|
||||
color: #ffffff;
|
||||
font-weight: 700;
|
||||
font-weight: 750;
|
||||
cursor: pointer;
|
||||
transition: transform 120ms ease, filter 120ms ease;
|
||||
}
|
||||
|
||||
.auth__field input[type="file"]::file-selector-button:hover {
|
||||
background: rgba(39, 74, 151, 0.5);
|
||||
filter: brightness(1.02);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.auth__field input[type="file"]::file-selector-button:active {
|
||||
transform: translateY(0px);
|
||||
}
|
||||
|
||||
|
||||
.auth__actions {
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
128
assets/css/productAdder.css
Normal file
128
assets/css/productAdder.css
Normal file
@ -0,0 +1,128 @@
|
||||
/* assets/css/productAdder.css
|
||||
Dropdown-Styles fuer productAdder.php
|
||||
*/
|
||||
|
||||
.auth__select__wrap {
|
||||
width: min(520px, 100%);
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
justify-self: center;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.auth__select__label {
|
||||
font-size: 0.95rem;
|
||||
color: var(--gh-muted);
|
||||
}
|
||||
|
||||
.auth__select {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
padding: 12px 40px 12px 12px;
|
||||
border: 1px solid var(--gh-border);
|
||||
border-radius: 5px;
|
||||
background-color: #1e2537;
|
||||
color: var(--gh-text);
|
||||
outline: none;
|
||||
appearance: none;
|
||||
transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
|
||||
background-image:
|
||||
linear-gradient(45deg, transparent 50%, #cbd5f5 50%),
|
||||
linear-gradient(135deg, #cbd5f5 50%, transparent 50%),
|
||||
linear-gradient(to right, #1e2537, #1e2537);
|
||||
background-position:
|
||||
calc(100% - 18px) calc(1em + 2px),
|
||||
calc(100% - 13px) calc(1em + 2px),
|
||||
100% 0;
|
||||
background-size: 5px 5px, 5px 5px, 2.5em 100%;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
.auth__select:focus {
|
||||
border-color: rgba(37, 99, 235, 0.75);
|
||||
box-shadow: var(--gh-focus);
|
||||
}
|
||||
|
||||
.auth__select option {
|
||||
background: #1e2537;
|
||||
color: var(--gh-text);
|
||||
}
|
||||
|
||||
.auth {
|
||||
min-height: 100vh;
|
||||
display: grid;
|
||||
place-items: start center;
|
||||
padding: 32px 16px;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.auth__grid {
|
||||
width: min(1100px, 100%);
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.auth__card {
|
||||
background: #1f2937;
|
||||
border: 1px solid var(--gh-border);
|
||||
border-radius: 5px;
|
||||
padding: 18px;
|
||||
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.auth__header {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.auth__title {
|
||||
margin: 0;
|
||||
font-size: 1.1rem;
|
||||
color: var(--gh-text);
|
||||
}
|
||||
|
||||
.auth__form {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.auth__form label {
|
||||
font-size: 0.95rem;
|
||||
color: var(--gh-muted);
|
||||
}
|
||||
|
||||
.auth__input {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid var(--gh-border);
|
||||
border-radius: 5px;
|
||||
background: #1e2537;
|
||||
color: var(--gh-text);
|
||||
outline: none;
|
||||
transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
|
||||
}
|
||||
|
||||
.auth__input:focus {
|
||||
border-color: rgba(37, 99, 235, 0.75);
|
||||
box-shadow: var(--gh-focus);
|
||||
}
|
||||
|
||||
.auth__input::placeholder {
|
||||
color: var(--gh-muted);
|
||||
}
|
||||
|
||||
.auth__card .auth__form:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.auth {
|
||||
padding: 24px 12px;
|
||||
}
|
||||
|
||||
.auth__card {
|
||||
padding: 16px;
|
||||
}
|
||||
}
|
||||
196
productAdder.php
Normal file
196
productAdder.php
Normal file
@ -0,0 +1,196 @@
|
||||
<?php
|
||||
// product_add.php
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
session_start();
|
||||
|
||||
/* =======================
|
||||
1) Kategorie aus GET
|
||||
======================= */
|
||||
$categoryID = 0;
|
||||
if (isset($_GET['categoryID']) && ctype_digit($_GET['categoryID'])) {
|
||||
$categoryID = (int)$_GET['categoryID'];
|
||||
}
|
||||
|
||||
/* =======================
|
||||
2) DB-Verbindung
|
||||
======================= */
|
||||
$conn = new mysqli("localhost", "FSST", "L9wUNZZ9Qkbt", "FSST", 3306);
|
||||
if ($conn->connect_error) {
|
||||
die("Datenbankfehler");
|
||||
}
|
||||
|
||||
/* =======================
|
||||
3) Kategorien laden
|
||||
======================= */
|
||||
$categories = [];
|
||||
$result = $conn->query("
|
||||
SELECT categoryID, name
|
||||
FROM categories
|
||||
ORDER BY name
|
||||
");
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$categories[] = $row;
|
||||
}
|
||||
|
||||
/* =======================
|
||||
4) Attribute zur Kategorie
|
||||
======================= */
|
||||
$attributes = [];
|
||||
if ($categoryID > 0) {
|
||||
$stmt = $conn->prepare("
|
||||
SELECT a.attributeID, a.name, a.unit, a.dataType
|
||||
FROM categoryAttributes ca
|
||||
JOIN attributes a ON a.attributeID = ca.attributeID
|
||||
WHERE ca.categoryID = ?
|
||||
ORDER BY a.name
|
||||
");
|
||||
$stmt->bind_param("i", $categoryID);
|
||||
$stmt->execute();
|
||||
$res = $stmt->get_result();
|
||||
while ($row = $res->fetch_assoc()) {
|
||||
$attributes[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
/* =======================
|
||||
5) Produkt speichern
|
||||
======================= */
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['saveProduct'])) {
|
||||
|
||||
$model = trim($_POST['model']);
|
||||
$description = $_POST['description'] ?? null;
|
||||
$categoryID = (int)$_POST['categoryID'];
|
||||
|
||||
// --- Produkt anlegen ---
|
||||
$stmt = $conn->prepare("
|
||||
INSERT INTO products (categoryID, model, description)
|
||||
VALUES (?, ?, ?)
|
||||
");
|
||||
$stmt->bind_param("iss", $categoryID, $model, $description);
|
||||
$stmt->execute();
|
||||
|
||||
$productID = $stmt->insert_id;
|
||||
|
||||
// --- Attribute speichern ---
|
||||
if (!empty($_POST['attributes'])) {
|
||||
|
||||
$stmtAttr = $conn->prepare("
|
||||
INSERT INTO productAttributes
|
||||
(productID, attributeID, valueString, valueNumber, valueBool)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
");
|
||||
|
||||
foreach ($_POST['attributes'] as $attributeID => $value) {
|
||||
|
||||
if ($value === '' || $value === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$valueString = null;
|
||||
$valueNumber = null;
|
||||
$valueBool = null;
|
||||
|
||||
if (is_numeric($value)) {
|
||||
$valueNumber = $value;
|
||||
} elseif ($value === '0' || $value === '1') {
|
||||
$valueBool = (int)$value;
|
||||
} else {
|
||||
$valueString = trim($value);
|
||||
}
|
||||
|
||||
$stmtAttr->bind_param(
|
||||
"iisdi",
|
||||
$productID,
|
||||
$attributeID,
|
||||
$valueString,
|
||||
$valueNumber,
|
||||
$valueBool
|
||||
);
|
||||
$stmtAttr->execute();
|
||||
}
|
||||
}
|
||||
|
||||
header("Location: product_add.php?categoryID=" . $categoryID);
|
||||
exit;
|
||||
}
|
||||
|
||||
include 'header.php';
|
||||
?>
|
||||
|
||||
<link rel="stylesheet" href="assets/css/login.css">
|
||||
<link rel="stylesheet" href="assets/css/productAdder.css">
|
||||
|
||||
<main class="auth">
|
||||
<section class="auth__grid">
|
||||
|
||||
<!-- Kategorie waehlen -->
|
||||
<div class="auth__card">
|
||||
<header class="auth__header">
|
||||
<h2 class="auth__title">Kategorie waehlen</h2>
|
||||
</header>
|
||||
<form method="get" class="auth__form">
|
||||
<div class="auth__select__wrap">
|
||||
<label class="auth__select__label" for="categoryID">Kategorie</label>
|
||||
<select id="categoryID" name="categoryID" class="auth__select" onchange="this.form.submit()" required>
|
||||
<option value="">Kategorie waehlen</option>
|
||||
<?php foreach ($categories as $cat): ?>
|
||||
<option value="<?= $cat['categoryID'] ?>"
|
||||
<?= $cat['categoryID'] === $categoryID ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars($cat['name']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Produkt anlegen -->
|
||||
<?php if ($categoryID > 0): ?>
|
||||
<div class="auth__card">
|
||||
<header class="auth__header">
|
||||
<h2 class="auth__title">Produkt hinzufuegen</h2>
|
||||
</header>
|
||||
|
||||
<form method="post" class="auth__form">
|
||||
<input type="hidden" name="categoryID" value="<?= $categoryID ?>">
|
||||
|
||||
<label for="model">Modell</label>
|
||||
<input id="model" type="text" name="model" class="auth__input" required>
|
||||
|
||||
<label for="description">Beschreibung</label>
|
||||
<textarea id="description" name="description" class="auth__input"></textarea>
|
||||
|
||||
<h3 class="auth__title">Attribute</h3>
|
||||
|
||||
<?php foreach ($attributes as $attr): ?>
|
||||
<label>
|
||||
<?= htmlspecialchars($attr['name']) ?>
|
||||
<?php if ($attr['unit']): ?>
|
||||
(<?= htmlspecialchars($attr['unit']) ?>)
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
|
||||
<input
|
||||
type="<?= $attr['dataType'] === 'number' ? 'number' : 'text' ?>"
|
||||
name="attributes[<?= $attr['attributeID'] ?>]"
|
||||
class="auth__input"
|
||||
>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<button type="submit" name="saveProduct" class="auth__input">
|
||||
Produkt speichern
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<?php
|
||||
$conn->close();
|
||||
include 'footer.php';
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user