getRootTableName(); $idTable = $acl->getID(); $aclNamespace = $acl->getNamespace(); $idDatabase = $acl->getDatabaseID(); } catch (Exception $e) { DBG::log($e); } if (!$aclNamespace) { try { $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]); $rootTableName = $item['_rootTableName']; $idTable = $item['idZasob']; $aclNamespace = $item['namespace']; } catch (Exception $e) { DBG::log($e); } } if (!$aclNamespace) throw new Exception("Object not found '{$namespace}'"); if (!$rootTableName) throw new Exception("Missing rootTableName"); if (!$idTable) throw new Exception("Missing idTable"); $renderProcesLink = function ($idProces) { return UI::h('a', [ 'href' => "procesy5.php?task=CRM_PROCES&filtr_id={$idProces}", 'class' => "btn btn-xs btn-link", 'style' => "padding:0", ], "{$idProces}"); }; $renderPermCell = function ($value) { return ($value) ? UI::h('span', [ 'class' => "label label-success" ], (string)$value) : UI::h('span', [ 'class' => "label label-danger" ], (string)$value); }; $permCols = [ 'PERM_R', 'PERM_W', 'PERM_X', 'PERM_C', 'PERM_S', 'PERM_O', 'PERM_V', 'PERM_E' ]; $labelPermCols = [ 'PERM_R' => 'R', 'PERM_W' => 'W', 'PERM_X' => 'X', 'PERM_C' => 'C', 'PERM_S' => 'S', 'PERM_O' => 'O', 'PERM_V' => 'V', 'PERM_E' => 'E' ]; $helpPermCols = [ 'PERM_R' => 'Odczyt', 'PERM_W' => 'Zapis', 'PERM_X' => 'Wykonanie', 'PERM_C' => 'Tworzenie', 'PERM_S' => 'Zapis pomimo braku uprawnień do rekordu', 'PERM_O' => 'Tylko własne dane', 'PERM_V' => 'Odczyt pomimo braku uprawnień do rekordu', 'PERM_E' => 'Export', ]; 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' => $idDatabase, 'namespace' => $aclNamespace ]) ], "struktura obiektu (AntAcl)") : UI::h('a', [ 'href' => Router::getRoute('Storage_AclStruct')->getLink('tableStruct', [ 'idStorage' => $idDatabase, 'table' => $rootTableName ]) ], "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([ 'cols_label' => $labelPermCols, 'cols_help' => $helpPermCols, 'rows' => array_map(function ($row) use ($renderProcesLink, $renderPermCell, $permCols) { $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)), ]); $row['ID_PROCES'] = $renderProcesLink($row['ID_PROCES']); foreach ($permCols as $colPerm) $row[ $colPerm ] = $renderPermCell( $row[$colPerm] ); 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( $idDatabase )->getDatabaseName(); UI::table([ 'caption' => "Powiązania komórek z procesem", 'cols_label' => $labelPermCols, 'cols_help' => $helpPermCols, 'rows' => array_map( function ($row) use ($aclTableRows, $idTable, $renderProcesLink, $renderPermCell, $permCols) { $fieldName = $row['COLUMN_NAME']; $item = [ 'name' => $fieldName, 'typ' => UI::h('details', [], [ UI::h('summary', ['style'=>"cursor:pointer"], $row['DATA_TYPE']), UI::h('p', [], $row['COLUMN_TYPE']), ]), 'w procesie' => [], 'idZasob' => 0, ]; foreach ($permCols as $colPerm) $item[$colPerm] = ''; foreach ($aclTableRows as $aclInfo) { if (strtolower($aclInfo['CELL_NAME']) == strtolower($row['COLUMN_NAME'])) { $item['w procesie'][] = $aclInfo['ID_PROCES']; $item['idZasob'] = $aclInfo['ID_CELL']; foreach ($permCols as $colPerm) $item[$colPerm] += $aclInfo[$colPerm]; } } $item['w procesie'] = (empty($item['w procesie'])) ? "Brak" : UI::h('span', ['style'=>"white-space:nowrap"], implode(", ", array_map($renderProcesLink, $item['w procesie']))); if (!$item['idZasob']) $item['idZasob'] = DB::getPDO()->fetchValue("select ID from CRM_LISTA_ZASOBOW where `DESC` = '{$fieldName}' and PARENT_ID = {$idTable} limit 1"); $item['idZasob'] = ($item['idZasob']) ? $item['idZasob'] : UI::h('i', ['style'=>"color:silver"], "Brak"); foreach ($permCols as $colPerm) $item[$colPerm] = $renderPermCell($item[$colPerm]); 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}] (z tabeli CRM_PROCES_idx_USER_to_PROCES_VIEW)"); $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 "); if (empty($rows)) UI::alert('warning', "Brak danych"); $userIdProces = array_map( V::makePick('ID_PROCES', 0, 'int'), $rows ); $userTablePerms = array_reduce($aclTableRows, function ($ret, $row) use ($userIdProces, $permCols) { $idProces = (int)$row['ID_PROCES']; if (!$idProces) return $ret; if (!in_array($idProces, $userIdProces)) return $ret; if (!array_key_exists($row['CELL_NAME'], $ret)) { $ret[ $row['CELL_NAME'] ] = [ 'fieldName' => $row['CELL_NAME'], 'idZasob' => $row['ID_CELL'], 'w procesie' => [], ]; foreach ($permCols as $colPerm) $ret[ $row['CELL_NAME'] ][ $colPerm ] = ''; } $ret[ $row['CELL_NAME'] ]['w procesie'] []= $row['ID_PROCES']; foreach ($permCols as $colPerm) $ret[ $row['CELL_NAME'] ][ $colPerm ] += $row[ $colPerm ]; return $ret; }, []); UI::table([ 'caption' => "Uprawniena dla usera '{$userLogin}'", 'cols_label' => $labelPermCols, 'cols_help' => $helpPermCols, 'rows' => array_map(function ($item) use ($renderProcesLink, $renderPermCell, $permCols) { sort($item['w procesie']); $item['w procesie'] = array_unique($item['w procesie'], SORT_NUMERIC); $item['w procesie'] = implode(", ", array_map($renderProcesLink, $item['w procesie'])); foreach ($permCols as $colPerm) $item[$colPerm] = $renderPermCell($item[$colPerm]); return $item; }, $userTablePerms), ]); } else UI::alert('warning', "Brak przypisanych procesów"); } catch (Exception $e) { UI::alert('danger', $e->getMessage()); DBG::log($e); } UI::endContainer(); UI::dol(); } }