70 lines
2.6 KiB
PHP
70 lines
2.6 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
|
|
include('include/headscript.php');
|
|
|
|
// Parametri dalla richiesta AJAX
|
|
$template_id = intval($_GET['template_id'] ?? 0);
|
|
$status = $_GET['status'] ?? 'i';
|
|
$offset = intval($_GET['offset'] ?? 0);
|
|
$limit = intval($_GET['limit'] ?? 20);
|
|
|
|
if (!$template_id || !in_array($status, ['i', 'P', 'l'])) {
|
|
error_log("Errore in load_more_rows.php: Parametri non validi - template_id: $template_id, status: $status");
|
|
echo json_encode(['success' => false, 'message' => 'Parametri non validi']);
|
|
exit;
|
|
}
|
|
|
|
// Connessione al database
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
// Recupera i dati
|
|
try {
|
|
$stmt = $pdo->prepare("
|
|
SELECT d.*, CONCAT(u.first_name, ' ', u.last_name) AS user_name
|
|
FROM datadb d
|
|
LEFT JOIN auth_users u ON d.user_id = u.id
|
|
WHERE d.templateid = ? AND d.status = ?
|
|
LIMIT ? OFFSET ?
|
|
");
|
|
$stmt->execute([$template_id, $status, $limit, $offset]);
|
|
$importedData = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// Recupera i dettagli manuali
|
|
$insertedIds = array_column($importedData, 'iddatadb');
|
|
$manualDetails = [];
|
|
if (!empty($insertedIds)) {
|
|
$placeholders = implode(',', array_fill(0, count($insertedIds), '?'));
|
|
$stmt = $pdo->prepare("
|
|
SELECT d.id AS detail_id, d.id AS datadb_id, d.mapping_id, d.field_value, m.field_label, m.data_type, m.is_required, m.manual_default
|
|
FROM import_data_details d
|
|
JOIN template_mapping m ON d.mapping_id = m.id
|
|
WHERE d.id IN ($placeholders)
|
|
");
|
|
$stmt->execute($insertedIds);
|
|
$manualDetails = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
// Prepara i dati per il JSON
|
|
$rows = [];
|
|
foreach ($importedData as $row) {
|
|
$rowData = [
|
|
'iddatadb' => $row['iddatadb'] ?? '',
|
|
'importreferencecode' => $row['importreferencecode'] ?? '',
|
|
'filename_import' => $row['filename_import'] ?? '',
|
|
'status' => $row['status'] ?? '',
|
|
'importdate' => $row['importdate'] ?? '',
|
|
'details' => array_filter($manualDetails, fn($d) => $d['datadb_id'] == $row['iddatadb'])
|
|
];
|
|
$rows[] = $rowData;
|
|
}
|
|
|
|
error_log("load_more_rows.php: Caricate " . count($rows) . " righe per template_id=$template_id, status=$status, offset=$offset");
|
|
echo json_encode(['success' => true, 'rows' => $rows]);
|
|
} catch (Exception $e) {
|
|
error_log("Errore in load_more_rows.php: " . $e->getMessage());
|
|
echo json_encode(['success' => false, 'message' => 'Errore nel caricamento: ' . $e->getMessage()]);
|
|
}
|
|
exit;
|