2018-02-23 19:04:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
|
|
|
switch (post('op')) {
|
|
|
|
case 'import':
|
2018-02-26 18:06:52 +01:00
|
|
|
$first_row = !post('first_row');
|
2018-02-23 19:04:05 +01:00
|
|
|
$selected = post('fields');
|
|
|
|
|
|
|
|
// Pulizia dei campi inutilizzati
|
|
|
|
foreach ($selected as $key => $value) {
|
|
|
|
if (!is_numeric($value)) {
|
|
|
|
unset($selected[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$fields = Import::getFields($id_record);
|
|
|
|
|
|
|
|
$csv = Import::getFile($id_record, $records[0]['id'], [
|
2018-03-22 15:40:20 +01:00
|
|
|
'headers' => $first_row,
|
2018-02-23 19:04:05 +01:00
|
|
|
]);
|
2018-03-15 17:39:19 +01:00
|
|
|
|
2018-02-23 19:04:05 +01:00
|
|
|
// Interpretazione dei dati
|
|
|
|
$data = [];
|
|
|
|
foreach ($csv as $row) {
|
|
|
|
$data_row = [];
|
|
|
|
|
|
|
|
foreach ($row as $key => $value) {
|
|
|
|
$field = $fields[$selected[$key]];
|
|
|
|
|
|
|
|
if (isset($selected[$key])) {
|
|
|
|
$name = $field['field'];
|
|
|
|
|
|
|
|
$query = $field['query'];
|
|
|
|
if (!empty($query)) {
|
|
|
|
$query = str_replace('|value|', prepare($value), $query);
|
|
|
|
|
|
|
|
$value = $dbo->fetchArray($query)[0]['result'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$data_row[$name] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$data[] = $data_row;
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:39:19 +01:00
|
|
|
$primary_key = post('primary_key');
|
|
|
|
|
2018-02-23 19:04:05 +01:00
|
|
|
// Richiamo delle operazioni specifiche
|
|
|
|
include $imports[$id_record]['import'];
|
|
|
|
|
2018-07-07 13:56:22 +02:00
|
|
|
App::flash()->info(tr('Importazione completata. '.count($csv).' righe processate.'));
|
2018-02-23 19:04:05 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|