added params crud lines
This commit is contained in:
parent
9447f3cf00
commit
329b3ffdeb
42
public/userarea/delete_param.php
Normal file
42
public/userarea/delete_param.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
include('include/headscript.php');
|
||||
|
||||
try {
|
||||
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||||
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid parameter id.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Check existence
|
||||
$stmt = $pdo->prepare("SELECT id FROM production_line_params WHERE id = :id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
|
||||
if (!$stmt->fetchColumn()) {
|
||||
echo json_encode(['success' => false, 'message' => 'Parameter not found.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Delete
|
||||
$del = $pdo->prepare("DELETE FROM production_line_params WHERE id = :id");
|
||||
$del->execute([':id' => $id]);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Parameter deleted successfully.'
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Server error: ' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
42
public/userarea/get_param.php
Normal file
42
public/userarea/get_param.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
include('include/headscript.php');
|
||||
|
||||
try {
|
||||
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||||
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid parameter id.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT id, line_id, position, short_label, label, icon
|
||||
FROM production_line_params
|
||||
WHERE id = :id
|
||||
");
|
||||
$stmt->execute([':id' => $id]);
|
||||
$param = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$param) {
|
||||
echo json_encode(['success' => false, 'message' => 'Parameter not found.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'param' => $param
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Server error: ' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
381
public/userarea/line_params.php
Normal file
381
public/userarea/line_params.php
Normal file
@ -0,0 +1,381 @@
|
||||
<?php
|
||||
include('include/headscript.php');
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Read line id from GET
|
||||
$lineId = isset($_GET['line_id']) ? (int)$_GET['line_id'] : 0;
|
||||
|
||||
if ($lineId <= 0) {
|
||||
die("Invalid line id");
|
||||
}
|
||||
|
||||
// Load line data
|
||||
$stmtLine = $pdo->prepare("SELECT * FROM production_lines WHERE id = :id");
|
||||
$stmtLine->execute([':id' => $lineId]);
|
||||
$line = $stmtLine->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$line) {
|
||||
die("Production line not found");
|
||||
}
|
||||
|
||||
// Load parameters for this line
|
||||
$stmtParams = $pdo->prepare("
|
||||
SELECT *
|
||||
FROM production_line_params
|
||||
WHERE line_id = :line_id
|
||||
ORDER BY position ASC, id ASC
|
||||
");
|
||||
$stmtParams->execute([':line_id' => $lineId]);
|
||||
$params = $stmtParams->fetchAll(PDO::FETCH_ASSOC);
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
|
||||
<?php include('cssinclude.php'); ?>
|
||||
<title>Parametri Linea <?= htmlspecialchars($line['name']) ?> - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
||||
|
||||
<!-- jQuery / Bootstrap / SweetAlert -->
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
|
||||
<!-- DataTables -->
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css">
|
||||
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.min.js"></script>
|
||||
|
||||
<style>
|
||||
body {
|
||||
font-size: 1.05rem;
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.card {
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
th {
|
||||
text-align: center !important;
|
||||
}
|
||||
|
||||
.back-lines {
|
||||
background-color: #cfe3ff !important;
|
||||
color: #1f2d3d !important;
|
||||
border: 1px solid #bcd4f4 !important;
|
||||
border-radius: 10px;
|
||||
font-weight: 600;
|
||||
font-size: 1rem;
|
||||
padding: 10px 18px;
|
||||
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
|
||||
transition: all 0.2s ease-in-out;
|
||||
}
|
||||
|
||||
.back-lines:hover {
|
||||
background-color: #b9d3ff !important;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.btn-add {
|
||||
background-color: #0d6efd;
|
||||
color: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 10px 20px;
|
||||
font-weight: 500;
|
||||
transition: all 0.2s ease-in-out;
|
||||
}
|
||||
|
||||
.btn-add:hover {
|
||||
background-color: #0b5ed7;
|
||||
transform: scale(1.02);
|
||||
}
|
||||
|
||||
.btn-action {
|
||||
border: none;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.btn-action.edit {
|
||||
color: #007bff;
|
||||
}
|
||||
|
||||
.btn-action.delete {
|
||||
color: #dc3545;
|
||||
}
|
||||
|
||||
.btn-action:hover {
|
||||
transform: scale(1.15);
|
||||
}
|
||||
|
||||
.table thead {
|
||||
background-color: #cfe3ff;
|
||||
color: #1f2d3d;
|
||||
}
|
||||
|
||||
.icon-preview i {
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
border-radius: 16px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="wrapper">
|
||||
<?php include('include/navbar.php'); ?>
|
||||
<?php include('include/topbar.php'); ?>
|
||||
|
||||
<div class="page-wrapper">
|
||||
<div class="page-content">
|
||||
<div class="card p-3">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<h5 class="mb-0 w-100 text-center">
|
||||
Parametri Linea: <?= htmlspecialchars($line['name']) ?> (Linea <?= (int)$line['line_number']; ?>)
|
||||
</h5>
|
||||
<button type="button" class="btn back-lines position-absolute end-0 me-3" onclick="location.href='linee.php'">
|
||||
↩️ Torna alle Linee
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<div>
|
||||
<h6 class="fw-semibold mb-0">Elenco Parametri</h6>
|
||||
<small class="text-muted">
|
||||
Linea ID: <?= (int)$line['id']; ?> - Colore:
|
||||
<span style="display:inline-block;width:16px;height:16px;border-radius:4px;border:1px solid #999;background:<?= htmlspecialchars($line['color']); ?>;"></span>
|
||||
</small>
|
||||
</div>
|
||||
<button class="btn btn-add" id="btnAddParam">➕ Aggiungi Parametro</button>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table id="tabellaParametri" class="table table-striped align-middle text-center" style="width:100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Position</th>
|
||||
<th>Short label</th>
|
||||
<th>Label</th>
|
||||
<th>Icon class</th>
|
||||
<th>Preview</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($params)) : ?>
|
||||
<tr>
|
||||
<td colspan="7" class="text-muted">No parameters defined for this line.</td>
|
||||
</tr>
|
||||
<?php else : ?>
|
||||
<?php foreach ($params as $p) : ?>
|
||||
<tr>
|
||||
<td><?= (int)$p['id']; ?></td>
|
||||
<td><?= (int)$p['position']; ?></td>
|
||||
<td><?= htmlspecialchars($p['short_label']); ?></td>
|
||||
<td><?= htmlspecialchars($p['label']); ?></td>
|
||||
<td><?= htmlspecialchars($p['icon']); ?></td>
|
||||
<td class="icon-preview">
|
||||
<?php if (!empty($p['icon'])) : ?>
|
||||
<i class="bi <?= htmlspecialchars($p['icon']); ?>"></i>
|
||||
<?php else : ?>
|
||||
<span class="text-muted">-</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn-action edit"
|
||||
data-id="<?= (int)$p['id']; ?>">
|
||||
<i class="fas fa-edit"></i>
|
||||
</button>
|
||||
<button class="btn-action delete"
|
||||
data-id="<?= (int)$p['id']; ?>">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
|
||||
<!-- ADD/EDIT PARAM MODAL -->
|
||||
<div class="modal fade" id="paramModal" tabindex="-1" aria-labelledby="paramModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header" style="background-color:#cfe3ff;">
|
||||
<h5 class="modal-title" id="paramModalLabel">Add Parameter</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="paramForm">
|
||||
<input type="hidden" name="param_id" id="param_id" value="">
|
||||
<input type="hidden" name="line_id" id="line_id" value="<?= (int)$line['id']; ?>">
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="position" class="form-label fw-semibold">Position (slot)</label>
|
||||
<input type="number" class="form-control" id="position" name="position" required min="1">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="short_label" class="form-label fw-semibold">Short label</label>
|
||||
<input type="text" class="form-control" id="short_label" name="short_label" maxlength="20" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="label" class="form-label fw-semibold">Label</label>
|
||||
<input type="text" class="form-control" id="label" name="label" maxlength="100" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="icon" class="form-label fw-semibold">Bootstrap Icon class (optional)</label>
|
||||
<input type="text" class="form-control" id="icon" name="icon" placeholder="es. bi-thermometer-half">
|
||||
<small class="text-muted">Use a Bootstrap Icons class without the <code>bi</code> prefix (prefix is automatically added in preview).</small>
|
||||
</div>
|
||||
|
||||
<div class="text-center">
|
||||
<button type="submit" class="btn btn-add" id="btnSaveParam">💾 Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include('jsinclude.php'); ?>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
const table = $('#tabellaParametri').DataTable({
|
||||
order: [
|
||||
[1, 'asc']
|
||||
],
|
||||
pageLength: 50,
|
||||
language: {
|
||||
url: 'https://cdn.datatables.net/plug-ins/1.13.6/i18n/it-IT.json'
|
||||
}
|
||||
});
|
||||
|
||||
const paramModal = new bootstrap.Modal(document.getElementById('paramModal'));
|
||||
|
||||
function resetForm() {
|
||||
$('#param_id').val('');
|
||||
$('#position').val('');
|
||||
$('#short_label').val('');
|
||||
$('#label').val('');
|
||||
$('#icon').val('');
|
||||
}
|
||||
|
||||
// Open modal for new parameter
|
||||
$('#btnAddParam').on('click', function() {
|
||||
resetForm();
|
||||
$('#paramModalLabel').text('Add Parameter');
|
||||
$('#btnSaveParam').text('💾 Save');
|
||||
paramModal.show();
|
||||
});
|
||||
|
||||
// Open modal for edit
|
||||
$(document).on('click', '.edit', function() {
|
||||
const id = $(this).data('id');
|
||||
|
||||
fetch('get_param.php?id=' + id)
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
const p = data.param;
|
||||
$('#param_id').val(p.id);
|
||||
$('#line_id').val(p.line_id);
|
||||
$('#position').val(p.position);
|
||||
$('#short_label').val(p.short_label);
|
||||
$('#label').val(p.label);
|
||||
$('#icon').val(p.icon || '');
|
||||
|
||||
$('#paramModalLabel').text('Edit Parameter');
|
||||
$('#btnSaveParam').text('💾 Update');
|
||||
paramModal.show();
|
||||
} else {
|
||||
Swal.fire('Error', data.message || 'Unable to load parameter.', 'error');
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
Swal.fire('Error', 'Server communication error.', 'error');
|
||||
});
|
||||
});
|
||||
|
||||
// Save (add or update)
|
||||
$('#paramForm').on('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const formData = new FormData(this);
|
||||
|
||||
fetch('save_param.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
Swal.fire('Saved', data.message || 'Parameter saved correctly.', 'success')
|
||||
.then(() => {
|
||||
location.reload();
|
||||
});
|
||||
} else {
|
||||
Swal.fire('Error', data.message || 'Error while saving parameter.', 'error');
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
Swal.fire('Error', 'Server communication error.', 'error');
|
||||
});
|
||||
});
|
||||
|
||||
// Delete parameter
|
||||
$(document).on('click', '.delete', function() {
|
||||
const id = $(this).data('id');
|
||||
|
||||
Swal.fire({
|
||||
title: 'Are you sure?',
|
||||
text: 'This action will permanently delete the parameter.',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Yes, delete',
|
||||
cancelButtonText: 'Cancel',
|
||||
confirmButtonColor: '#d33'
|
||||
}).then(result => {
|
||||
if (result.isConfirmed) {
|
||||
fetch('delete_param.php?id=' + id)
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
Swal.fire('Deleted', data.message || 'Parameter deleted.', 'success')
|
||||
.then(() => location.reload());
|
||||
} else {
|
||||
Swal.fire('Error', data.message || 'Error while deleting parameter.', 'error');
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
Swal.fire('Error', 'Server communication error.', 'error');
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -84,6 +84,10 @@
|
||||
color: #128346;
|
||||
}
|
||||
|
||||
.btn-action.params {
|
||||
color: #6f42c1;
|
||||
}
|
||||
|
||||
.btn-action:hover {
|
||||
transform: scale(1.15);
|
||||
}
|
||||
@ -114,7 +118,7 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="wrapper">
|
||||
<div class="wrapper toggled">
|
||||
<?php include('include/navbar.php'); ?>
|
||||
<?php include('include/topbar.php'); ?>
|
||||
|
||||
@ -134,7 +138,7 @@
|
||||
<button class="btn btn-add" data-bs-toggle="modal" data-bs-target="#addLineaModal">➕ Aggiungi Linea</button>
|
||||
</div>
|
||||
|
||||
<!-- TABELLA -->
|
||||
<!-- TABLE -->
|
||||
<div class="table-responsive">
|
||||
<table id="tabellaLinee" class="table table-striped align-middle text-center" style="width:100%;">
|
||||
<thead>
|
||||
@ -156,32 +160,44 @@
|
||||
$stmt = $pdo->query("SELECT * FROM production_lines ORDER BY line_number ASC");
|
||||
|
||||
if ($stmt->rowCount() === 0) {
|
||||
echo "<tr><td colspan='7' class='text-muted'>Nessuna linea di produzione presente</td></tr>";
|
||||
echo "<tr><td colspan='8' class='text-muted'>Nessuna linea di produzione presente</td></tr>";
|
||||
} else {
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$badge = $row['status'] === 'active'
|
||||
? "<span class='badge-active'>Attiva</span>"
|
||||
: "<span class='badge-inactive'>Inattiva</span>";
|
||||
|
||||
$lineNameEsc = htmlspecialchars($row['name'], ENT_QUOTES, 'UTF-8');
|
||||
|
||||
echo "<tr>
|
||||
<td>{$row['id']}</td>
|
||||
<td>{$row['line_number']}</td>
|
||||
<td>" . htmlspecialchars($row['name']) . "</td>
|
||||
<td>{$lineNameEsc}</td>
|
||||
<td>" . htmlspecialchars($row['model']) . "</td>
|
||||
<td>" . htmlspecialchars($row['brand']) . "</td>
|
||||
|
||||
<td>
|
||||
<div style='width:28px; height:28px; border-radius:6px; border:1px solid #999; background: {$row['color']}; margin:auto;'></div>
|
||||
</td>
|
||||
|
||||
<td>{$badge}</td>
|
||||
<td>
|
||||
|
||||
<button class='btn-action edit' title='Modifica' data-id='{$row['id']}'><i class='fas fa-edit'></i></button>
|
||||
<button class='btn-action delete' title='Elimina' data-id='{$row['id']}'><i class='fas fa-trash'></i></button>
|
||||
<button class='btn-action toggle' title='Cambia stato' data-id='{$row['id']}' data-status='{$row['status']}'><i class='fas fa-power-off'></i></button>
|
||||
</td>
|
||||
</tr>";
|
||||
<button class='btn-action params' title='Parametri linea'
|
||||
data-id='{$row['id']}'
|
||||
data-name='{$lineNameEsc}'>
|
||||
<i class='fas fa-sliders-h'></i>
|
||||
</button>
|
||||
<button class='btn-action edit' title='Modifica' data-id='{$row['id']}'>
|
||||
<i class='fas fa-edit'></i>
|
||||
</button>
|
||||
<button class='btn-action delete' title='Elimina' data-id='{$row['id']}'>
|
||||
<i class='fas fa-trash'></i>
|
||||
</button>
|
||||
<button class='btn-action toggle' title='Cambia stato'
|
||||
data-id='{$row['id']}'
|
||||
data-status='{$row['status']}'>
|
||||
<i class='fas fa-power-off'></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -196,7 +212,7 @@
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
|
||||
<!-- MODALE AGGIUNTA LINEA -->
|
||||
<!-- ADD LINE MODAL -->
|
||||
<div class="modal fade" id="addLineaModal" tabindex="-1" aria-labelledby="addLineaLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
@ -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");
|
||||
|
||||
@ -273,6 +273,7 @@
|
||||
order: [
|
||||
[0, 'desc']
|
||||
],
|
||||
pageLength: 50,
|
||||
language: {
|
||||
url: 'https://cdn.datatables.net/plug-ins/1.13.6/i18n/it-IT.json'
|
||||
}
|
||||
|
||||
102
public/userarea/save_param.php
Normal file
102
public/userarea/save_param.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
include('include/headscript.php');
|
||||
|
||||
try {
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
echo json_encode(['success' => 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()
|
||||
]);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user