AclUsage.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('Router');
  4. Lib::loadClass('Response');
  5. Lib::loadClass('UI');
  6. class Route_Storage_AclUsage extends RouteBase {
  7. public function handleAuth() {
  8. if (!User::logged()) {
  9. User::authByRequest();
  10. }
  11. }
  12. public function defaultAction() {
  13. UI::gora();
  14. UI::menu();
  15. UI::startContainer();
  16. try {
  17. $namespace = V::get('namespace', '', $_GET, 'word');
  18. if (!$namespace) {
  19. $typeName = V::get('typeName', '', $_GET, 'word');
  20. if (!$typeName) throw new Exception("Wrong param typeName");
  21. $namespace = Api_WfsNs::getBaseWfsUri() . '/' . str_replace(':', '/', $typeName);
  22. }
  23. $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
  24. $rootTableName = $acl->getRootTableName();
  25. $idTable = $acl->getID();
  26. echo UI::h('details', ['style'=>"margin-bottom:24px; padding:0 10px; background-color:#eee", 'open' => "open"], [
  27. UI::h('summary', ['style'=>"font-size:1.4em; line-height:2em; cursor:pointer; outline:none"], [
  28. "Uprawnienia obiektu '{$namespace}' ",
  29. // UI::h('small', ['style'=>"font-size:0.8em; font-style:italic; color:#aaa"], " więcej...")
  30. ]),
  31. UI::h('div', ['style'=>"padding:4px 24px; border-top:1px solid #fff"], [
  32. UI::h('p', [], "tabela: '{$rootTableName}'"),
  33. UI::h('p', [], "id zasobu: [{$idTable}]"),
  34. UI::h('p', [], [
  35. "struktura: ",
  36. ($acl instanceof AntAclBase)
  37. ? UI::h('a', [ 'href' => Router::getRoute('Storage_AclStruct')->getLink('', [ 'idStorage' => $acl->getDatabaseID(), 'namespace' => $acl->getNamespace() ]) ], "struktura obiektu (AntAcl)")
  38. : UI::h('a', [ 'href' => Router::getRoute('Storage_AclStruct')->getLink('tableStruct', [ 'idStorage' => $acl->getDatabaseID(), 'table' => $acl->getRootTableName() ]) ], "struktura tabeli (TableAcl)")
  39. ]),
  40. ])
  41. ]);
  42. if ($idTable > 0) {
  43. $aclTableRows = DB::getPDO()->fetchAll("select * from `CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW` where ID_TABLE = {$idTable}");
  44. UI::startTag('details');
  45. echo UI::h('summary', ['style'=>"cursor:pointer; margin-bottom:12px"], "Wszystkie powiązania komórek z procesami - szczegóły");
  46. UI::table([
  47. 'rows' => array_map(function ($row) {
  48. $splitPos = strpos($row['TABLE_DESCRIPTION'], ' ', 20);
  49. if ($splitPos > 30) $splitPos = 20;
  50. $row['TABLE_DESCRIPTION'] = UI::h('details', [], [
  51. UI::h('summary', [ 'style' => "white-space:nowrap" ], substr($row['TABLE_DESCRIPTION'], 0, $splitPos)),
  52. UI::h('p', [], substr($row['TABLE_DESCRIPTION'], $splitPos)),
  53. ]);
  54. return $row;
  55. }, $aclTableRows)
  56. ]);
  57. UI::endTag('details');
  58. $csvIdProces = array();
  59. foreach ($aclTableRows as $row) {
  60. if (!in_array($row['ID_PROCES'], $csvIdProces)) $csvIdProces[] = $row['ID_PROCES'];
  61. }
  62. }
  63. $databaseName = DB::getPDO( $acl->getDatabaseID() )->getDatabaseName();
  64. UI::table([
  65. 'caption' => "Powiązania komórek z procesem",
  66. 'rows' => array_map(
  67. function ($row) use ($aclTableRows, $idTable) {
  68. $fieldName = $row['COLUMN_NAME'];
  69. $item = [];
  70. $item['name'] = $fieldName;
  71. $item['typ'] = UI::h('details', [], [
  72. UI::h('summary', ['style'=>"cursor:pointer"], $row['DATA_TYPE']),
  73. UI::h('p', [], $row['COLUMN_TYPE']),
  74. ]);
  75. $item['w procesie'] = array();
  76. $item['id_zasob'] = 0;
  77. $item['PERM_R'] = 0;
  78. $item['PERM_W'] = 0;
  79. $item['PERM_X'] = 0;
  80. $item['PERM_C'] = 0;
  81. $item['PERM_S'] = 0;
  82. $item['PERM_O'] = 0;
  83. $item['PERM_V'] = 0;
  84. $item['PERM_E'] = 0;
  85. foreach ($aclTableRows as $aclInfo) {
  86. if (strtolower($aclInfo['CELL_NAME']) == strtolower($row['COLUMN_NAME'])) {
  87. $item['w procesie'][] = $aclInfo['ID_PROCES'];
  88. $item['id_zasob'] = $aclInfo['ID_CELL'];
  89. $item['PERM_R'] += $aclInfo['PERM_R'];
  90. $item['PERM_W'] += $aclInfo['PERM_W'];
  91. $item['PERM_X'] += $aclInfo['PERM_X'];
  92. $item['PERM_C'] += $aclInfo['PERM_C'];
  93. $item['PERM_S'] += $aclInfo['PERM_S'];
  94. $item['PERM_O'] += $aclInfo['PERM_O'];
  95. $item['PERM_V'] += $aclInfo['PERM_V'];
  96. $item['PERM_E'] += $aclInfo['PERM_E'];
  97. }
  98. }
  99. $item['w procesie'] = (empty($item['w procesie']))
  100. ? "<i style=\"color:red\">Brak</i>"
  101. : UI::h('span', ['style'=>"white-space:nowrap"], implode(", ", $item['w procesie']));
  102. 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");
  103. $item['id_zasob'] = ($item['id_zasob']) ? $item['id_zasob'] : UI::h('i', ['style'=>"color:silver"], "Brak");
  104. return $item;
  105. }, DB::getPDO()->fetchAll("
  106. select t.COLUMN_NAME, t.DATA_TYPE, t.COLUMN_TYPE
  107. from `information_schema`.`COLUMNS` t
  108. where t.TABLE_SCHEMA = '{$databaseName}'
  109. and t.TABLE_NAME like '{$rootTableName}'
  110. ")
  111. )
  112. ]);
  113. if (!empty($csvIdProces)) {
  114. $userLogin = User::getLogin();
  115. $csvIdProces = implode(",", $csvIdProces);
  116. UI::tag('h4', ['style'=>"margin-top:40px"], "Procesy dla '{$userLogin}': [{$csvIdProces}] <small><i>(z tabeli CRM_PROCES_idx_USER_to_PROCES_VIEW)</i></small>");
  117. $rows = DB::getPDO()->fetchAll("
  118. select ID_PROCES
  119. from `CRM_PROCES_idx_USER_to_PROCES_VIEW`
  120. where ADM_ACCOUNT = '{$userLogin}'
  121. and ID_PROCES in({$csvIdProces})
  122. group by ID_PROCES
  123. ");
  124. $userIdProces = array(); foreach ($rows as $row) $userIdProces[] = $row['ID_PROCES'];
  125. $userTablePerms = array();
  126. foreach ($aclTableRows as $row) {
  127. if (!in_array($row['ID_PROCES'], $userIdProces)) continue;
  128. if (array_key_exists($row['CELL_NAME'], $userTablePerms)) {
  129. $userTablePerms[ $row['CELL_NAME'] ]['w procesie'] .= ",{$row['ID_PROCES']}";
  130. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_R' ] += $row['PERM_R'];
  131. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_W' ] += $row['PERM_W'];
  132. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_X' ] += $row['PERM_X'];
  133. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_C' ] += $row['PERM_C'];
  134. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_S' ] += $row['PERM_S'];
  135. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_O' ] += $row['PERM_O'];
  136. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_V' ] += $row['PERM_V'];
  137. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_E' ] += $row['PERM_E'];
  138. } else {
  139. $userTablePerms[ $row['CELL_NAME'] ] = [
  140. 'fieldName' => $row['CELL_NAME'],
  141. 'zasob' => $row['ID_CELL'],
  142. 'w procesie' => "{$row['ID_PROCES']}",
  143. 'PERM_R' => $row['PERM_R'],
  144. 'PERM_W' => $row['PERM_W'],
  145. 'PERM_X' => $row['PERM_X'],
  146. 'PERM_C' => $row['PERM_C'],
  147. 'PERM_S' => $row['PERM_S'],
  148. 'PERM_O' => $row['PERM_O'],
  149. 'PERM_V' => $row['PERM_V'],
  150. 'PERM_E' => $row['PERM_E'],
  151. ];
  152. }
  153. }
  154. UI::table([
  155. 'caption' => "Uprawniena dla usera '{$userLogin}'",
  156. 'rows' => $userTablePerms
  157. ]);
  158. } else UI::alert('warning', "Brak przypisanych procesów");
  159. } catch (Exception $e) {
  160. UI::alert('danger', $e->getMessage());
  161. DBG::log($e);
  162. }
  163. UI::endContainer();
  164. UI::dol();
  165. }
  166. }