@@ -250,7 +266,7 @@
}
});
- // â Aggiungi linea
+ // â Add line
$("#addLineaForm").on("submit", function(e) {
e.preventDefault();
const formData = new FormData(this);
@@ -271,13 +287,19 @@
.catch(() => Swal.fire("Errore", "Impossibile contattare il server.", "error"));
});
- // âī¸ Modifica
+ // âī¸ Edit line
$(document).on("click", ".edit", function() {
const id = $(this).data("id");
location.href = "edit_linea.php?id=" + id;
});
- // đī¸ Elimina
+ // đ§Š Parameters management
+ $(document).on("click", ".params", function() {
+ const id = $(this).data("id");
+ location.href = "line_params.php?line_id=" + id;
+ });
+
+ // đī¸ Delete line
$(document).on("click", ".delete", function() {
const id = $(this).data("id");
Swal.fire({
@@ -304,7 +326,7 @@
});
});
- // đ Toggle stato
+ // đ Toggle status
$(document).on("click", ".toggle", function() {
const id = $(this).data("id");
const currentStatus = $(this).data("status");
diff --git a/public/userarea/matrici.php b/public/userarea/matrici.php
index f8e36c4..458aa1e 100644
--- a/public/userarea/matrici.php
+++ b/public/userarea/matrici.php
@@ -273,6 +273,7 @@
order: [
[0, 'desc']
],
+ pageLength: 50,
language: {
url: 'https://cdn.datatables.net/plug-ins/1.13.6/i18n/it-IT.json'
}
diff --git a/public/userarea/save_param.php b/public/userarea/save_param.php
new file mode 100644
index 0000000..8c8bd71
--- /dev/null
+++ b/public/userarea/save_param.php
@@ -0,0 +1,102 @@
+ false, 'message' => 'Invalid request method.']);
+ exit;
+ }
+
+ $db = DBHandlerSelect::getInstance();
+ $pdo = $db->getConnection();
+
+ $paramId = isset($_POST['param_id']) ? (int)$_POST['param_id'] : 0;
+ $lineId = isset($_POST['line_id']) ? (int)$_POST['line_id'] : 0;
+ $position = isset($_POST['position']) ? (int)$_POST['position'] : 0;
+ $shortLabel = isset($_POST['short_label']) ? trim($_POST['short_label']) : '';
+ $label = isset($_POST['label']) ? trim($_POST['label']) : '';
+ $icon = isset($_POST['icon']) ? trim($_POST['icon']) : '';
+
+ if ($lineId <= 0) {
+ echo json_encode(['success' => false, 'message' => 'Invalid line ID.']);
+ exit;
+ }
+
+ if ($position <= 0) {
+ echo json_encode(['success' => false, 'message' => 'Position must be greater than zero.']);
+ exit;
+ }
+
+ if ($shortLabel === '' || $label === '') {
+ echo json_encode(['success' => false, 'message' => 'Short label and label are required.']);
+ exit;
+ }
+
+ // Check that line exists
+ $stmtLine = $pdo->prepare("SELECT id FROM production_lines WHERE id = :id");
+ $stmtLine->execute([':id' => $lineId]);
+ if (!$stmtLine->fetchColumn()) {
+ echo json_encode(['success' => false, 'message' => 'Production line not found.']);
+ exit;
+ }
+
+ if ($paramId > 0) {
+ // Update
+ $sql = "
+ UPDATE production_line_params
+ SET line_id = :line_id,
+ position = :position,
+ short_label = :short_label,
+ label = :label,
+ icon = :icon
+ WHERE id = :id
+ ";
+ $stmt = $pdo->prepare($sql);
+ $stmt->execute([
+ ':line_id' => $lineId,
+ ':position' => $position,
+ ':short_label' => $shortLabel,
+ ':label' => $label,
+ ':icon' => ($icon !== '' ? $icon : null),
+ ':id' => $paramId,
+ ]);
+
+ echo json_encode([
+ 'success' => true,
+ 'message' => 'Parameter updated successfully.',
+ 'id' => $paramId
+ ]);
+ } else {
+ // Insert
+ $sql = "
+ INSERT INTO production_line_params (line_id, position, short_label, label, icon)
+ VALUES (:line_id, :position, :short_label, :label, :icon)
+ ";
+ $stmt = $pdo->prepare($sql);
+ $stmt->execute([
+ ':line_id' => $lineId,
+ ':position' => $position,
+ ':short_label' => $shortLabel,
+ ':label' => $label,
+ ':icon' => ($icon !== '' ? $icon : null),
+ ]);
+
+ $newId = (int)$pdo->lastInsertId();
+
+ echo json_encode([
+ 'success' => true,
+ 'message' => 'Parameter created successfully.',
+ 'id' => $newId
+ ]);
+ }
+} catch (Exception $e) {
+ echo json_encode([
+ 'success' => false,
+ 'message' => 'Server error: ' . $e->getMessage()
+ ]);
+}