diff --git a/public/userarea/get_customfield_values.php b/public/userarea/get_customfield_values.php index 6001e74..5770073 100644 --- a/public/userarea/get_customfield_values.php +++ b/public/userarea/get_customfield_values.php @@ -1,5 +1,5 @@ ერთი default + if (empty($fieldIds)) { + $fieldIds = [156]; + } - // Recupera i dati dal server - $data = $api->get($endpoint); + $results = []; - // Salva la risposta in un file per debug - file_put_contents(__DIR__ . '/customfield_values_response.json', json_encode($data)); + foreach ($fieldIds as $customFieldId) { + $endpoint = "CustomField($customFieldId)?\$expand=CustomFieldsValues"; + $data = $api->get($endpoint); - // Output JSON al client - echo json_encode($data); + $results[$customFieldId] = $data['CustomFieldsValues'] ?? []; + } + + // Debug ფაილი + file_put_contents(__DIR__ . '/customfield_values_response.json', json_encode($results)); + + echo json_encode($results); } catch (Exception $e) { http_response_code(500); echo json_encode([ diff --git a/public/userarea/import_edit2.php b/public/userarea/import_edit2.php index d5d7336..e0bdfcc 100644 --- a/public/userarea/import_edit2.php +++ b/public/userarea/import_edit2.php @@ -19,11 +19,11 @@ if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['template_id']) || !i exit; } -$template_id = intval($_POST['template_id']); -$selected_rows = $_POST['selected_rows']; -$columns = json_decode($_POST['columns'], true); // Header dell'XLS -$rows = json_decode($_POST['rows'], true); // Dati dell'XLS -$newFilename = htmlspecialchars($_POST['filename']); +$template_id = intval($_POST['template_id']) ?? $_SESSION['template_id']; +$selected_rows = $_POST['selected_rows'] ?? $_SESSION['selected_rows']; +$columns = json_decode($_POST['columns'], true) ?? $_SESSION['columns']; // Header dell'XLS +$rows = json_decode($_POST['rows'], true) ?? $_SESSION['rows']; // Dati dell'XLS +$newFilename = htmlspecialchars($_POST['filename']) ?? $_SESSION['filename']; // Log dei dati ricevuti error_log("Received Data - Template ID: $template_id, Selected Rows: " . json_encode($selected_rows)); @@ -58,70 +58,72 @@ foreach ($allMappings as $mapping) { } } -// Inserisci le righe selezionate in datadb (solo campi generici con templateid) -$insertedIds = []; -foreach ($selected_rows as $rowIndex) { - $row = $rows[$rowIndex]; - $values = [ - $template_id, // templateid - $importReferenceCode, // importreferencecode - $newFilename, // filename_import - 'i', // status - $user_id, // user_id - null, // limscode - date('Y-m-d') // importdate - ]; - $sql = "INSERT INTO datadb (templateid, importreferencecode, filename_import, status, user_id, limscode, importdate) VALUES (?, ?, ?, ?, ?, ?, ?)"; - $stmt = $pdo->prepare($sql); - $stmt->execute($values); +//// Inserisci le righe selezionate in datadb (solo campi generici con templateid) +//$insertedIds = []; +//foreach ($selected_rows as $rowIndex) { +// $row = $rows[$rowIndex]; +// $values = [ +// $template_id, // templateid +// $importReferenceCode, // importreferencecode +// $newFilename, // filename_import +// 'i', // status +// $user_id, // user_id +// null, // limscode +// date('Y-m-d') // importdate +// ]; +// $sql = "INSERT INTO datadb (templateid, importreferencecode, filename_import, status, user_id, limscode, importdate) VALUES (?, ?, ?, ?, ?, ?, ?)"; +// $stmt = $pdo->prepare($sql); +// $stmt->execute($values); +// +// $iddatadb = $pdo->lastInsertId(); +// $insertedIds[] = $iddatadb; +// +// // Inserisci tutti i campi (automatici e manuali) in import_data_details +// foreach ($allMappings as $mapping) { +// $fieldValue = null; +// if (!$mapping['is_manual']) { // Campi automatici dall'XLS +// $excelColumn = trim($mapping['excel_column']); +// $excelColumnIndex = array_search($excelColumn, array_map('trim', $columns)); +// if ($excelColumnIndex !== false && isset($row[$excelColumnIndex]) && $row[$excelColumnIndex] !== '') { +// $fieldValue = $row[$excelColumnIndex]; +// error_log("Found Excel column '$excelColumn' at index $excelColumnIndex, value: " . var_export($fieldValue, true)); +// } else { +// $fieldValue = $mapping['manual_default'] ?? ''; +// error_log("Excel column '$excelColumn' not found or empty, using default: " . var_export($fieldValue, true)); +// } +// switch ($mapping['data_type']) { +// case 'INT': +// $fieldValue = is_numeric($fieldValue) ? (int)$fieldValue : ($mapping['manual_default'] ?? 0); +// break; +// case 'DATE': +// $fieldValue = !empty($fieldValue) ? date('Y-m-d', strtotime($fieldValue)) : ($mapping['manual_default'] === 'today' ? date('Y-m-d') : ($mapping['manual_default'] ?? '')); +// break; +// case 'CHAR': +// $fieldValue = !empty($fieldValue) ? substr((string)$fieldValue, 0, 1) : ($mapping['manual_default'] ?? ''); +// break; +// case 'Testo': +// case 'VARCHAR': +// default: +// $fieldValue = !empty($fieldValue) ? htmlspecialchars((string)$fieldValue) : ($mapping['manual_default'] ?? ''); +// break; +// } +// } else { // Campi manuali +// $fieldValue = $mapping['manual_default'] ?? ''; +// if ($mapping['data_type'] === 'DATE' && $mapping['manual_default'] === 'today') { +// $fieldValue = date('Y-m-d'); +// } +// } +// if ($mapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) { +// error_log("Required field missing for mapping ID: " . $mapping['id'] . ", field: " . $mapping['field_label']); +// } +// error_log("Inserting into import_data_details - Mapping ID: " . $mapping['id'] . ", Field Value: " . var_export($fieldValue, true) . ", Is Manual: " . $mapping['is_manual'] . ", Excel Column: " . ($mapping['excel_column'] ?? 'N/A') . ", Manual Default: " . ($mapping['manual_default'] ?? 'N/A')); +// $stmt = $pdo->prepare("INSERT INTO import_data_details (id, mapping_id, field_value) VALUES (?, ?, ?)"); +// $stmt->execute([$iddatadb, $mapping['id'], $fieldValue]); +// error_log("Inserted into import_data_details for ID $iddatadb, Mapping ID: " . $mapping['id'] . ", Field Value: " . var_export($fieldValue, true)); +// } +//} - $iddatadb = $pdo->lastInsertId(); - $insertedIds[] = $iddatadb; - - // Inserisci tutti i campi (automatici e manuali) in import_data_details - foreach ($allMappings as $mapping) { - $fieldValue = null; - if (!$mapping['is_manual']) { // Campi automatici dall'XLS - $excelColumn = trim($mapping['excel_column']); - $excelColumnIndex = array_search($excelColumn, array_map('trim', $columns)); - if ($excelColumnIndex !== false && isset($row[$excelColumnIndex]) && $row[$excelColumnIndex] !== '') { - $fieldValue = $row[$excelColumnIndex]; - error_log("Found Excel column '$excelColumn' at index $excelColumnIndex, value: " . var_export($fieldValue, true)); - } else { - $fieldValue = $mapping['manual_default'] ?? ''; - error_log("Excel column '$excelColumn' not found or empty, using default: " . var_export($fieldValue, true)); - } - switch ($mapping['data_type']) { - case 'INT': - $fieldValue = is_numeric($fieldValue) ? (int)$fieldValue : ($mapping['manual_default'] ?? 0); - break; - case 'DATE': - $fieldValue = !empty($fieldValue) ? date('Y-m-d', strtotime($fieldValue)) : ($mapping['manual_default'] === 'today' ? date('Y-m-d') : ($mapping['manual_default'] ?? '')); - break; - case 'CHAR': - $fieldValue = !empty($fieldValue) ? substr((string)$fieldValue, 0, 1) : ($mapping['manual_default'] ?? ''); - break; - case 'Testo': - case 'VARCHAR': - default: - $fieldValue = !empty($fieldValue) ? htmlspecialchars((string)$fieldValue) : ($mapping['manual_default'] ?? ''); - break; - } - } else { // Campi manuali - $fieldValue = $mapping['manual_default'] ?? ''; - if ($mapping['data_type'] === 'DATE' && $mapping['manual_default'] === 'today') { - $fieldValue = date('Y-m-d'); - } - } - if ($mapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) { - error_log("Required field missing for mapping ID: " . $mapping['id'] . ", field: " . $mapping['field_label']); - } - error_log("Inserting into import_data_details - Mapping ID: " . $mapping['id'] . ", Field Value: " . var_export($fieldValue, true) . ", Is Manual: " . $mapping['is_manual'] . ", Excel Column: " . ($mapping['excel_column'] ?? 'N/A') . ", Manual Default: " . ($mapping['manual_default'] ?? 'N/A')); - $stmt = $pdo->prepare("INSERT INTO import_data_details (id, mapping_id, field_value) VALUES (?, ?, ?)"); - $stmt->execute([$iddatadb, $mapping['id'], $fieldValue]); - error_log("Inserted into import_data_details for ID $iddatadb, Mapping ID: " . $mapping['id'] . ", Field Value: " . var_export($fieldValue, true)); - } -} +$insertedIds = $_POST['inserted_ids'] ?? $_SESSION['inserted_ids']; // Recupera i dati appena inseriti con i nomi degli utenti $stmt = $pdo->prepare(" @@ -436,7 +438,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {