diff --git a/src/admin/index.php b/src/admin/index.php
index 332c703..a3a8ae5 100644
--- a/src/admin/index.php
+++ b/src/admin/index.php
@@ -81,7 +81,7 @@ if ($result_total_products) {
Gestione ordini
Gestione prodotti
Gestione utenti
-
+
Ritorna al tuo account
diff --git a/src/admin/manageOrders.php b/src/admin/manageOrders.php
index 4a293dd..cd087d6 100644
--- a/src/admin/manageOrders.php
+++ b/src/admin/manageOrders.php
@@ -101,7 +101,7 @@ if ($result === false) {
Gestione ordini
Gestione prodotti
Gestione utenti
-
+
Ritorna al tuo account
diff --git a/src/admin/manageProducts.php b/src/admin/manageProducts.php
index 354b686..b886971 100644
--- a/src/admin/manageProducts.php
+++ b/src/admin/manageProducts.php
@@ -22,6 +22,95 @@ if ($role !== 'admin') {
http_response_code(403);
die("Accesso negato. Solo gli amministratori possono accedere a questa sezione.");
}
+
+// Gestione aggiornamenti
+if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['save'])) {
+ $product_id = $_POST['product_id'];
+ $name = $_POST['name'];
+ $description = $_POST['description'];
+ $category_id = $_POST['category_id'];
+ $price = $_POST['price'];
+ $stock = $_POST['stock'];
+
+ // Gestione immagine
+ $image_path = basename($_POST['current_image']);
+ 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));
+ // Controlli base
+ if (in_array($imageFileType, ['jpg', 'png', 'jpeg', 'gif'])) {
+ if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) {
+ $image_path = $image_name;
+ }
+ }
+ }
+
+ // Update DB
+ $sql_update = "UPDATE Products SET ProductName = ?, Description = ?, CategoryID = ?, Price = ?, StockQuantity = ?, ImagePath = ? WHERE ProductID = ?";
+ $stmt_update = $conn->prepare($sql_update);
+ $stmt_update->bind_param("ssidisi", $name, $description, $category_id, $price, $stock, $image_path, $product_id);
+ $stmt_update->execute();
+ $stmt_update->close();
+
+ // Redirect
+ header("Location: manageProducts.php");
+ 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";
+$stmt_cat = $conn->prepare($sql_cat);
+$stmt_cat->execute();
+$result_cat = $stmt_cat->get_result();
+while ($row = $result_cat->fetch_assoc()) {
+ $categories[] = $row;
+}
+$stmt_cat->close();
+
+// Ottieni prodotti
+$products = [];
+$sql_prod = "SELECT ProductID, ProductName, Description, Price, StockQuantity, ImagePath, CategoryID FROM Products";
+$stmt_prod = $conn->prepare($sql_prod);
+$stmt_prod->execute();
+$result_prod = $stmt_prod->get_result();
+while ($row = $result_prod->fetch_assoc()) {
+ $products[] = $row;
+}
+$stmt_prod->close();
?>
@@ -32,6 +121,22 @@ if ($role !== 'admin') {
Gestione Prodotti - TechStore
+
@@ -55,13 +160,96 @@ if ($role !== 'admin') {
Gestione ordini
Gestione prodotti
Gestione utenti
-
+
Ritorna al tuo account
-
Gestione prodotti
-
WIP
+
Gestione Prodotti
+
+
+ Aggiungi nuovo prodotto
+
+
+
diff --git a/src/admin/manageUsers.php b/src/admin/manageUsers.php
index 5a100a2..153a6d9 100644
--- a/src/admin/manageUsers.php
+++ b/src/admin/manageUsers.php
@@ -106,7 +106,7 @@ if ($result === false) {
Gestione ordini
Gestione prodotti
Gestione utenti
-
+
Ritorna al tuo account
diff --git a/src/assets/style.css b/src/assets/style.css
index 31af370..823f33c 100644
--- a/src/assets/style.css
+++ b/src/assets/style.css
@@ -256,6 +256,149 @@ form button:hover {
padding: 20px;
}
+.product-table {
+ width: 100%;
+ border-collapse: collapse;
+ margin-top: 20px;
+}
+
+.product-table th,
+.product-table td {
+ border: 1px solid #ddd;
+ padding: 12px;
+ vertical-align: top;
+}
+
+.product-table th {
+ background-color: #f8f9fa;
+ font-weight: 700;
+ text-align: left;
+}
+
+.product-row: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,
+.product-price-input,
+.stock-input,
+.product-image-input {
+ width: 100%;
+ padding: 10px;
+ border: 1px solid #ccc;
+ border-radius: 4px;
+ box-sizing: border-box;
+}
+
+.product-description-textarea {
+ min-height: 80px;
+ resize: vertical;
+}
+
+.stock-control {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+}
+
+.stock-button {
+ width: 32px;
+ height: 32px;
+ border: none;
+ border-radius: 4px;
+ background-color: #007bff;
+ color: #fff;
+ cursor: pointer;
+}
+
+.stock-button:hover {
+ background-color: #0056b3;
+}
+
+.product-image-preview {
+ max-width: 100px;
+ display: block;
+ margin-bottom: 8px;
+}
+
+.image-upload {
+ display: flex;
+ flex-direction: column;
+ gap: 8px;
+}
+
+.save-button {
+ padding: 10px 16px;
+ background-color: #28a745;
+ color: #fff;
+ border: none;
+ border-radius: 4px;
+ cursor: pointer;
+}
+
+.save-button:hover {
+ background-color: #218838;
+}
+
+.admin-divider{
+ display: block;
+ height: 1px;
+ border: 0;
+ border-top: 1px solid #ddd;
+ margin: 1em 0;
+ padding: 0;
+}
+
.admin-stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));