From 364c512bfbd49168502e7dba4f439491ffe23067 Mon Sep 17 00:00:00 2001 From: Andrea Fiorencis Date: Mon, 13 Apr 2026 13:32:22 +0200 Subject: [PATCH] Implementazione aggiunta prodotto in pagina admin --- src/admin/manageProducts.php | 75 ++++++++++++++++++++++++++++++++++++ src/assets/style.css | 48 +++++++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/src/admin/manageProducts.php b/src/admin/manageProducts.php index 75a64e7..b886971 100644 --- a/src/admin/manageProducts.php +++ b/src/admin/manageProducts.php @@ -59,6 +59,37 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['save'])) { exit(); } +// Gestione aggiunta nuovo prodotto +if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add'])) { + $name = $_POST['name']; + $description = $_POST['description']; + $category_id = $_POST['category_id']; + $price = $_POST['price']; + $stock = $_POST['stock']; + $image_path = ''; + + if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) { + $target_dir = "../img/"; + $image_name = basename($_FILES["image"]["name"]); + $target_file = $target_dir . $image_name; + $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); + if (in_array($imageFileType, ['jpg', 'png', 'jpeg', 'gif'])) { + if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) { + $image_path = $image_name; + } + } + } + + $sql_insert = "INSERT INTO Products (ProductName, Description, CategoryID, Price, StockQuantity, ImagePath) VALUES (?, ?, ?, ?, ?, ?)"; + $stmt_insert = $conn->prepare($sql_insert); + $stmt_insert->bind_param("ssidis", $name, $description, $category_id, $price, $stock, $image_path); + $stmt_insert->execute(); + $stmt_insert->close(); + + header("Location: manageProducts.php"); + exit(); +} + // Ottieni categorie $categories = []; $sql_cat = "SELECT CategoryID, Name FROM Categories"; @@ -91,11 +122,20 @@ $stmt_prod->close(); @@ -126,6 +166,41 @@ $stmt_prod->close();

Gestione Prodotti

+ + diff --git a/src/assets/style.css b/src/assets/style.css index 53457d6..823f33c 100644 --- a/src/assets/style.css +++ b/src/assets/style.css @@ -279,6 +279,54 @@ form button:hover { background-color: #f7f9fb; } +.add-product-panel { + margin-bottom: 24px; + padding: 18px; + border: 1px solid #ddd; + border-radius: 8px; + background-color: #fdfdfd; +} + +.add-product-panel h2 { + margin-top: 0; + margin-bottom: 16px; + color: #333; + font-size: 1.25rem; +} + +.add-product-form { + display: grid; + gap: 16px; +} + +.add-product-form .form-row { + display: grid; + gap: 8px; +} + +.add-product-form label { + font-weight: 600; + color: #444; +} + +.toggle-button { + padding: 10px 16px; + background-color: #17a2b8; + color: #fff; + border: none; + border-radius: 4px; + cursor: pointer; + margin-bottom: 16px; +} + +.toggle-button:hover { + background-color: #117a8b; +} + +.add-product-panel.collapsed { + display: none; +} + .product-name-input, .product-description-textarea, .product-category-select,