2018-02-23 19:04:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
|
|
|
if (empty($id_record)) {
|
|
|
|
require $docroot.'/add.php';
|
|
|
|
} else {
|
|
|
|
// Inclusione del file del modulo per eventuale HTML personalizzato
|
|
|
|
include $imports[$id_record]['import'];
|
|
|
|
|
|
|
|
$fields = Import::getFields($id_record);
|
|
|
|
|
|
|
|
$select = [];
|
2018-03-01 01:56:57 +01:00
|
|
|
$select2 = [];
|
2018-02-23 19:04:05 +01:00
|
|
|
foreach ($fields as $key => $value) {
|
|
|
|
$select[] = [
|
|
|
|
'id' => $key,
|
|
|
|
'text' => $value['label'],
|
|
|
|
];
|
2018-03-01 01:56:57 +01:00
|
|
|
|
|
|
|
$select2[] = [
|
|
|
|
'id' => $value['field'],
|
|
|
|
'text' => $value['label'],
|
|
|
|
];
|
|
|
|
|
2018-03-15 17:39:19 +01:00
|
|
|
if ($value['primary_key']) {
|
2018-03-01 01:56:57 +01:00
|
|
|
$primary_key = $value['field'];
|
|
|
|
}
|
2018-02-23 19:04:05 +01:00
|
|
|
}
|
|
|
|
|
2018-03-01 01:56:57 +01:00
|
|
|
echo '
|
|
|
|
<form action="" method="post" id="edit-form">
|
|
|
|
<input type="hidden" name="backto" value="record-list">
|
|
|
|
<input type="hidden" name="op" value="import">
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-8">
|
2019-02-21 22:21:30 +01:00
|
|
|
{[ "type": "checkbox", "label": "'.tr('Importa prima riga').'", "name": "include_first_row", "extra":"", "value": "1" ]}
|
2018-03-01 01:56:57 +01:00
|
|
|
</div>
|
|
|
|
<div class="col-md-4">
|
|
|
|
{[ "type": "select", "label": "'.tr('Chiave primaria').'", "name": "primary_key", "values": '.json_encode($select2).', "value": "'.$primary_key.'" ]}
|
|
|
|
</div>
|
|
|
|
</div>';
|
|
|
|
|
2019-02-21 22:21:30 +01:00
|
|
|
$csv = Import::getCSV($id_record, $record['id']);
|
|
|
|
$rows = $csv->setLimit(10)->fetchAll();
|
2018-11-22 15:34:44 +01:00
|
|
|
|
2018-02-23 19:04:05 +01:00
|
|
|
$count = count($rows[0]);
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<div class="row">';
|
|
|
|
|
|
|
|
for ($column = 0; $column < $count; ++$column) {
|
|
|
|
echo '
|
|
|
|
<div class="col-sm-6 col-lg-4">
|
|
|
|
<div class="panel panel-primary">
|
|
|
|
<div class="panel-heading">
|
|
|
|
<h3 class="panel-title">'.tr('Colonna _NUM_', [
|
|
|
|
'_NUM_' => $column + 1,
|
|
|
|
]).'</h3>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="panel-body">';
|
|
|
|
|
|
|
|
// Individuazione delle corrispondenze
|
|
|
|
$selected = null;
|
|
|
|
foreach ($fields as $key => $value) {
|
2018-09-04 10:03:02 +02:00
|
|
|
if (in_array(str_to_lower($rows[0][$column]), $value['names'])) {
|
2019-02-21 22:21:30 +01:00
|
|
|
$exclude_first_row = 1;
|
2018-02-23 19:04:05 +01:00
|
|
|
$selected = $key;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
{[ "type": "select", "label": "'.tr('Campo').'", "name": "fields[]", "values": '.json_encode($select).', "value": "'.$selected.'" ]}
|
|
|
|
|
|
|
|
<table class="table table-striped">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>'.tr('#').'</th>
|
|
|
|
<th>'.tr('Valore').'</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>';
|
|
|
|
|
|
|
|
foreach ($rows as $key => $row) {
|
|
|
|
echo '
|
|
|
|
<tr>
|
|
|
|
<td>'.($key + 1).'</td>
|
|
|
|
<td>'.$row[$column].'</td>
|
|
|
|
</tr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</div>
|
|
|
|
</form>';
|
2018-03-15 17:39:19 +01:00
|
|
|
|
|
|
|
echo '
|
2018-02-28 21:40:16 +01:00
|
|
|
<script>
|
2020-07-31 14:25:50 +02:00
|
|
|
$(document).ready(function() {';
|
2018-03-15 17:39:19 +01:00
|
|
|
|
2019-02-21 22:21:30 +01:00
|
|
|
if ($exclude_first_row) {
|
2018-03-15 17:39:19 +01:00
|
|
|
echo '
|
2019-02-21 22:21:30 +01:00
|
|
|
$("#include_first_row").prop("checked", false).trigger("change");';
|
2018-03-15 17:39:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
$("#save").html("<i class=\"fa fa-flag-checkered\"></i> '.tr('Avvia importazione').'");
|
2020-07-31 14:25:50 +02:00
|
|
|
|
2019-02-21 22:21:30 +01:00
|
|
|
$("#save").unbind("click");
|
|
|
|
$("#save").on("click", function() {
|
|
|
|
importPage(0);
|
|
|
|
});
|
2018-02-28 23:44:30 +01:00
|
|
|
});
|
2019-02-21 22:21:30 +01:00
|
|
|
|
|
|
|
var count = 0;
|
|
|
|
function importPage(page){
|
|
|
|
$("#main_loading").show();
|
|
|
|
|
|
|
|
data = {
|
|
|
|
id_module: "'.$id_module.'",
|
|
|
|
id_plugin: "'.$id_plugin.'",
|
|
|
|
id_record: "'.$id_record.'",
|
|
|
|
page: page,
|
|
|
|
};
|
2020-07-31 14:25:50 +02:00
|
|
|
|
2019-02-21 22:21:30 +01:00
|
|
|
$("#edit-form").ajaxSubmit({
|
|
|
|
url: globals.rootdir + "/actions.php",
|
|
|
|
data: data,
|
|
|
|
type: "post",
|
|
|
|
success: function(data) {
|
|
|
|
data = JSON.parse(data);
|
2020-07-31 14:25:50 +02:00
|
|
|
|
2019-02-21 22:21:30 +01:00
|
|
|
count += data.count;
|
2020-07-31 14:25:50 +02:00
|
|
|
|
2019-02-21 22:21:30 +01:00
|
|
|
if(data.more) {
|
|
|
|
importPage(page + 1);
|
|
|
|
} else {
|
|
|
|
$("#main_loading").fadeOut();
|
|
|
|
|
|
|
|
swal({
|
|
|
|
title: "'.tr('Importazione completata: _COUNT_ righe processate', [
|
|
|
|
'_COUNT_' => '" + count + "',
|
|
|
|
]).'",
|
|
|
|
type: "success",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(data) {
|
|
|
|
$("#main_loading").fadeOut();
|
|
|
|
|
|
|
|
alert("'.tr('Errore').': " + data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2018-03-15 17:39:19 +01:00
|
|
|
</script>';
|
2018-02-23 19:04:05 +01:00
|
|
|
}
|