AclStruct.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('Router');
  4. Lib::loadClass('Response');
  5. Lib::loadClass('UI');
  6. Lib::loadClass('SchemaFactory');
  7. class Route_Storage_AclStruct extends RouteBase {
  8. public function handleAuth() {
  9. if (!User::logged()) {
  10. User::authByRequest();
  11. }
  12. }
  13. public function defaultAction() {
  14. UI::gora();
  15. UI::menu();
  16. // Router::getRoute('Storage')->navView(); // TODO: header like in Storage_AclUsage
  17. UI::startTag('div', [ 'class' => 'container-fluid' ]);
  18. try {
  19. $namespace = V::get('namespace', '', $_GET);
  20. if (empty($namespace)) throw new Exception("Missing param namespace");
  21. // [idZasob] => 25872
  22. // [idDatabase] => 36
  23. // [namespace] => default_db/CRM_PROCES/CRM_PROCES
  24. // [_rootTableName] => CRM_PROCES
  25. // [_type] => AntAcl
  26. // [hasStruct] => 1
  27. // [isStructInstalled] => 1
  28. // [isObjectActive] => 1
  29. // [description] =>
  30. // [name] => CRM_PROCES
  31. // [nsPrefix] => default_db__x3A__CRM_PROCES
  32. // [typeName] => default_db__x3A__CRM_PROCES:CRM_PROCES
  33. // [reinstallLink] => https://biuro.biall-net.pl/dev-pl/se-master/index.php?_route=Storage&_task=objectReinstall&namespace=default_db/CRM_PROCES/CRM_PROCES
  34. $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
  35. switch ($item['_type']) {
  36. case 'TableAcl': $this->tableStructView($item, $item['name'], $item['idDatabase']); break;
  37. case 'AntAcl': $this->objectStructView($item); break;
  38. default: throw new Exception("Not implemented type"); break;
  39. }
  40. } catch (Exception $e) {
  41. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  42. DBG::log($e);
  43. }
  44. UI::endTag('div'); // .container-fluid
  45. UI::dol();
  46. }
  47. public function tableStructAction() {
  48. UI::gora();
  49. UI::menu();
  50. // Router::getRoute('Storage')->navView(); // TODO: header like in Storage_AclUsage
  51. try {
  52. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  53. if (empty($idStorage)) throw new Exception("Missing id storage");
  54. $storageList = Router::getRoute('Storage')->getStorageList();
  55. if (empty($storageList)) throw new Exception("No storage defined");
  56. if (!array_key_exists($idStorage, $storageList)) throw new Exception("Storage not exists");
  57. $tblName = V::get('table', '', $_REQUEST, 'word');
  58. if (empty($tblName)) throw new Exception("No table name");
  59. $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
  60. $this->tableStructView($item, $tblName, $idStorage);
  61. } catch (Exception $e) {
  62. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  63. }
  64. UI::dol();
  65. }
  66. public function objectStructureAction() { // objectStructAction
  67. UI::gora();
  68. UI::menu();
  69. // Router::getRoute('Storage')->navView(); // TODO: header like in Storage_AclUsage
  70. UI::startTag('div', [ 'class' => 'container-fluid' ]);
  71. try {
  72. $namespace = V::get('namespace', '', $_GET);
  73. if (empty($namespace)) throw new Exception("Missing param namespace");
  74. $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
  75. $this->objectStructView($item);
  76. } catch (Exception $e) {
  77. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  78. DBG::log($e);
  79. }
  80. UI::endTag('div'); // .container-fluid
  81. UI::dol();
  82. }
  83. public function tableStructView($item, $tblName, $idStorage) {
  84. $storagePdo = DB::getStorage($idStorage);
  85. $tblStruct = $storagePdo->getTableStruct($tblName);
  86. $idTable = Router::getRoute('Storage')->fetchTableId($idStorage, $tblName);
  87. if ($idTable <= 0) {
  88. UI::alert('warning', "Zasob tabela '{$tblName}' nie istnieje");// TODO: add p5UI btn
  89. DBG::table("tblStruct", $tblStruct, __CLASS__, __FUNCTION__, __LINE__);
  90. throw new Exception("Zasob tabela '{$tblName}' nie istnieje");
  91. }
  92. $cellZasobList = array();
  93. foreach (DB::getPDO()->fetchAllByKey("
  94. select z.ID, z.`DESC`, z.`TYPE` as ZASOB_TYPE, z.A_STATUS
  95. from CRM_LISTA_ZASOBOW z
  96. where z.PARENT_ID = '{$idTable}'
  97. ", $key = 'DESC') as $ind => $row) {
  98. $cellZasobList[strtolower($ind)] = $row;
  99. }
  100. $emptyItem = array();
  101. $emptyItem['name'] = '';
  102. $emptyItem['id_zasob'] = '';
  103. $emptyItem['zasob_type'] = '';
  104. $emptyItem['uwagi'] = '';
  105. $emptyItem['type'] = '';
  106. $emptyItem['is_nullable'] = '';
  107. $emptyItem['default_value'] = '';
  108. $emptyItem['default_is_null'] = '';
  109. $emptyItem['max_length'] = '';
  110. $emptyItem['num_precision'] = '';
  111. $emptyItem['num_scale'] = '';
  112. $emptyItem['char_encoding'] = '';
  113. $emptyItem['char_collation'] = '';
  114. $emptyItem['extra'] = '';
  115. $emptyItem['raw_storage_type'] = '';
  116. $tableList = array();
  117. foreach ($tblStruct as $row) {
  118. $cellName = $row['name'];
  119. $tblItem = V::cloneArray($emptyItem);
  120. $tblItem['name'] = $cellName;
  121. foreach ($row as $fldName => $fldVal) {
  122. if (array_key_exists($fldName, $tblItem)) $tblItem[$fldName] = $fldVal;
  123. }
  124. $tblItem['uwagi'] = '';
  125. $lowerCellName = strtolower($cellName);
  126. $tblZasob = V::get($lowerCellName, '', $cellZasobList);
  127. if ($tblZasob) {
  128. $cellZasobList[$lowerCellName]['_checked'] = true;
  129. $tblItem['id_zasob'] = $tblZasob['ID'];
  130. $tblItem['zasob_type'] = $tblZasob['ZASOB_TYPE'];
  131. } else {
  132. $tblItem['uwagi'] .= '!Zasob';//'TODO: ADD ZASOB';
  133. $ajaxAddZasobLink = Router::getRoute('Storage')->getLink('addCellToZasoby', [ 'idStorage' => $idStorage, 'tblName' => $tblName, 'cellName' => $cellName]);
  134. $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addCellToZasoby', { href: '{$ajaxAddZasobLink}' })";
  135. $tblItem['id_zasob'] = '<a onclick="'.$onClick.'" class="btn btn-xs btn-primary" href="#">TODO: ADD ZASOB</a>';
  136. }
  137. $tableList[] = $tblItem;
  138. }
  139. foreach ($cellZasobList as $cellName => $row) {
  140. if ('URL_ACTION' == $row['ZASOB_TYPE']) continue;
  141. if (!$row['_checked']) {
  142. $tblItem = V::cloneArray($emptyItem);
  143. $tblItem['name'] = $cellName;
  144. $tblItem['id_zasob'] = $row['ID'];
  145. $tblItem['zasob_type'] = $row['ZASOB_TYPE'];
  146. $tblItem['uwagi'] = '!DB';//'TODO: nie istnieje w bazie danych';
  147. $tableList[] = $tblItem;
  148. }
  149. }
  150. usort($tableList, function($rowA, $rowB) {
  151. $a = $rowA['name']; $b = $rowB['name'];
  152. if ('ID' == $a) return -1;
  153. if ('ID' == $b) return 1;
  154. if ($a == $b) return 0;
  155. $a1 = substr($a, 0, 1); $b1 = substr($b, 0, 1);
  156. if (('_' == $a1 || '_' == $b1) && $a1 != $b1) {
  157. return ($a1 < $b1) ? 1 : -1;
  158. }
  159. return ($a < $b) ? -1 : 1;
  160. });
  161. UI::table([
  162. 'caption' => UI::h('span', [], [
  163. "Komórki [{$idTable}] ",
  164. UI::h('a', [
  165. 'href' => "index.php?_route=ViewTableAjax&namespace=default_db/{$tblName}",
  166. 'class' => "btn btn-md btn-link"
  167. ], "Przeglądaj tabelę"),
  168. UI::h('a', [
  169. 'href' => "procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id={$idTable}&filtr_ids=%2B&filtr_ob=%2B",
  170. 'class' => "btn btn-md btn-link",
  171. 'title' => "Struktura aktualnie przeglądanej tabeli"
  172. ], "Zasoby"),
  173. UI::h('a', [
  174. 'href' => "index.php?FUNCTION_INIT=PROCES_MENU&HEADER_NOT_INIT=YES&_task=PROCES_FOR_TABLE&tblId={$idTable}",
  175. 'class' => "btn btn-md btn-link",
  176. 'title' => "Procesy dla aktualnie przeglądanej tabeli"
  177. ], "Procesy"),
  178. UI::h('a', [
  179. 'href' => Router::getRoute('Storage_AclUsage')->getLink('', [ 'namespace' => "default_db/{$tblName}" ]),
  180. 'class' => "btn btn-md btn-link",
  181. 'title' => "Uprawnienia - analiza użycia komórek w procesach"
  182. ], "Uprawnienia (analiza użycia)"),
  183. ]),
  184. 'cols' => array_keys($emptyItem),
  185. 'rows' => $tableList
  186. ]);
  187. echo UI::h('script', [], "
  188. jQuery(document).on('p5UIBtnAjax:Storage:addCellToZasoby:click', function(e, n, payload) {
  189. console.log('event p5UIBtnAjax:Storage:addCellToZasoby:click', n, payload);
  190. });
  191. jQuery(document).on('p5UIBtnAjax:Storage:addCellToZasoby:ajaxLoaded', function(e, n, payload) {
  192. console.log('event p5UIBtnAjax:Storage:addCellToZasoby:ajaxLoaded', n, payload);
  193. if ('success' == payload.type && payload.body && payload.body.id > 0) {
  194. var cellUwagiJQNode = jQuery(n).parents('td').next('td');
  195. cellUwagiJQNode.text(cellUwagiJQNode.text().replace('!Zasob', ''))
  196. jQuery(n).parents('td').text(payload.body.id);
  197. jQuery(n).remove();
  198. }
  199. jQuery.notify(payload.msg, payload.type);
  200. });
  201. ");
  202. $ajaxAddZasobLink = Router::getRoute('Storage')->getLink('addGeomEtykietaCells', [ 'idStorage' => $idStorage, 'tblName' => $tblName]);
  203. $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addGeomEtykietaCells', { href: '{$ajaxAddZasobLink}' })";
  204. UI::tag('a', ['onclick'=>$onClick, 'class'=>"btn btn-xs btn-default", 'href'=>"#"], "Dodaj komórki etykiet", true);
  205. echo "<i>(<code>`etykieta_x`</code>, <code>`etykieta_y`</code>, <code>`etykieta_obrot`</code>)</i>";
  206. echo UI::h('script', [], "
  207. jQuery(document).on('p5UIBtnAjax:Storage:addGeomEtykietaCells:ajaxLoaded', function(e, n, payload) {
  208. console.log('event p5UIBtnAjax:Storage:addGeomEtykietaCells:ajaxLoaded', n, payload);
  209. if ('success' == payload.type && payload.body && payload.body.id > 0) {
  210. var cellUwagiJQNode = jQuery(n).parents('td').next('td');
  211. cellUwagiJQNode.text(cellUwagiJQNode.text().replace('!Zasob', ''))
  212. jQuery(n).parents('td').text(payload.body.id);
  213. jQuery(n).remove();
  214. }
  215. jQuery.notify(payload.msg, payload.type);
  216. });
  217. ");
  218. $tableActions = array_filter($cellZasobList, function ($row) {
  219. return ('URL_ACTION' == $row['ZASOB_TYPE']);
  220. });
  221. UI::table([
  222. 'caption' => "tableActions",
  223. // 'cols' => array_keys($emptyItem),
  224. 'rows' => array_map(function ($item) {
  225. $sqlIdAction = DB::getPDO()->quote($item['ID'], PDO::PARAM_INT);
  226. $args = DB::getPDO()->fetchAll("
  227. select z.`DESC`
  228. , a.ID as ALIAS_ID, a.`DESC` as ALIAS_DESC, a.OPIS as ALIAS_OPIS
  229. from CRM_LISTA_ZASOBOW z
  230. left join CRM_LISTA_ZASOBOW a on(a.ID = z.ALIAS_ID)
  231. where z.PARENT_ID = {$sqlIdAction}
  232. and z.`TYPE` = 'PARAM_IN'
  233. ");
  234. $definitionArgs = DB::getPDO()->fetchAll("
  235. select p.ID, p.`DESC`
  236. from CRM_LISTA_ZASOBOW z
  237. join CRM_LISTA_ZASOBOW d on(d.ID = z.ALIAS_ID)
  238. left join CRM_LISTA_ZASOBOW p on(p.PARENT_ID = d.ID)
  239. where z.ID = {$sqlIdAction}
  240. and p.`TYPE` = 'PARAM_IN'
  241. ");
  242. $flatDefinitionArgs = implode(";", array_map(function ($arg) {
  243. return "{$arg['ID']}={$arg['DESC']}";
  244. }, $definitionArgs));
  245. return [
  246. 'label' => DB::getPDO()->fetchValue(" select z.OPIS from CRM_LISTA_ZASOBOW z where z.ID = {$sqlIdAction} ") . " " .
  247. UI::h('i', [
  248. 'class' => "glyphicon glyphicon-pencil",
  249. 'style' => "cursor:pointer",
  250. 'onClick' => "return Storage__tableStruct__editActionLabel(this, {$sqlIdAction})"], ''),
  251. 'args' => implode("<br>&", array_map(function ($item) {
  252. return (NULL === $item['ALIAS_ID'])
  253. ? $item['DESC']
  254. : "{$item['DESC']}=" . '{$row["' . $item['ALIAS_DESC'] . '"]}';// TODO: add rmParam btn
  255. }, $args)) . " " .
  256. UI::h('i', [
  257. 'class' => "glyphicon glyphicon-plus-sign",
  258. 'style' => "cursor:pointer",
  259. 'title' => "Dodaj PARAM_IN",
  260. 'onClick' => "return Storage__tableStruct__addParamAction(this, {$sqlIdAction}, '{$flatDefinitionArgs}')"], ''),
  261. // 'args_info' => '<pre>' . var_export($args, true) . '</pre>',
  262. 'ID' => $item['ID'],
  263. 'DESC' => $item['DESC'],
  264. 'A_STATUS' => $item['A_STATUS'],
  265. 'definition args' => implode("", array_map(function ($item) {
  266. return '<div style="white-space:nowrap">' . "[{$item['ID']}] {$item['DESC']}" . '</div>';
  267. }, $definitionArgs)),
  268. ];
  269. }, $tableActions)
  270. ]);
  271. echo UI::h('button', [
  272. 'onClick'=>"Storage__tableStruct__addAction()",
  273. 'class'=>"btn btn-xs btn-default"
  274. ], "Dodaj Akcję");
  275. echo UI::h('link', ['rel'=>"stylesheet", 'type'=>"text/css", 'href'=>"static/sweetalert2.min.css"]);
  276. echo UI::h('script', ['src'=>"static/sweetalert2.min.js"]);
  277. echo UI::h('style', [], "
  278. .swal2-radio.p5-swal-radio-as-list { text-align:left }
  279. .swal2-radio.p5-swal-radio-as-list > label { display:block; margin-left:20px }
  280. ");
  281. UI::inlineJS(__FILE__ . '.tableActions.js', [
  282. 'ID_STORAGE' => $idStorage,
  283. 'TABLE_NAME' => $tblName,
  284. 'FETCH_URL' => Router::getRoute('Storage')->getLink('fetchActionListAjax'),
  285. 'ADD_ACTION_URL' => Router::getRoute('Storage')->getLink('addActionAjax')
  286. ]);
  287. echo '<hr>';
  288. $ajaxAddBaseProcesLink = Router::getRoute('Storage')->getLink('addTableBaseProces', [ 'idStorage' => $idStorage, 'tblName' => $tblName ]);
  289. $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addTableBaseProces', { href: '{$ajaxAddBaseProcesLink}' })";
  290. UI::tag('a', ['onclick'=>$onClick, 'class'=>"btn btn-xs btn-default", 'href'=>"#"], "Dodaj podstawowy proces dla tabeli '{$tblName}' - read only", true);
  291. echo UI::h('script', [], "
  292. jQuery(document).on('p5UIBtnAjax:Storage:addTableBaseProces:ajaxLoaded', function(e, n, payload) {
  293. jQuery.notify(payload.msg, payload.type);
  294. });
  295. ");
  296. }
  297. public function objectStructView($item) {
  298. $namespace = $item['namespace'];
  299. usort($item['field'], function ($a, $b) {
  300. if ($a['fieldNamespace'] > $b['fieldNamespace']) return 1;
  301. if ($a['fieldNamespace'] < $b['fieldNamespace']) return -1;
  302. return 0;
  303. });
  304. if ('setFieldRefConfig' === V::get('_postTask', '', $_POST)) {
  305. $field = V::get('field', '', $_POST);
  306. $source = V::get('source', '', $_POST);
  307. switch ($source) {
  308. case 'view':
  309. $refSelect = ACL::generateRefSelectSqlByFlatRelationCache($namespace, $field);
  310. ACL::setRefSource($namespace, $field, 'view', $refSelect);
  311. break;
  312. case 'table': ACL::setRefSource($namespace, $field, 'table'); break;
  313. }
  314. }
  315. if ('preview' === V::get('_postTask', '', $_POST)) {
  316. try {
  317. $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
  318. $localFields = array_filter($item['field'], function ($field) {
  319. return $field['isLocal'];
  320. });
  321. $refFields = array_filter($item['field'], function ($field) {
  322. return 'ref:' === substr($field['xsdType'], 0, 4);
  323. });
  324. $activeRefFields = array_filter($refFields, function ($field) {
  325. $refNamespace = str_replace(['__x3A__', ':'], '/', substr($field['xsdType'], strlen('ref:')));
  326. return (1 == DB::getPDO()->fetchValue("
  327. select t.isObjectActive
  328. from `CRM_#CACHE_ACL_OBJECT` t
  329. where t.`namespace` = '{$refNamespace}'
  330. "));
  331. });
  332. $previewItems = ACL::getAclByNamespace($namespace)->buildQuery([])->getItems([
  333. 'limit' => 5
  334. ]);
  335. DBG::nicePrint($previewItems, 'items (default query) - preview (limit 5)');
  336. $query = [ 'cols' => array_merge(
  337. array_map(
  338. function ($field) {
  339. return $field['fieldNamespace'];
  340. }, $localFields
  341. ),
  342. array_map(
  343. function ($field) {
  344. return "{$field['fieldNamespace']}/*";
  345. }, $activeRefFields
  346. )
  347. ) ];
  348. DBG::nicePrint($query, 'items with ref/* - query');
  349. $previewItems = ACL::getAclByNamespace($namespace)->buildQuery($query)->getItems([
  350. 'limit' => 5
  351. ]);
  352. DBG::nicePrint($previewItems, 'items with ref/* - preview (limit 5)');
  353. $query = [ 'cols' => array_merge(
  354. array_map(
  355. function ($field) {
  356. return $field['fieldNamespace'];
  357. }, $localFields
  358. ),
  359. array_map(
  360. function ($field) {
  361. return "{$field['fieldNamespace']}";
  362. }, $activeRefFields
  363. )
  364. ) ];
  365. DBG::nicePrint($query, 'items with ref as xlink - query');
  366. $previewItems = ACL::getAclByNamespace($namespace)->buildQuery($query)->getItems([
  367. 'limit' => 5
  368. ]);
  369. DBG::nicePrint($previewItems, 'items with ref as xlink - preview (limit 5)');
  370. } catch (Exception $e) {
  371. DBG::log($e);
  372. UI::alert('danger', $e->getMessage());
  373. }
  374. }
  375. echo UI::h('details', ['style'=>"margin-bottom:24px; padding:0 10px; background-color:#eee", 'open' => "open"], [
  376. UI::h('summary', ['style'=>"font-size:1.4em; line-height:2em; cursor:pointer; outline:none"], [
  377. "Struktura obiektu '{$namespace}' ",
  378. // UI::h('small', ['style'=>"font-size:0.8em; font-style:italic; color:#aaa"], " więcej...")
  379. ]),
  380. UI::h('div', ['style'=>"padding:4px 24px; border-top:1px solid #fff"], [
  381. UI::h('span', ['style'=>"margin-right:12px"], [
  382. ( ($item['idZasob'] > 0)
  383. ? UI::h('span', [ 'title' => "Nr zasobu '{$item['idZasob']}'" ], "Nr zasobu [{$item['idZasob']}]")
  384. : UI::h('span', [ 'title' => "Brak nr zasobu - dodaj do zasobów" ], [
  385. UI::hButtonAjax("+ do zasobów", 'addAclObjectToZasobyAjax', [
  386. 'class' => "btn btn-xs btn-primary",
  387. 'href' => Router::getRoute('Storage')->getLink('addAclObjectToZasobyAjax'),
  388. 'data' => [
  389. 'idStorage' => $item['idDatabase'],
  390. 'namespace' => $item['namespace'],
  391. ]
  392. ])
  393. ])
  394. ),
  395. ]),
  396. UI::h('span', ['style'=>"margin:0 12px"], [
  397. ( ($item['isObjectActive'] > 0)
  398. ? UI::h('span', [ 'class' => "label label-success", 'title' => "Namespace active" ], "Active")
  399. : UI::h('span', [ 'title' => "Namespace not active" ], [
  400. ($item['idZasob'] > 0)
  401. ? UI::hButtonAjax("Aktywuj", 'activateObjectAjax', [
  402. 'class' => "btn btn-xs btn-primary",
  403. 'href' => Router::getRoute('Storage')->getLink('activateObjectAjax'),
  404. 'data' => [
  405. 'namespace' => $item['namespace'],
  406. ]
  407. ])
  408. : '',
  409. ])
  410. ),
  411. ]),
  412. UI::h('a', [
  413. 'href' => "index.php?_route=ViewTableAjax&namespace={$item['namespace']}",
  414. 'class' => "btn btn-sm btn-link"
  415. ], "Przeglądaj tabelę"),
  416. ( ($item['idZasob'] > 0)
  417. ? UI::h('a', [
  418. 'href' => "procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id={$item['idZasob']}&filtr_ids=%2B&filtr_ob=%2B",
  419. 'class' => "btn btn-sm btn-link",
  420. 'title' => "Struktura tabeli w drzewie zasobów"
  421. ], "Zasoby")
  422. : ''
  423. ),
  424. ( ($item['idZasob'] > 0)
  425. ? UI::h('a', [
  426. 'href' => "index.php?FUNCTION_INIT=PROCES_MENU&HEADER_NOT_INIT=YES&_task=PROCES_FOR_TABLE&tblId={$item['idZasob']}",
  427. 'class' => "btn btn-sm btn-link",
  428. 'title' => "Procesy dla aktualnie przeglądanej tabeli"
  429. ], "Procesy")
  430. : ''
  431. ),
  432. UI::h('a', [
  433. 'href' => Router::getRoute('Storage')->getLink('objectReinstall', ['namespace' => $item['namespace']]),
  434. 'class' => 'btn btn-sm btn-link', 'style' => "color:#f00",
  435. 'title' => "Zainstaluje ponownie obiekt"
  436. ], "reinstall object"),
  437. UI::h('a', [
  438. 'href' => Router::getRoute('Storage_AclUsage')->getLink('', [ 'namespace' => $item['namespace'] ]),
  439. 'class' => "btn btn-sm btn-link",
  440. 'title' => "Uprawnienia - analiza użycia komórek w procesach"
  441. ], "Uprawnienia (analiza użycia)"),
  442. UI::hButtonPost("(podgląd z relacjami)", [
  443. 'data' => [
  444. '_postTask' => 'preview'
  445. ],
  446. 'class' => 'btn btn-sm btn-link', 'style' => "font-style:italic",
  447. 'title' => "Podgląd kilku ostatnich obiektów wraz z relacjami"
  448. ]),
  449. ])
  450. ]);
  451. $thisGetLink = [Router::getRoute('Storage'), 'getLink'];
  452. { // not installed ref
  453. $refFields = array_filter($item['field'], function ($field) {
  454. return 'ref:' === substr($field['xsdType'], 0, 4);
  455. });
  456. UI::table([
  457. 'caption' => UI::h('span', [], "Obiekty powiązane (TODO backRef)"),
  458. 'rows' => array_map(function ($field) use ($thisGetLink) {
  459. $refNamespace = str_replace(['__x3A__', ':'], '/', substr($field['xsdType'], strlen('ref:')));
  460. $isInstalled = (1 == DB::getPDO()->fetchValue("
  461. select t.isObjectActive
  462. from `CRM_#CACHE_ACL_OBJECT` t
  463. where t.`namespace` = '{$refNamespace}'
  464. "));
  465. $refSource = null;
  466. if ($isInstalled) {
  467. try {
  468. $refTable = ACL::getRefTable($field['objectNamespace'], $field['fieldNamespace']);
  469. DBG::log($refTable, 'array', "getRefTable('{$field['objectNamespace']}', '{$field['fieldNamespace']}')");
  470. $refSource = ACL::getRefSource($field['objectNamespace'], $field['fieldNamespace']);
  471. DBG::log($refSource, 'array', "ACL::getRefSource('{$field['objectNamespace']}', '{$field['fieldNamespace']}')");
  472. } catch (Exception $e) {
  473. DBG::log($e);
  474. }
  475. }
  476. return [
  477. 'fieldName' => $field['fieldNamespace'],
  478. // 'xsdType' => $field['xsdType'], // always === "ref:{$field['fieldNamespace']}"
  479. 'ref object' => UI::h('a', [
  480. 'class' => "btn btn-xs btn-link",
  481. 'href' => $thisGetLink('objectStruct', [ 'namespace' => $refNamespace ])
  482. ], "objectStruct ({$refNamespace})"),
  483. 'ref source' => UI::h('div', [],
  484. (null === $refSource)
  485. ? [ "ref object not installed" ] // TODO: link to install? is table struct
  486. : [
  487. // UI::hButtonAjax("Tabela ref", "setFieldRefConfig", [
  488. // 'class' => "btn btn-xs btn-default" . ( 'table' === $refSource ? ' disabled' : '' ),
  489. // 'href' => $thisGetLink('setFieldRefConfig'),
  490. // 'data' => [ 'namespace' => $refNamespace, 'field' => $field['fieldNamespace'], 'do' => 'table' ]
  491. // ]),
  492. // UI::hButtonAjax("Widok (cache)", "setFieldRefConfig", [
  493. // 'title' => "Według flat_relation_cache",
  494. // 'class' => "btn btn-xs btn-default" . ( 'view' === $refSource ? ' disabled' : '' ),
  495. // 'href' => $thisGetLink('setFieldRefConfig'),
  496. // 'data' => [ 'namespace' => $refNamespace, 'field' => $field['fieldNamespace'], 'do' => 'view' ]
  497. // ]),
  498. UI::hButtonPost("Tabela ref", [
  499. 'title' => "Według wygenerowanej tabeli REF",
  500. 'class' => "btn btn-xs btn-default" . ( 'table' === $refSource ? ' disabled' : '' ),
  501. // 'href' => $thisGetLink('setFieldRefConfig'),
  502. 'data' => [ 'namespace' => $refNamespace, 'field' => $field['fieldNamespace'], '_postTask' => 'setFieldRefConfig', 'source' => 'table' ]
  503. ]),
  504. UI::hButtonPost("Widok (cache)", [
  505. 'title' => "Według flat_relation_cache",
  506. 'class' => "btn btn-xs btn-default" . ( 'view' === $refSource ? ' disabled' : '' ),
  507. // 'href' => $thisGetLink('setFieldRefConfig'),
  508. 'data' => [ 'namespace' => $refNamespace, 'field' => $field['fieldNamespace'], '_postTask' => 'setFieldRefConfig', 'source' => 'view' ]
  509. ]),
  510. ]
  511. ),
  512. '@class' => ($isInstalled) ? "success" : "danger",
  513. ]; // TODO: link to install object
  514. }, $refFields)
  515. ]);
  516. }
  517. UI::table([
  518. 'caption' => UI::h('span', [], [
  519. UI::h('span', [ 'style' => "margin-right:6px;color:#000" ], "Struktura obiektu '{$item['namespace']}'"),
  520. ]),
  521. 'rows' => array_map(function ($field) use ($item, $thisGetLink) {
  522. $tblItem = []; foreach ($field as $k => $v) $tblItem[$k] = $v;
  523. $tblItem['namespace'] = UI::h('span', [], [
  524. UI::h('span', ['style' => "color:#aaa"], substr($field['namespace'], 0, strlen($field['objectNamespace']) + 1)),
  525. UI::h('span', ['style' => "color:#000"], substr($field['namespace'], strlen($field['objectNamespace']) + 1)),
  526. ]);
  527. $tblItem['idZasob'] = ($field['idZasob'] > 0)
  528. ? $field['idZasob']
  529. : (
  530. ($item['idZasob'] > 0)
  531. ? UI::hButtonAjax("+ do zasobów", 'addFieldToZasobyAjax', [
  532. 'class' => "btn btn-xs btn-primary",
  533. 'href' => $thisGetLink('addFieldToZasobyAjax'),
  534. 'data' => [
  535. 'namespace' => $item['namespace'],
  536. 'fieldNamespace' => $field['namespace'],
  537. ]
  538. ])
  539. : UI::h('span', ['title'=>"Brak Nr zasobu dla obiektu", 'class'=>"btn btn-xs btn-danger"], "Brak nr zasobu obiektu")
  540. )
  541. ;
  542. unset($tblItem['objectNamespace']);
  543. unset($tblItem['fieldNamespace']);
  544. return $tblItem;
  545. }, $item['field'])
  546. ]);
  547. UI::hButtonAjaxOnResponse('addFieldToZasobyAjax', /* payload, n */ "
  548. if (!payload.type) return false
  549. if (payload.body && payload.body.id && payload.body.id > 0) { // if ('success' == payload.type) {
  550. n.parentNode.replaceChild(document.createTextNode(payload.body.id), n)
  551. }
  552. jQuery.notify(payload.msg, payload.type)
  553. ");
  554. UI::hButtonAjaxOnResponse('addAclObjectToZasobyAjax', /* payload, n */ "
  555. if (!payload.type) return false
  556. if ('success' === payload.type || 'info' === payload.type) {
  557. if (payload.body && payload.body.id && payload.body.id > 0) {
  558. n.parentNode.replaceChild(document.createTextNode(payload.body.id), n)
  559. } else {
  560. console.log('TODO: addAclObjectToZasobyAjax unknown response', payload);
  561. }
  562. window.location.reload()
  563. }
  564. ");
  565. UI::hButtonAjaxOnResponse('activateObjectAjax', /* payload, n */ "
  566. jQuery.notify(payload.msg, payload.type)
  567. if (!payload.type) return false
  568. if ('success' === payload.type || 'info' === payload.type) {
  569. if (payload.body && payload.body.isObjectActive && payload.body.isObjectActive > 0) {
  570. n.parentNode.replaceChild(document.createTextNode('Active'), n)
  571. } else {
  572. console.log('TODO: activateObjectAjax unknown response', payload);
  573. }
  574. }
  575. ");
  576. if ($item['isObjectActive']) {
  577. echo UI::hButtonAjax("Dodaj podstawowy proces dla obiektu '{$item['namespace']}' - read only (TODO)", 'addObjectBaseProcesAjax', [
  578. 'class' => "btn btn-xs btn-default",
  579. 'href' => Router::getRoute('Storage')->getLink('addObjectBaseProcesAjax'),
  580. 'data' => [ 'namespace' => $item['namespace'] ]
  581. ]);
  582. UI::hButtonAjaxOnResponse('addObjectBaseProcesAjax', /* payload, n */ "
  583. jQuery.notify(payload.msg, payload.type)
  584. ");
  585. }
  586. DBG::nicePrint($item, '$item');
  587. }
  588. }