AclUsage.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. UI::h('p', [], [
  41. "dodaj proces: ",
  42. UI::hButtonAjax("Dodaj podstawowy proces - read only (TODO)", 'addObjectBaseProcesAjax', [
  43. 'title' => "Dodaj podstawowy proces dla obiektu '{$namespace}' - read only (TODO)",
  44. 'class' => "btn btn-xs btn-default",
  45. 'href' => Router::getRoute('Storage')->getLink('addObjectBaseProcesAjax'),
  46. 'data' => [ 'namespace' => $namespace ]
  47. ]),
  48. " ",
  49. UI::hButtonAjax("TODO edytor procesu", 'todoGotoProcesEditorAjax', [
  50. 'title' => "Otwórz edytor procesu dla obiektu '{$namespace}'",
  51. 'class' => "btn btn-xs btn-warning",
  52. 'href' => Router::getRoute('Storage')->getLink('addObjectBaseProcesAjax'),
  53. 'data' => [ 'namespace' => $namespace ]
  54. ]),
  55. ]),
  56. ])
  57. ]);
  58. UI::hButtonAjaxOnResponse('addObjectBaseProcesAjax', /* payload, n */ "
  59. jQuery.notify(payload.msg, payload.type)
  60. ");
  61. UI::hButtonAjaxOnResponse('todoGotoProcesEditorAjax', /* payload, n */ "
  62. jQuery.notify('TODO: edytor procesu', 'error')
  63. ");
  64. if ($idTable > 0) {
  65. $aclTableRows = DB::getPDO()->fetchAll("select * from `CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW` where ID_TABLE = {$idTable}");
  66. UI::startTag('details');
  67. echo UI::h('summary', ['style'=>"cursor:pointer; margin-bottom:12px"], "Wszystkie powiązania komórek z procesami - szczegóły");
  68. UI::table([
  69. 'rows' => array_map(function ($row) {
  70. $splitPos = (strlen($row['TABLE_DESCRIPTION']) > 20) ? strpos($row['TABLE_DESCRIPTION'], ' ', 20) : 20;
  71. if ($splitPos > 30) $splitPos = 20;
  72. $row['TABLE_DESCRIPTION'] = UI::h('details', [], [
  73. UI::h('summary', [ 'style' => "white-space:nowrap" ], substr($row['TABLE_DESCRIPTION'], 0, $splitPos)),
  74. UI::h('p', [], substr($row['TABLE_DESCRIPTION'], $splitPos)),
  75. ]);
  76. return $row;
  77. }, $aclTableRows)
  78. ]);
  79. UI::endTag('details');
  80. $csvIdProces = array();
  81. foreach ($aclTableRows as $row) {
  82. if (!in_array($row['ID_PROCES'], $csvIdProces)) $csvIdProces[] = $row['ID_PROCES'];
  83. }
  84. }
  85. $databaseName = DB::getPDO( $acl->getDatabaseID() )->getDatabaseName();
  86. UI::table([
  87. 'caption' => "Powiązania komórek z procesem",
  88. 'rows' => array_map(
  89. function ($row) use ($aclTableRows, $idTable) {
  90. $fieldName = $row['COLUMN_NAME'];
  91. $item = [];
  92. $item['name'] = $fieldName;
  93. $item['typ'] = UI::h('details', [], [
  94. UI::h('summary', ['style'=>"cursor:pointer"], $row['DATA_TYPE']),
  95. UI::h('p', [], $row['COLUMN_TYPE']),
  96. ]);
  97. $item['w procesie'] = array();
  98. $item['id_zasob'] = 0;
  99. $item['PERM_R'] = 0;
  100. $item['PERM_W'] = 0;
  101. $item['PERM_X'] = 0;
  102. $item['PERM_C'] = 0;
  103. $item['PERM_S'] = 0;
  104. $item['PERM_O'] = 0;
  105. $item['PERM_V'] = 0;
  106. $item['PERM_E'] = 0;
  107. foreach ($aclTableRows as $aclInfo) {
  108. if (strtolower($aclInfo['CELL_NAME']) == strtolower($row['COLUMN_NAME'])) {
  109. $item['w procesie'][] = $aclInfo['ID_PROCES'];
  110. $item['id_zasob'] = $aclInfo['ID_CELL'];
  111. $item['PERM_R'] += $aclInfo['PERM_R'];
  112. $item['PERM_W'] += $aclInfo['PERM_W'];
  113. $item['PERM_X'] += $aclInfo['PERM_X'];
  114. $item['PERM_C'] += $aclInfo['PERM_C'];
  115. $item['PERM_S'] += $aclInfo['PERM_S'];
  116. $item['PERM_O'] += $aclInfo['PERM_O'];
  117. $item['PERM_V'] += $aclInfo['PERM_V'];
  118. $item['PERM_E'] += $aclInfo['PERM_E'];
  119. }
  120. }
  121. $item['w procesie'] = (empty($item['w procesie']))
  122. ? "<i style=\"color:red\">Brak</i>"
  123. : UI::h('span', ['style'=>"white-space:nowrap"], implode(", ", $item['w procesie']));
  124. 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");
  125. $item['id_zasob'] = ($item['id_zasob']) ? $item['id_zasob'] : UI::h('i', ['style'=>"color:silver"], "Brak");
  126. return $item;
  127. }, DB::getPDO()->fetchAll("
  128. select t.COLUMN_NAME, t.DATA_TYPE, t.COLUMN_TYPE
  129. from `information_schema`.`COLUMNS` t
  130. where t.TABLE_SCHEMA = '{$databaseName}'
  131. and t.TABLE_NAME like '{$rootTableName}'
  132. ")
  133. )
  134. ]);
  135. if (!empty($csvIdProces)) {
  136. $userLogin = User::getLogin();
  137. $csvIdProces = implode(",", $csvIdProces);
  138. UI::tag('h4', ['style'=>"margin-top:40px"], "Procesy dla '{$userLogin}': [{$csvIdProces}] <small><i>(z tabeli CRM_PROCES_idx_USER_to_PROCES_VIEW)</i></small>");
  139. $rows = DB::getPDO()->fetchAll("
  140. select ID_PROCES
  141. from `CRM_PROCES_idx_USER_to_PROCES_VIEW`
  142. where ADM_ACCOUNT = '{$userLogin}'
  143. and ID_PROCES in({$csvIdProces})
  144. group by ID_PROCES
  145. ");
  146. $userIdProces = array(); foreach ($rows as $row) $userIdProces[] = $row['ID_PROCES'];
  147. $userTablePerms = array();
  148. foreach ($aclTableRows as $row) {
  149. if (!in_array($row['ID_PROCES'], $userIdProces)) continue;
  150. if (array_key_exists($row['CELL_NAME'], $userTablePerms)) {
  151. $userTablePerms[ $row['CELL_NAME'] ]['w procesie'] .= ",{$row['ID_PROCES']}";
  152. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_R' ] += $row['PERM_R'];
  153. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_W' ] += $row['PERM_W'];
  154. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_X' ] += $row['PERM_X'];
  155. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_C' ] += $row['PERM_C'];
  156. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_S' ] += $row['PERM_S'];
  157. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_O' ] += $row['PERM_O'];
  158. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_V' ] += $row['PERM_V'];
  159. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_E' ] += $row['PERM_E'];
  160. } else {
  161. $userTablePerms[ $row['CELL_NAME'] ] = [
  162. 'fieldName' => $row['CELL_NAME'],
  163. 'zasob' => $row['ID_CELL'],
  164. 'w procesie' => "{$row['ID_PROCES']}",
  165. 'PERM_R' => $row['PERM_R'],
  166. 'PERM_W' => $row['PERM_W'],
  167. 'PERM_X' => $row['PERM_X'],
  168. 'PERM_C' => $row['PERM_C'],
  169. 'PERM_S' => $row['PERM_S'],
  170. 'PERM_O' => $row['PERM_O'],
  171. 'PERM_V' => $row['PERM_V'],
  172. 'PERM_E' => $row['PERM_E'],
  173. ];
  174. }
  175. }
  176. UI::table([
  177. 'caption' => "Uprawniena dla usera '{$userLogin}'",
  178. 'rows' => $userTablePerms
  179. ]);
  180. } else UI::alert('warning', "Brak przypisanych procesów");
  181. } catch (Exception $e) {
  182. UI::alert('danger', $e->getMessage());
  183. DBG::log($e);
  184. }
  185. UI::endContainer();
  186. UI::dol();
  187. }
  188. }