diff --git a/app/modules/web/Controllers/BootstrapController.php b/app/modules/web/Controllers/BootstrapController.php index f0390109..bbc71e7f 100644 --- a/app/modules/web/Controllers/BootstrapController.php +++ b/app/modules/web/Controllers/BootstrapController.php @@ -63,7 +63,9 @@ class BootstrapController extends SimpleControllerBase 'plugins' => [], 'loggedin' => $this->session->isLoggedIn(), 'authbasic_autologin' => Browser::getServerAuthUser() && $configData->isAuthBasicAutoLoginEnabled(), - 'pk' => $this->session->getPublicKey() ?: (new CryptPKI())->getPublicKey() + 'pk' => $this->session->getPublicKey() ?: (new CryptPKI())->getPublicKey(), + 'import_allowed_exts' => ['CSV', 'XML'], + 'files_allowed_exts' => $configData->getFilesAllowedExts() ]; Response::printJson($data, 0); diff --git a/app/modules/web/Controllers/ConfigImportController.php b/app/modules/web/Controllers/ConfigImportController.php new file mode 100644 index 00000000..52d1620b --- /dev/null +++ b/app/modules/web/Controllers/ConfigImportController.php @@ -0,0 +1,74 @@ +. + */ + +namespace SP\Modules\Web\Controllers; + + +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; +use SP\Http\JsonResponse; +use SP\Http\Request; +use SP\Modules\Web\Controllers\Traits\JsonTrait; +use SP\Services\Import\FileImport; +use SP\Services\Import\ImportParams; +use SP\Services\Import\ImportService; + +/** + * Class ConfigImportController + * + * @package SP\Modules\Web\Controllers + */ +class ConfigImportController extends SimpleControllerBase +{ + use JsonTrait; + + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function importAction() + { + if ($this->config->getConfigData()->isDemoEnabled()) { + $this->returnJsonResponse(JsonResponse::JSON_WARNING, __u('Ey, esto es una DEMO!!')); + } + + $importParams = new ImportParams(); + $importParams->setDefaultUser(Request::analyze('import_defaultuser', $this->session->getUserData()->getId())); + $importParams->setDefaultGroup(Request::analyze('import_defaultgroup', $this->session->getUserData()->getUserGroupId())); + $importParams->setImportPwd(Request::analyzeEncrypted('importPwd')); + $importParams->setImportMasterPwd(Request::analyzeEncrypted('importMasterPwd')); + $importParams->setCsvDelimiter(Request::analyze('csvDelimiter')); + + try { + $importService = $this->dic->get(ImportService::class); + $importService->doImport($importParams, new FileImport($this->router->request()->files()->get('inFile'))); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Importación finalizada'), [__u('Revise el registro de eventos para más detalles')]); + } catch (\Exception $e) { + processException($e); + + $this->returnJsonResponseException($e); + } + } +} \ No newline at end of file diff --git a/app/modules/web/themes/material-blue/views/config/import.inc b/app/modules/web/themes/material-blue/views/config/import.inc index cd554bbb..8543f824 100644 --- a/app/modules/web/themes/material-blue/views/config/import.inc +++ b/app/modules/web/themes/material-blue/views/config/import.inc @@ -72,8 +72,8 @@