change clienti to datadb and fixed column pages
This commit is contained in:
@@ -11,13 +11,14 @@ try {
|
||||
}
|
||||
|
||||
$iddatadb = intval($_POST['iddatadb']);
|
||||
$idclient = isset($_POST['idclient']) ? (is_numeric($_POST['idclient']) ? intval($_POST['idclient']) : null) : null;
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$data = $_POST;
|
||||
$details = [];
|
||||
|
||||
// 1. POST-დან ამოვიღოთ მხოლოდ details
|
||||
// 1. Estrarre i dettagli da POST
|
||||
foreach ($data as $key => $value) {
|
||||
if (preg_match('/^details(\d+)field_value$/', $key, $matches)) {
|
||||
$id = $matches[1];
|
||||
@@ -25,16 +26,15 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
// 2. DB-დან წამოვიღოთ არსებული მნიშვნელობები
|
||||
// 2. Recupera i valori esistenti da import_data_details
|
||||
$stmt = $pdo->prepare("SELECT mapping_id, field_value FROM import_data_details WHERE id = ?");
|
||||
$stmt->execute([$iddatadb]);
|
||||
|
||||
$currentValues = [];
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$currentValues[$row['mapping_id']] = $row['field_value'];
|
||||
}
|
||||
|
||||
// 3. შევადაროთ POST-ს და DB-ს
|
||||
// 3. Confronta i valori nuovi con quelli esistenti
|
||||
$changed = [];
|
||||
foreach ($details as $id => $newValue) {
|
||||
$oldValue = $currentValues[$id] ?? null;
|
||||
@@ -46,7 +46,7 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
// 4. თუ არის ცვლილებები → UPDATE
|
||||
// 4. Aggiorna i dettagli se ci sono modifiche
|
||||
if (!empty($changed)) {
|
||||
$updateStmt = $pdo->prepare("
|
||||
UPDATE import_data_details
|
||||
@@ -61,15 +61,27 @@ try {
|
||||
':mappingId' => $mappingId
|
||||
]);
|
||||
}
|
||||
|
||||
$response['success'] = true;
|
||||
$response['message'] = "Updated successfully";
|
||||
$response['changed'] = $changed; // Debug / optional
|
||||
} else {
|
||||
$response['success'] = true;
|
||||
$response['message'] = "No changes found";
|
||||
}
|
||||
|
||||
// 5. Aggiorna idclient in datadb
|
||||
if (isset($idclient)) {
|
||||
$updateStmt = $pdo->prepare("
|
||||
UPDATE datadb
|
||||
SET idclient = :idclient
|
||||
WHERE iddatadb = :iddatadb
|
||||
");
|
||||
$updateStmt->execute([
|
||||
':idclient' => $idclient,
|
||||
':iddatadb' => $iddatadb
|
||||
]);
|
||||
$response['message'] = !empty($changed) ? "Updated details and idclient successfully" : "Updated idclient successfully";
|
||||
} else {
|
||||
$response['message'] = !empty($changed) ? "Updated details successfully" : "No changes found";
|
||||
}
|
||||
|
||||
$response['success'] = true;
|
||||
$response['changed'] = $changed; // Debug / optional
|
||||
|
||||
} catch (Exception $e) {
|
||||
$response['success'] = false;
|
||||
$response['message'] = $e->getMessage();
|
||||
|
||||
Reference in New Issue
Block a user