fixed errors

This commit is contained in:
2026-10-06 11:59:02 +02:00
parent 764cdade18
commit ea33db6c48
2 changed files with 69 additions and 2 deletions
+39 -1
View File
@@ -146,6 +146,10 @@ $rowsData = $stmt->fetchAll(PDO::FETCH_ASSOC);
background: #fd7e14;
}
.btn-delete {
background: #dc3545;
}
.pager-bar {
display: flex;
align-items: center;
@@ -232,7 +236,7 @@ $rowsData = $stmt->fetchAll(PDO::FETCH_ASSOC);
<table class="err-table">
<thead>
<tr>
<th style="width:170px;">Azioni</th>
<th style="width:210px;">Azioni</th>
<th>Status</th>
<th>Client</th>
<th>Errore</th>
@@ -250,6 +254,7 @@ $rowsData = $stmt->fetchAll(PDO::FETCH_ASSOC);
<a href="download_logs.php?iddatadb=<?= (int)$row['iddatadb'] ?>" class="action-btn btn-log" title="Scarica log"><i class="fas fa-file-download"></i></a>
<?php endif; ?>
<button type="button" class="action-btn btn-revert revert-btn" data-iddatadb="<?= (int)$row['iddatadb'] ?>" title="Riporta a Imported"><i class="fas fa-rotate-left"></i></button>
<button type="button" class="action-btn btn-delete delete-btn" data-iddatadb="<?= (int)$row['iddatadb'] ?>" title="Elimina record"><i class="fas fa-trash"></i></button>
</td>
<td>
<span class="status-badge status-x">Error</span>
@@ -331,6 +336,39 @@ $rowsData = $stmt->fetchAll(PDO::FETCH_ASSOC);
});
});
// Elimina record
$(document).on('click', '.delete-btn', function() {
const $btn = $(this);
const iddatadb = $btn.data('iddatadb');
if (!confirm('Eliminare definitivamente questo record? L\'operazione non è reversibile.')) return;
const original = $btn.html();
$btn.prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i>');
$.ajax({
url: 'revert_status.php',
method: 'POST',
dataType: 'json',
data: {
iddatadb: iddatadb,
action: 'delete'
},
success: function(res) {
if (res && res.success) {
const $tr = $('tr[data-id="' + iddatadb + '"]');
$tr.fadeOut(300, () => $tr.remove());
} else {
alert('Errore: ' + ((res && res.message) ? res.message : 'cancellazione non riuscita'));
$btn.prop('disabled', false).html(original);
}
},
error: function() {
alert('Errore di rete.');
$btn.prop('disabled', false).html(original);
}
});
});
// Revert a Imported (i)
$(document).on('click', '.revert-btn', function() {
const $btn = $(this);
+30 -1
View File
@@ -8,12 +8,41 @@ header('Content-Type: application/json');
$iddatadb = (int)($_POST['iddatadb'] ?? 0);
$newStatus = $_POST['status'] ?? 'i';
$action = $_POST['action'] ?? 'revert';
if ($iddatadb <= 0) {
echo json_encode(['success' => false, 'message' => 'ID record mancante']);
exit;
}
// Cancellazione record (consentita solo da stato 'i' o 'x')
if ($action === 'delete') {
try {
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
$stmt = $pdo->prepare("DELETE FROM datadb WHERE iddatadb = ? AND status IN ('i', 'x')");
$stmt->execute([$iddatadb]);
if ($stmt->rowCount() > 0) {
echo json_encode(['success' => true]);
} else {
$chk = $pdo->prepare("SELECT status FROM datadb WHERE iddatadb = ?");
$chk->execute([$iddatadb]);
$current = $chk->fetchColumn();
if ($current === false) {
echo json_encode(['success' => false, 'message' => 'Record non trovato']);
} else {
echo json_encode(['success' => false, 'message' => "Cancellazione non consentita: stato attuale '$current'"]);
}
}
} catch (Throwable $e) {
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
exit;
}
// Da questa azione consentiamo solo il ritorno a 'i'
if ($newStatus !== 'i') {
echo json_encode(['success' => false, 'message' => 'Stato non consentito']);
@@ -28,7 +57,7 @@ try {
// Azzera idcommessaweb: il revert è una scelta esplicita di riesportare, altrimenti il
// CHECK PRELIMINARE di export_to_lims.php riallineerebbe la riga alla vecchia commessa.
// commessaweb resta come traccia del codice precedente.
$stmt = $pdo->prepare("UPDATE datadb SET status = ?, idcommessaweb = NULL WHERE iddatadb = ? AND status = 'l'");
$stmt = $pdo->prepare("UPDATE datadb SET status = ?, idcommessaweb = NULL WHERE iddatadb = ? AND status IN ('l', 'x')");
$stmt->execute([$newStatus, $iddatadb]);
if ($stmt->rowCount() > 0) {