diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 7575668..be67e33 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -2783,13 +2783,41 @@ final class ApiController extends Controller */ public function apiAddGroupToAccount(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void { + if (!empty($val = $this->validateAddGroupToAccount($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidAddResponse($request, $response, $val); + + return; + } + $account = (int) $request->getData('account'); - $groups = \array_map('intval', $request->getDataList('igroup-idlist')); + $groups = [$request->getDataInt('account-list') ?? 0]; $this->createModelRelation($request->header->account, $account, $groups, AccountMapper::class, 'groups', 'account-group', $request->getOrigin()); $this->createStandardAddResponse($request, $response, $groups); } + /** + * Validate adding a group to an account request + * + * @param RequestAbstract $request Request + * + * @return array + * + * @since 1.0.0 + */ + private function validateAddGroupToAccount(RequestAbstract $request) : array + { + $val = []; + if (($val['account'] = !$request->hasData('account')) + || ($val['accountlist'] = !$request->hasData('account-list')) + ) { + return $val; + } + + return []; + } + /** * Api method to add an account to a group * @@ -2805,13 +2833,41 @@ final class ApiController extends Controller */ public function apiAddAccountToGroup(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void { + if (!empty($val = $this->validateAddAccountToGroup($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidAddResponse($request, $response, $val); + + return; + } + $group = (int) $request->getData('group'); - $accounts = \array_map('intval', $request->getDataList('iaccount-idlist')); + $accounts = [$request->getDataInt('group-list') ?? 0]; $this->createModelRelation($request->header->account, $group, $accounts, GroupMapper::class, 'accounts', 'group-account', $request->getOrigin()); $this->createStandardAddResponse($request, $response, $accounts); } + /** + * Validate adding an account to a group request + * + * @param RequestAbstract $request Request + * + * @return array + * + * @since 1.0.0 + */ + private function validateAddAccountToGroup(RequestAbstract $request) : array + { + $val = []; + if (($val['group'] = !$request->hasData('group')) + || ($val['grouplist'] = !$request->hasData('group-list')) + ) { + return $val; + } + + return []; + } + /** * Api method to add a group to an account * diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 2b2a523..3755154 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -221,18 +221,95 @@ final class BackendController extends Controller $view->data['permissions'] = $permissions; + $view->data['units'] = UnitMapper::getAll()->execute(); + $view->data['apps'] = AppMapper::getAll()->execute(); + $view->data['modules'] = ModuleMapper::getAll()->execute(); + $accGrpSelector = new \Modules\Admin\Theme\Backend\Components\GroupTagSelector\GroupTagSelectorView($this->app->l11nManager, $request, $response); $view->data['grpSelector'] = $accGrpSelector; - // audit log - if ($request->getData('ptype') === 'p') { - $view->data['auditlogs'] = AuditMapper::getAll()->with('createdBy')->where('id', $request->getDataInt('audit') ?? 0, '<')->limit(25)->execute(); - } elseif ($request->getData('ptype') === 'n') { - $view->data['auditlogs'] = AuditMapper::getAll()->with('createdBy')->where('id', $request->getDataInt('audit') ?? 0, '>')->limit(25)->execute(); - } else { - $view->data['auditlogs'] = AuditMapper::getAll()->with('createdBy')->where('id', 0, '>')->limit(25)->execute(); + // Auditor log + $searchFieldData = $request->getLike('.*\-p\-.*'); + $searchField = []; + foreach ($searchFieldData as $key => $data) { + if ($data === '1') { + $split = \explode('-', $key); + $member = \end($split); + + $searchField[] = $member; + } } + $filterFieldData = $request->getLike('.*\-f\-.*?\-t'); + $filterField = []; + foreach ($filterFieldData as $key => $type) { + $split = \explode('-', $key); + \end($split); + + $member = \prev($split); + + if ($request->hasData('auditlist-f-' . $member . '-f1')) { + $filterField[$member] = [ + 'type' => $type, + 'value1' => $request->getData('auditlist-f-' . $member . '-f1'), + 'logic1' => $request->getData('auditlist-f-' . $member . '-o1'), + 'value2' => $request->getData('auditlist-f-' . $member . '-f2'), + 'logic2' => $request->getData('auditlist-f-' . $member . '-o2'), + ]; + } + } + + $pageLimit = 25; + $view->data['pageLimit'] = $pageLimit; + + $mapper = AuditMapper::getAll()->with('createdBy'); + + /** @var \Modules\Auditor\Models\Audit[] $list */ + $list = AuditMapper::find( + search: $request->getDataString('search'), + mapper: $mapper, + id: $request->getDataInt('id') ?? 0, + secondaryId: $request->getDataString('subid') ?? '', + type: $request->getDataString('pType'), + pageLimit: empty($request->getDataInt('limit') ?? 0) ? 100 : $request->getDataInt('limit'), + sortBy: $request->getDataString('sort_by') ?? '', + sortOrder: $request->getDataString('sort_order') ?? OrderType::DESC, + searchFields: $searchField, + filters: $filterField + ); + + $view->data['audits'] = $list['data']; + + /** @var \Model\Setting[] $exportTemplates */ + $exportTemplates = $this->app->appSettings->get( + names: [SettingsEnum::DEFAULT_LIST_EXPORTS], + module: 'Admin' + ); + + $templateIds = []; + foreach ($exportTemplates as $template) { + $templateIds[] = (int) $template->content; + } + + /** @var \Modules\Media\Models\Media[] $mediaTemplates */ + $mediaTemplates = MediaMapper::getAll() + ->where('id', $templateIds, 'in') + ->execute(); + + $tableView = new TableView($this->app->l11nManager, $request, $response); + $tableView->module = 'Auditor'; + $tableView->theme = 'Backend'; + $tableView->setTitleTemplate('/Web/Backend/Themes/table-title'); + $tableView->setExportTemplate('/Web/Backend/Themes/popup-export-data'); + $tableView->setExportTemplates($mediaTemplates); + $tableView->setColumnHeaderElementTemplate('/Web/Backend/Themes/header-element-table'); + $tableView->setFilterTemplate('/Web/Backend/Themes/popup-filter-table'); + $tableView->setSortTemplate('/Web/Backend/Themes/sort-table'); + $tableView->setData('hasPrevious', $list['hasPrevious']); + $tableView->setData('hasNext', $list['hasNext']); + + $view->data['tableView'] = $tableView; + return $view; } diff --git a/Theme/Backend/accounts-single.tpl.php b/Theme/Backend/accounts-single.tpl.php index 1bad1a5..bf54e53 100755 --- a/Theme/Backend/accounts-single.tpl.php +++ b/Theme/Backend/accounts-single.tpl.php @@ -22,7 +22,6 @@ use phpOMS\Localization\ISO4217Enum; use phpOMS\Localization\ISO639Enum; use phpOMS\Localization\ISO8601EnumArray; use phpOMS\Localization\TimeZoneEnumArray; -use phpOMS\Message\Http\HttpHeader; use phpOMS\System\File\Local\Directory; use phpOMS\Uri\UriFactory; use phpOMS\Utils\Converter\AreaType; @@ -37,15 +36,26 @@ use phpOMS\Utils\Converter\WeightType; */ $account = $this->data['account']; $permissions = $this->data['permissions']; -$audits = $this->data['auditlogs'] ?? []; $l11n = $account->l11n; -$previous = empty($audits) - ? HttpHeader::getAllHeaders()['Referer'] ?? 'admin/account/settings?id={?id}#{\#}' - : 'admin/account/settings?{?}&audit=' . \reset($audits)->id . '&ptype=p#{\#}'; -$next = empty($audits) - ? HttpHeader::getAllHeaders()['Referer'] ?? 'admin/account/settings?id={?id}#{\#}' - : 'admin/account/settings?{?}&audit=' . \end($audits)->id . '&ptype=n#{\#}'; +$audits = $this->data['audits'] ?? []; + +$tableView = $this->data['tableView']; +$tableView->id = 'auditList'; +$tableView->baseUri = '{/base}/admin/audit/list'; +$tableView->exportUri = '{/api}auditor/list/export'; +$tableView->setObjects($audits); + +$previous = $tableView->getPreviousLink( + $this->request, + empty($tableView->objects) || !$this->getData('hasPrevious') ? null : \reset($tableView->objects) +); + +$next = $tableView->getNextLink( + $this->request, + empty($tableView->objects) ? null : \end($tableView->objects), + $this->getData('hasNext') ?? false +); echo $this->data['nav']->render(); ?> @@ -132,7 +142,7 @@ echo $this->data['nav']->render(); ?> -
or
+
or
@@ -210,96 +220,126 @@ echo $this->data['nav']->render(); ?>
-
-
-
getHtml('Permissions'); ?>
-
+
+ +
getHtml('Permissions'); ?>
+
+
+ + +
- +
- +
- +
- +
- +
- +
- - - + + + - - - + + + - - - + + + - - - + + + - - - + + +
- - - + + + + +
-
-
-
+
getHtml('Permissions'); ?>
-
- +
+
- + $value) : ++$c; - $permission = $value->getPermission(); - ?> - - +
getHtml('ID', '0', '0'); ?> getHtml('Unit'); ?> @@ -310,29 +350,68 @@ echo $this->data['nav']->render(); ?> getHtml('Comp'); ?> getHtml('Perm'); ?>
- - id; ?> - printHtml($value->unit); ?> - printHtml($value->app); ?> - printHtml($value->module); ?> - printHtml($value->category); ?> - printHtml($value->element); ?> - printHtml($value->component); ?> + foreach ($permissions as $key => $value) : ++$c; + $permission = $value->getPermission(); ?> +
+ + + + + + + id; ?> + printHtml(isset($this->data['units'][$value->unit]) ? $this->data['units'][$value->unit]->name : ''); ?> + printHtml(isset($this->data['apps'][$value->app]) ? $this->data['apps'][$value->app]->name : ''); ?> + printHtml($value->module); ?> + printHtml((string) $value->category); ?> + printHtml((string) $value->element); ?> + printHtml((string) $value->component); ?> - - - - - + + C + + + R + + + U + + + D + + + P + -
getHtml('Empty', '0', '0'); ?> +
getHtml('Empty', '0', '0'); ?>
@@ -382,7 +461,7 @@ echo $this->data['nav']->render(); ?>
@@ -810,45 +889,69 @@ echo $this->data['nav']->render(); ?> request->uri->fragment === 'c-tab-5' ? ' checked' : ''; ?>>
-
-
-
-
getHtml('Audits', 'Auditor'); ?>
- - - - - $audit) : ++$count; - $url = UriFactory::build('{/base}/admin/audit/single?{?}&id=' . $audit->id); - ?> - -
getHtml('ID', '0', '0'); ?> - getHtml('Module', 'Auditor'); ?> - getHtml('Type', 'Auditor'); ?> - getHtml('Trigger', 'Auditor'); ?> - getHtml('By', 'Auditor'); ?> - getHtml('Ref', 'Auditor'); ?> - getHtml('Date', 'Auditor'); ?> -
id; ?> - printHtml($audit->module); ?> - type; ?> - printHtml($audit->trigger); ?> - printHtml($audit->createdBy->login); ?> - printHtml($audit->ref); ?> - createdAt->format('Y-m-d H:i'); ?> - - -
getHtml('Empty', '0', '0'); ?> - -
- +
+
+
+
renderTitle($this->getHtml('Audits', 'Auditor', 'Backend')); ?>
+
+ + + + + $audit) : ++$count; + $url = UriFactory::build('{/base}/admin/audit/single?id=' . $audit->id); ?> + +
renderHeaderElement('id', $this->getHtml('ID', '0', '0'), 'number'); ?> + renderHeaderElement('module', $this->getHtml('Module', 'Auditor', 'Backend'), 'text'); ?> + renderHeaderElement('action', $this->getHtml('Action', 'Auditor', 'Backend'), 'select', + [ + 'create' => $this->getHtml('CREATE', 'Auditor', 'Backend'), + 'modify' => $this->getHtml('UPDATE', 'Auditor', 'Backend'), + 'delete' => $this->getHtml('DELETE', 'Auditor', 'Backend'), + ], + false // don't render sort + ); ?> + renderHeaderElement('type', $this->getHtml('Type', 'Auditor', 'Backend'), 'number'); ?> + renderHeaderElement('trigger', $this->getHtml('Trigger', 'Auditor', 'Backend'), 'text'); ?> + renderHeaderElement('createdBy', $this->getHtml('By', 'Auditor', 'Backend'), 'text'); ?> + renderHeaderElement('ref', $this->getHtml('Ref', 'Auditor', 'Backend'), 'text', [], true, true, false); ?> + renderHeaderElement('createdAt', $this->getHtml('Date', 'Auditor', 'Backend'), 'date'); ?> +
id; ?> + printHtml($audit->module); ?> + old === null) : echo $this->getHtml('CREATE', 'Auditor', 'Backend'); ?> + old !== null && $audit->new !== null) : echo $this->getHtml('UPDATE', 'Auditor', 'Backend'); ?> + new === null) : echo $this->getHtml('DELETE', 'Auditor', 'Backend'); ?> + getHtml('UNKNOWN', 'Auditor', 'Backend'); ?> + + printHtml((string) $audit->type); ?> + printHtml($audit->trigger); ?> + printHtml( + $this->renderUserName('%3$s %2$s %1$s', [$audit->createdBy->name1, $audit->createdBy->name2, $audit->createdBy->name3, $audit->createdBy->login]) + ); ?> + printHtml((string) $audit->ref); ?> + createdAt->format('Y-m-d H:i:s'); ?> + + +
getHtml('Empty', '0', '0'); ?> + +
+ getData('hasPrevious') || $this->getData('hasNext')) : ?> +
+ getData('hasPrevious')) : ?> + + + getData('hasNext')) : ?> + + +
+
+ +
diff --git a/Theme/Backend/groups-single.tpl.php b/Theme/Backend/groups-single.tpl.php index e57011d..cff410d 100755 --- a/Theme/Backend/groups-single.tpl.php +++ b/Theme/Backend/groups-single.tpl.php @@ -92,16 +92,21 @@ echo $this->data['nav']->render(); ?>
-
+
getHtml('Accounts'); ?>
+ +
getData('accGrpSelector')->render('iAccount', 'group', true); ?>
- +
@@ -112,19 +117,47 @@ echo $this->data['nav']->render(); ?>
getHtml('Accounts'); ?>
- +
+ - $value) : ++$c; $url = UriFactory::build('{/base}/admin/account/settings?{?}&id=' . $value->id); ?> - - +
getHtml('ID', '0', '0'); ?> getHtml('Name'); ?>
- name1; ?> name2; ?> + + $value) : ++$c; + $url = UriFactory::build('{/base}/admin/account/settings?{?}&id=' . $value->id); ?> +
+ + + + + + id; ?> + printHtml($value->login); ?> -
getHtml('Empty', '0', '0'); ?> +
getHtml('Empty', '0', '0'); ?>
@@ -268,8 +301,13 @@ echo $this->data['nav']->render(); ?>