mirror of
https://github.com/rmontanana/inventario2.git
synced 2025-08-15 23:45:58 +00:00
ref #3 Casi terminado el proceso de importación de datos, incluida la gestión de transacciones. Falta mostrar progreso de la importación o no.
This commit is contained in:
@@ -31,11 +31,15 @@ class Importacion {
|
||||
}
|
||||
|
||||
public function ejecuta() {
|
||||
$opc = $_GET['opc'];
|
||||
$opc = '';
|
||||
if (isset($_GET['opc'])) {
|
||||
$opc = $_GET['opc'];
|
||||
}
|
||||
switch ($opc) {
|
||||
case 'form':return $this->formulario();
|
||||
case 'importar':return $this->importarFichero();
|
||||
case 'ejecutar':return "Ok";
|
||||
case 'ejecutar':return $this->ejecutaFichero();
|
||||
default: return "Importacion: No entiendo qué me has pedido.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,26 +49,35 @@ class Importacion {
|
||||
die('No se pudo subir el fichero ' . $_FILES['userfile']['tmp_name']);
|
||||
}
|
||||
$csv = new Csv($this->bdd);
|
||||
return $csv->cargaCSV($uploadfile);
|
||||
$csv->cargaCSV($uploadfile);
|
||||
return $csv->resumen();
|
||||
}
|
||||
|
||||
private function formulario() {
|
||||
$accion = "index.php?importacion&opc=importar";
|
||||
$salida = '<form enctype="multipart/form-data" name="importacion.form" method="post" action="' . $accion . '">' . "\n";
|
||||
$salida .="<fieldset style=\"width: 96%;\"><p><legend style=\"color: red;\"><b>Elige Archivo</b></legend>\n";
|
||||
$salida .= '<input type="file" name="fichero" id="fichero" onClick="seleccionFichero(this);">';
|
||||
$salida .='<p align="center"><button class="btn btn-primary" type=submit>Aceptar</button></p><br>' . "\n";
|
||||
$salida .="<script type='text/javascript'>
|
||||
$salida .= "<fieldset style=\"width: 96%;\"><p><legend style=\"color: red;\"><b>Elige Archivo</b></legend>\n";
|
||||
$salida .= '<input type="file" name="fichero" id="fichero" onChange="seleccionFichero(this);">';
|
||||
$salida .= '<p align="center"><button class="btn btn-primary" type=submit>Aceptar</button></p><br>' . "\n";
|
||||
$mensaje = utf8_decode('Sólo se permiten archivos con extensión CSV');
|
||||
$salida .= "<script type='text/javascript'>
|
||||
function seleccionFichero(obj) {
|
||||
var filePath = obj.value;
|
||||
|
||||
var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();
|
||||
if(ext != 'csv') {
|
||||
alert('Sólo se permiten archivos con extensión CSV');
|
||||
}
|
||||
alert('".$mensaje."');
|
||||
location.reload();
|
||||
}}
|
||||
</script>";
|
||||
return $salida;
|
||||
}
|
||||
private function ejecutaFichero() {
|
||||
$archivo = $_POST['ficheroCSV'];
|
||||
$csv = new Csv($this->bdd);
|
||||
$csv->cargaCSV($archivo);
|
||||
return $csv->ejecutaFichero();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user