import xls update
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once(__DIR__ . '/class/db-functions.php');
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
if (!isset($data['template_id'], $data['excel_column'], $data['mysql_column'], $data['tablename'])) {
|
||||
echo json_encode(["success" => false, "message" => "Missing required fields"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Rimuove l'associazione
|
||||
$stmtDelete = $pdo->prepare("
|
||||
DELETE FROM excel_column_mappings
|
||||
WHERE template_id = ? AND excel_column = ? AND mysql_column = ? AND tablename = ?
|
||||
");
|
||||
$result = $stmtDelete->execute([
|
||||
$data['template_id'],
|
||||
$data['excel_column'],
|
||||
$data['mysql_column'],
|
||||
$data['tablename']
|
||||
]);
|
||||
|
||||
if (!$result) {
|
||||
echo json_encode(["success" => false, "message" => "Failed to delete mapping"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Dopo la rimozione, aggiorna la lista delle colonne disponibili
|
||||
$stmtColumns = $pdo->prepare("SHOW COLUMNS FROM " . $data['tablename']);
|
||||
$stmtColumns->execute();
|
||||
$all_mysql_columns = array_column($stmtColumns->fetchAll(PDO::FETCH_ASSOC), 'Field');
|
||||
|
||||
$stmtHeader = $pdo->prepare("SELECT headerexcel FROM excel_column_mappings WHERE template_id = ? LIMIT 1");
|
||||
$stmtHeader->execute([$data['template_id']]);
|
||||
$headerRow = $stmtHeader->fetch(PDO::FETCH_ASSOC);
|
||||
$xls_headers = isset($headerRow['headerexcel']) ? explode(",", $headerRow['headerexcel']) : [];
|
||||
|
||||
// Ricalcola le colonne non associate
|
||||
$stmtMappings = $pdo->prepare("SELECT excel_column, mysql_column FROM excel_column_mappings WHERE template_id = ?");
|
||||
$stmtMappings->execute([$data['template_id']]);
|
||||
$existingMappings = $stmtMappings->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$mapped_xls_columns = array_column($existingMappings, 'excel_column');
|
||||
$mapped_mysql_columns = array_column($existingMappings, 'mysql_column');
|
||||
|
||||
$remaining_xls_columns = array_diff($xls_headers, $mapped_xls_columns);
|
||||
$remaining_mysql_columns = array_diff($all_mysql_columns, $mapped_mysql_columns);
|
||||
|
||||
echo json_encode([
|
||||
"success" => true,
|
||||
"remaining_xls_columns" => array_values($remaining_xls_columns),
|
||||
"remaining_mysql_columns" => array_values($remaining_mysql_columns)
|
||||
]);
|
||||
exit;
|
||||
Reference in New Issue
Block a user