diff --git a/Admin/Routes/Web/Api.php b/Admin/Routes/Web/Api.php new file mode 100644 index 0000000..089381c --- /dev/null +++ b/Admin/Routes/Web/Api.php @@ -0,0 +1,18 @@ + [ + [ + 'dest' => '\Modules\Exchange\Controller:apiExchangeImport', + 'verb' => RouteVerb::SET, + ], + ], + '^.*/api/admin/exchange/export/profile.*$' => [ + [ + 'dest' => '\Modules\Exchange\Controller:apiExchangeExport', + 'verb' => RouteVerb::SET, + ], + ], +]; diff --git a/Controller.php b/Controller.php index 9803ba1..1de81f9 100644 --- a/Controller.php +++ b/Controller.php @@ -20,12 +20,15 @@ use Modules\Navigation\Views\NavigationView; use phpOMS\Contract\RenderableInterface; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; +use phpOMS\Message\NotificationLevel; use phpOMS\Module\ModuleAbstract; use phpOMS\Module\WebInterface; use phpOMS\Views\View; +use phpOMS\Account\PermissionType; use Modules\Exchange\Models\InterfaceManager; use Modules\Exchange\Models\InterfaceManagerMapper; +use Modules\Exchange\Models\PermissionState; /** * Exchange controller class. @@ -155,6 +158,73 @@ final class Controller extends ModuleAbstract implements WebInterface $view->addData('interface', $interface); + $lang = include __DIR__ . '/Interfaces/' . $interface->getInterfacePath() . '/' . $response->getHeader()->getL11n()->getLanguage() . '.lang.php'; + $view->addData('lang', $lang); + return $view; } + + /** + * Api method to import data + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiExchangeImport(RequestAbstract $request, ResponseAbstract $response, $data = null) : void + { + if (!$this->app->accountManager->get($request->getHeader()->getAccount())->hasPermission( + PermissionType::MODIFY, $this->app->orgId, $this->app->appName, self::MODULE_NAME, PermissionState::IMPORT) + ) { + $response->set('exchange_import', null); + $response->getHeader()->setStatusCode(RequestStatusCode::R_403); + return; + } + + $import = $this->importDataFromRequest($request); + + if ($import) { + $response->set($request->getUri()->__toString(), [ + 'status' => NotificationLevel::OK, + 'title' => 'Exchange', + 'message' => 'Import succeeded.' + ]); + } else { + $response->set($request->getUri()->__toString(), [ + 'status' => NotificationLevel::ERROR, + 'title' => 'Exchange', + 'message' => 'Import failed.' + ]); + } + } + + /** + * Method to import data based on a request + * + * @param RequestAbstract $request Request + * + * @return bool + * + * @since 1.0.0 + */ + private function importDataFromRequest(RequestAbstract $request) : bool + { + $interfaces = InterfaceManagerMapper::getAll(); + foreach ($interfaces as $interface) { + if ($request->getData('exchange') === $interface->getInterfacePath()) { + $class = '\\Modules\\Exchange\\Interfaces\\' . $interface->getInterfacePath() . '\\Importer'; + $importer = new $class(); + + return $importer->importRequest($request); + } + } + + return false; + } } diff --git a/Interfaces/GSD/en.lang.php b/Interfaces/GSD/en.lang.php new file mode 100644 index 0000000..381a57a --- /dev/null +++ b/Interfaces/GSD/en.lang.php @@ -0,0 +1,22 @@ + 'Accounts', + 'Articles' => 'Articles', + 'CostCenters' => 'Cost Centers', + 'CostObjects' => 'Cost Objects', + 'Customers' => 'Customers', + 'Invoices' => 'Invoices', + 'Options' => 'Options', + 'Suppliers' => 'Suppliers', +]; diff --git a/Interfaces/GSD/import.tpl.php b/Interfaces/GSD/import.tpl.php index 0964e28..90da985 100644 --- a/Interfaces/GSD/import.tpl.php +++ b/Interfaces/GSD/import.tpl.php @@ -1,12 +1,54 @@
-

getHtml('Task') ?>

+

getHtml('Import') ?> - GSD

-
+ +
+
+
+
+
getHtml('Options') ?> +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+
diff --git a/Models/PermissionState.php b/Models/PermissionState.php new file mode 100644 index 0000000..bdb0298 --- /dev/null +++ b/Models/PermissionState.php @@ -0,0 +1,31 @@ + [ + 'End' => 'End', 'Exchange' => 'Exchange', + 'Export' => 'Export', 'Exports' => 'Exports', + 'Import' => 'Import', 'Imports' => 'Imports', + 'Options' => 'Options', + 'Start' => 'Start', 'Title' => 'Title', 'Website' => 'Website', ]]; diff --git a/Theme/Backend/exchange-import.tpl.php b/Theme/Backend/exchange-import.tpl.php index ebd3ba2..891d4fc 100644 --- a/Theme/Backend/exchange-import.tpl.php +++ b/Theme/Backend/exchange-import.tpl.php @@ -11,9 +11,11 @@ * @link http://website.orange-management.de */ + $lang = $this->getData('lang'); + /** * @var \phpOMS\Views\View $this */ echo $this->getData('nav')->render(); -include __DIR__ . '/../../Interfaces/' . $this->getData('interface')->getInterfacePath() . '/import.tpl.php'; \ No newline at end of file +include __DIR__ . '/../../Interfaces/' . $this->getData('interface')->getInterfacePath() . '/import.tpl.php';