| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <?php
- Lib::loadClass('RouteBase');
- Lib::loadClass('Router');
- Lib::loadClass('Response');
- Lib::loadClass('UI');
- class Route_Storage_AclUsage extends RouteBase {
- public function handleAuth() {
- if (!User::logged()) {
- User::authByRequest();
- }
- }
- public function defaultAction() {
- UI::gora();
- UI::menu();
- UI::startContainer();
- try {
- $namespace = V::get('namespace', '', $_GET, 'word');
- if (!$namespace) {
- $typeName = V::get('typeName', '', $_GET, 'word');
- if (!$typeName) throw new Exception("Wrong param typeName");
- $namespace = Api_WfsNs::getBaseWfsUri() . '/' . str_replace(':', '/', $typeName);
- }
- $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
- $rootTableName = $acl->getRootTableName();
- $idTable = $acl->getID();
- echo UI::h('details', ['style'=>"margin-bottom:24px; padding:0 10px; background-color:#eee", 'open' => "open"], [
- UI::h('summary', ['style'=>"font-size:1.4em; line-height:2em; cursor:pointer; outline:none"], [
- "Uprawnienia obiektu '{$namespace}' ",
- // UI::h('small', ['style'=>"font-size:0.8em; font-style:italic; color:#aaa"], " więcej...")
- ]),
- UI::h('div', ['style'=>"padding:4px 24px; border-top:1px solid #fff"], [
- UI::h('p', [], "tabela: '{$rootTableName}'"),
- UI::h('p', [], "id zasobu: [{$idTable}]"),
- UI::h('p', [], [
- "struktura: ",
- ($acl instanceof AntAclBase)
- ? UI::h('a', [ 'href' => Router::getRoute('Storage_AclStruct')->getLink('', [ 'idStorage' => $acl->getDatabaseID(), 'namespace' => $acl->getNamespace() ]) ], "struktura obiektu (AntAcl)")
- : UI::h('a', [ 'href' => Router::getRoute('Storage_AclStruct')->getLink('tableStruct', [ 'idStorage' => $acl->getDatabaseID(), 'table' => $acl->getRootTableName() ]) ], "struktura tabeli (TableAcl)")
- ]),
- UI::h('p', [], [
- "dodaj proces: ",
- UI::hButtonAjax("Dodaj podstawowy proces - read only (TODO)", 'addObjectBaseProcesAjax', [
- 'title' => "Dodaj podstawowy proces dla obiektu '{$namespace}' - read only (TODO)",
- 'class' => "btn btn-xs btn-default",
- 'href' => Router::getRoute('Storage')->getLink('addObjectBaseProcesAjax'),
- 'data' => [ 'namespace' => $namespace ]
- ]),
- " ",
- UI::hButtonAjax("TODO edytor procesu", 'todoGotoProcesEditorAjax', [
- 'title' => "Otwórz edytor procesu dla obiektu '{$namespace}'",
- 'class' => "btn btn-xs btn-warning",
- 'href' => Router::getRoute('Storage')->getLink('addObjectBaseProcesAjax'),
- 'data' => [ 'namespace' => $namespace ]
- ]),
- ]),
- ])
- ]);
- UI::hButtonAjaxOnResponse('addObjectBaseProcesAjax', /* payload, n */ "
- jQuery.notify(payload.msg, payload.type)
- ");
- UI::hButtonAjaxOnResponse('todoGotoProcesEditorAjax', /* payload, n */ "
- jQuery.notify('TODO: edytor procesu', 'error')
- ");
- if ($idTable > 0) {
- $aclTableRows = DB::getPDO()->fetchAll("select * from `CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW` where ID_TABLE = {$idTable}");
- UI::startTag('details');
- echo UI::h('summary', ['style'=>"cursor:pointer; margin-bottom:12px"], "Wszystkie powiązania komórek z procesami - szczegóły");
- UI::table([
- 'rows' => array_map(function ($row) {
- $splitPos = (strlen($row['TABLE_DESCRIPTION']) > 20) ? strpos($row['TABLE_DESCRIPTION'], ' ', 20) : 20;
- if ($splitPos > 30) $splitPos = 20;
- $row['TABLE_DESCRIPTION'] = UI::h('details', [], [
- UI::h('summary', [ 'style' => "white-space:nowrap" ], substr($row['TABLE_DESCRIPTION'], 0, $splitPos)),
- UI::h('p', [], substr($row['TABLE_DESCRIPTION'], $splitPos)),
- ]);
- return $row;
- }, $aclTableRows)
- ]);
- UI::endTag('details');
- $csvIdProces = array();
- foreach ($aclTableRows as $row) {
- if (!in_array($row['ID_PROCES'], $csvIdProces)) $csvIdProces[] = $row['ID_PROCES'];
- }
- }
- $databaseName = DB::getPDO( $acl->getDatabaseID() )->getDatabaseName();
- UI::table([
- 'caption' => "Powiązania komórek z procesem",
- 'rows' => array_map(
- function ($row) use ($aclTableRows, $idTable) {
- $fieldName = $row['COLUMN_NAME'];
- $item = [];
- $item['name'] = $fieldName;
- $item['typ'] = UI::h('details', [], [
- UI::h('summary', ['style'=>"cursor:pointer"], $row['DATA_TYPE']),
- UI::h('p', [], $row['COLUMN_TYPE']),
- ]);
- $item['w procesie'] = array();
- $item['id_zasob'] = 0;
- $item['PERM_R'] = 0;
- $item['PERM_W'] = 0;
- $item['PERM_X'] = 0;
- $item['PERM_C'] = 0;
- $item['PERM_S'] = 0;
- $item['PERM_O'] = 0;
- $item['PERM_V'] = 0;
- $item['PERM_E'] = 0;
- foreach ($aclTableRows as $aclInfo) {
- if (strtolower($aclInfo['CELL_NAME']) == strtolower($row['COLUMN_NAME'])) {
- $item['w procesie'][] = $aclInfo['ID_PROCES'];
- $item['id_zasob'] = $aclInfo['ID_CELL'];
- $item['PERM_R'] += $aclInfo['PERM_R'];
- $item['PERM_W'] += $aclInfo['PERM_W'];
- $item['PERM_X'] += $aclInfo['PERM_X'];
- $item['PERM_C'] += $aclInfo['PERM_C'];
- $item['PERM_S'] += $aclInfo['PERM_S'];
- $item['PERM_O'] += $aclInfo['PERM_O'];
- $item['PERM_V'] += $aclInfo['PERM_V'];
- $item['PERM_E'] += $aclInfo['PERM_E'];
- }
- }
- $item['w procesie'] = (empty($item['w procesie']))
- ? "<i style=\"color:red\">Brak</i>"
- : UI::h('span', ['style'=>"white-space:nowrap"], implode(", ", $item['w procesie']));
- if (!$item['id_zasob']) $item['id_zasob'] = DB::getPDO()->fetchValue("select ID from CRM_LISTA_ZASOBOW where `DESC` = '{$fieldName}' and PARENT_ID = {$idTable} limit 1");
- $item['id_zasob'] = ($item['id_zasob']) ? $item['id_zasob'] : UI::h('i', ['style'=>"color:silver"], "Brak");
- return $item;
- }, DB::getPDO()->fetchAll("
- select t.COLUMN_NAME, t.DATA_TYPE, t.COLUMN_TYPE
- from `information_schema`.`COLUMNS` t
- where t.TABLE_SCHEMA = '{$databaseName}'
- and t.TABLE_NAME like '{$rootTableName}'
- ")
- )
- ]);
- if (!empty($csvIdProces)) {
- $userLogin = User::getLogin();
- $csvIdProces = implode(",", $csvIdProces);
- UI::tag('h4', ['style'=>"margin-top:40px"], "Procesy dla '{$userLogin}': [{$csvIdProces}] <small><i>(z tabeli CRM_PROCES_idx_USER_to_PROCES_VIEW)</i></small>");
- $rows = DB::getPDO()->fetchAll("
- select ID_PROCES
- from `CRM_PROCES_idx_USER_to_PROCES_VIEW`
- where ADM_ACCOUNT = '{$userLogin}'
- and ID_PROCES in({$csvIdProces})
- group by ID_PROCES
- ");
- $userIdProces = array(); foreach ($rows as $row) $userIdProces[] = $row['ID_PROCES'];
- $userTablePerms = array();
- foreach ($aclTableRows as $row) {
- if (!in_array($row['ID_PROCES'], $userIdProces)) continue;
- if (array_key_exists($row['CELL_NAME'], $userTablePerms)) {
- $userTablePerms[ $row['CELL_NAME'] ]['w procesie'] .= ",{$row['ID_PROCES']}";
- $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_R' ] += $row['PERM_R'];
- $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_W' ] += $row['PERM_W'];
- $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_X' ] += $row['PERM_X'];
- $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_C' ] += $row['PERM_C'];
- $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_S' ] += $row['PERM_S'];
- $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_O' ] += $row['PERM_O'];
- $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_V' ] += $row['PERM_V'];
- $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_E' ] += $row['PERM_E'];
- } else {
- $userTablePerms[ $row['CELL_NAME'] ] = [
- 'fieldName' => $row['CELL_NAME'],
- 'zasob' => $row['ID_CELL'],
- 'w procesie' => "{$row['ID_PROCES']}",
- 'PERM_R' => $row['PERM_R'],
- 'PERM_W' => $row['PERM_W'],
- 'PERM_X' => $row['PERM_X'],
- 'PERM_C' => $row['PERM_C'],
- 'PERM_S' => $row['PERM_S'],
- 'PERM_O' => $row['PERM_O'],
- 'PERM_V' => $row['PERM_V'],
- 'PERM_E' => $row['PERM_E'],
- ];
- }
- }
- UI::table([
- 'caption' => "Uprawniena dla usera '{$userLogin}'",
- 'rows' => $userTablePerms
- ]);
- } else UI::alert('warning', "Brak przypisanych procesów");
- } catch (Exception $e) {
- UI::alert('danger', $e->getMessage());
- DBG::log($e);
- }
- UI::endContainer();
- UI::dol();
- }
- }
|