48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
include('include/headscript.php');
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
$response = ['success' => false, 'message' => ''];
|
|
|
|
try {
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['iddatadb'])) {
|
|
throw new Exception('Richiesta non valida');
|
|
}
|
|
|
|
$iddatadb = intval($_POST['iddatadb']);
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
// Campi non modificabili
|
|
$excludeFields = ['importdate', 'status', 'user_id', 'filename_import', 'importreferencecode', 'limscode'];
|
|
|
|
// Prepara i dati da aggiornare
|
|
$updates = [];
|
|
$values = [];
|
|
foreach ($_POST as $key => $value) {
|
|
if ($key !== 'iddatadb' && !in_array($key, $excludeFields)) {
|
|
$updates[] = "$key = ?";
|
|
$values[] = $value;
|
|
}
|
|
}
|
|
$values[] = $iddatadb;
|
|
|
|
if (empty($updates)) {
|
|
throw new Exception('Nessun dato da aggiornare');
|
|
}
|
|
|
|
$sql = "UPDATE datadb SET " . implode(', ', $updates) . " WHERE iddatadb = ?";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($values);
|
|
|
|
$response['success'] = true;
|
|
$response['message'] = 'Riga aggiornata con successo';
|
|
} catch (Exception $e) {
|
|
$response['message'] = $e->getMessage();
|
|
error_log("Errore in save_edited_row.php: " . $e->getMessage());
|
|
}
|
|
|
|
echo json_encode($response);
|
|
exit;
|