Storage.php 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810
  1. <?php
  2. // @requires $_SERVER['SERVER_NAME']
  3. Lib::loadClass('RouteBase');
  4. Lib::loadClass('Schema_TableFactory');
  5. Lib::loadClass('Response');
  6. Lib::loadClass('UI');
  7. Lib::loadClass('OBJ');
  8. Lib::loadClass('SchemaFactory');
  9. /*
  10. # Storage:
  11. - [x] view available storage (from Zasoby - type 'BAZA_DANYCH', 'DATABASE_MYSQL', ...)
  12. - [x] check config for connection
  13. - [x] add cells to Zasoby
  14. - [ ] create cells in Storage
  15. - [x] use PDO
  16. */
  17. class Route_Storage extends RouteBase {
  18. public function handleAuth() {
  19. if (!User::logged()) {
  20. User::authByRequest();
  21. }
  22. }
  23. public function defaultAction() {
  24. UI::gora();
  25. UI::menu();
  26. $this->navView();
  27. UI::startContainer();
  28. try {
  29. $sourceStorage = SchemaFactory::loadDefaultObject('SystemSource');
  30. try {
  31. $sourceStorage->getTotal();
  32. } catch (Exception $e) {
  33. UI::alert('warning', $e->getMessage());
  34. $sourceStorage->updateCache();
  35. UI::alert('info', "Lista dostępnych baz danych zaktualizowana");
  36. }
  37. if ('1' == V::get('refreshSourceList', '', $_POST)) {
  38. $sourceStorage->updateCache();
  39. UI::alert('info', "Lista dostępnych baz danych zaktualizowana");
  40. }
  41. UI::table([
  42. 'caption' => "Bazy danych " .
  43. UI::hButtonPost('<i class="glyphicon glyphicon-refresh"></i>' . " odśwież", [
  44. 'class' => "btn btn-xs btn-link",
  45. 'data' => [
  46. 'refreshSourceList' => '1'
  47. ]
  48. ]),
  49. 'rows' => array_merge(
  50. array_map(function ($item) {
  51. return [
  52. 'Nr zasobu' => $item['idZasob'],
  53. 'nazwa' => $item['name'],
  54. 'opis' => $item['description'],
  55. 'config?' => ($item['hasConfig']) ? '<span class="label label-success">TAK</span>' : '<span class="text text-muted">brak</span>',
  56. 'obiekty' => UI::h('a', [ 'href' => $this->getLink('tableList', [ 'idStorage' => $item['idZasob'] ]) ], "obiekty"),
  57. 'raw info' => UI::h('a', [ 'href' => $this->getLink('rawInfo', [ 'idStorage' => $item['idZasob'] ]) ], "raw info"),
  58. 'xsd' => UI::h('a', [ 'href' => $this->getLink('xsd', [ 'idStorage' => $item['idZasob'] ]) ], "xsd"),
  59. ];
  60. }, $sourceStorage->getItems())
  61. , [
  62. [
  63. 'Nr zasobu' => '',
  64. 'nazwa' => "Obiekty",
  65. 'opis' => "SystemObjects",
  66. 'config?' => '<span class="text text-muted">brak</span>',
  67. 'obiekty' => UI::h('a', [ 'href' => $this->getLink('systemObjects') ], "obiekty"),
  68. ],
  69. [
  70. 'Nr zasobu' => '',
  71. 'nazwa' => "Obiekty Test",
  72. 'opis' => "Obiekty podstawowe (test json)",
  73. 'config?' => '<span class="text text-muted">brak</span>',
  74. 'obiekty' => UI::h('a', [ 'href' => $this->getLink('coreObjectList') ], "obiekty"),
  75. 'raw info' => UI::h('a', [ 'href' => $this->getLink('coreObjectParseAll') ], "raw info"),
  76. ],
  77. [
  78. 'Nr zasobu' => '',
  79. 'nazwa' => "Obiekty Test",
  80. 'opis' => "Obiekty dla domeny '" . str_replace(array(".", "-"), '_', $_SERVER['SERVER_NAME']) . "' (test json)",
  81. 'config?' => '<span class="text text-muted">brak</span>',
  82. 'obiekty' => UI::h('a', [ 'href' => $this->getLink('objectList') ], "obiekty"),
  83. // 'raw info' => UI::h('a', [ 'href' => $this->getLink('objectRawInfo') ], "raw info"),
  84. ],
  85. ]
  86. )
  87. ]);
  88. // $sourceStorage = SchemaFactory::loadDefaultObject('SystemObject');
  89. // $sourceStorage->updateCache();
  90. } catch (Exception $e) {
  91. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  92. }
  93. UI::endContainer();
  94. UI::dol();
  95. }
  96. public function checkObjectInstallAjaxAction() {
  97. $response = array();
  98. try {
  99. $objectName = V::get('object', '', $_REQUEST, 'word');
  100. if (empty($objectName)) throw new Exception("Missing Object name");
  101. $response['object'] = $objectName;
  102. $json = OBJ::getCoreObjectFromFile($objectName);
  103. OBJ::checkInstall($json);
  104. $response['type'] = 'success';
  105. $response['msg'] = "OK - object installed";
  106. } catch (Exception $e) {
  107. $response['type'] = 'error';
  108. $response['msg'] = $e->getMessage();
  109. $response['code'] = $e->getCode();
  110. $response['line'] = $e->getLine();
  111. }
  112. Response::sendJsonExit($response);
  113. }
  114. public function coreObjectStructAction() {
  115. UI::gora();
  116. UI::menu();
  117. $this->navView();
  118. try {
  119. $objectName = V::get('object', '', $_REQUEST, 'word');
  120. if (empty($objectName)) throw new Exception("Missing Object name");
  121. $json = OBJ::getCoreObjectFromFile($objectName);
  122. $label = OBJ::getLabel($json);
  123. $parentList = OBJ::getParentList($json);
  124. $linksParentList = array(); foreach ($parentList as $parentName) {
  125. $parentLink = '<a href="index.php?_route=Storage&_task=coreObjectStruct&object=' . str_replace('/', '-', $parentName) . '">' . $parentName . '</a>';
  126. array_unshift($linksParentList, $parentLink);
  127. }
  128. $ajaxCheckInstall = Request::getPathUri() . "index.php?_route=Storage&_task=checkObjectInstallAjax&object={$objectName}";
  129. $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:checkObjectInstallAjax', { href: '{$ajaxCheckInstall}' })";
  130. $btnCheckInstall = '<a onclick="'.$onClick.'" href="#" title="check install db tables"><i class="glyphicon glyphicon-cog"></i></a>';
  131. UI::startContainer();
  132. UI::tag('h1', [], "Obiekt <code>{$label}</code> <small>{$btnCheckInstall}</small>");
  133. if (!empty($parentList)) {
  134. UI::startTag('ol', ['class'=>"breadcrumb"]);
  135. UI::tag('li', [], "Dziedziczy z:");
  136. foreach ($linksParentList as $parentLink) {
  137. UI::tag('li', [], $parentLink);
  138. }
  139. // <!-- <li class="active">Data</li> -->
  140. UI::endTag('ol');
  141. // <!-- <p> implode(", ", $parentList);</p> -->
  142. }
  143. // TODO: UI::table(['rows'=>array_map()]);
  144. ?>
  145. <table class="table table-bordered table-hovered">
  146. <caption>Struktura:</caption>
  147. <thead>
  148. <tr>
  149. <th>nazwa</th>
  150. <th>typ</th>
  151. <th>label</th>
  152. <th>json</th>
  153. </tr>
  154. </thead>
  155. <tbody>
  156. <?php foreach (OBJ::getFields($json) as $fieldName => $field) : ?>
  157. <tr>
  158. <td><?php echo $fieldName; ?></td>
  159. <td><?php echo $field['type']; ?></td>
  160. <td><?php echo $field['label']; ?></td>
  161. <td><?php echo json_encode($field); ?></td>
  162. </tr>
  163. <?php endforeach; ?>
  164. </tbody>
  165. </table>
  166. <a href="index.php?_route=Storage&_task=coreObjectConnect&object=<?php echo $objectName; ?>" class="btn btn-primary">Przypisz rekordy do klasy</a>
  167. <?php
  168. $mainTable = OBJ::getMainTableName($json);
  169. $sqlFields = OBJ::getTableFields($json);
  170. $this->showTableWidget($mainTable, $sqlFields);
  171. ?>
  172. </div>
  173. <script>
  174. jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:click', function(e, n, payload) {
  175. console.log('event p5UIBtnAjax:Storage:checkObjectInstallAjax:click', n, payload);
  176. });
  177. jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', function(e, n, payload) {
  178. console.log('event p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', n, payload);
  179. if ('success' == payload.type) {
  180. // jQuery(n).parents('td').text(payload.body.id);
  181. }
  182. jQuery.notify(payload.msg, payload.type);
  183. });
  184. </script>
  185. <?php
  186. DBG::_(true, true, "json", $json, __CLASS__, __FUNCTION__, __LINE__);
  187. } catch (Exception $e) {
  188. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  189. }
  190. UI::dol();
  191. }
  192. public function coreObjectConnectAction() {
  193. UI::gora();
  194. UI::menu();
  195. $this->navView();
  196. try {
  197. $objectName = V::get('object', '', $_REQUEST, 'word');
  198. if (empty($objectName)) throw new Exception("Missing Object name");
  199. $json = OBJ::getCoreObjectFromFile($objectName);
  200. $label = OBJ::getLabel($json);
  201. $parentList = OBJ::getParentList($json);
  202. $linksParentList = array(); foreach ($parentList as $parentName) {
  203. $parentLink = '<a href="index.php?_route=Storage&_task=coreObjectStruct&object=' . str_replace('/', '-', $parentName) . '">' . $parentName . '</a>';
  204. array_unshift($linksParentList, $parentLink);
  205. }
  206. $ajaxCheckInstall = Request::getPathUri() . "index.php?_route=Storage&_task=checkObjectInstallAjax&object={$objectName}";
  207. $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:checkObjectInstallAjax', { href: '{$ajaxCheckInstall}' })";
  208. $btnCheckInstall = '<a onclick="'.$onClick.'" href="#" title="check install db tables"><i class="glyphicon glyphicon-cog"></i></a>';
  209. ?>
  210. <div class="container">
  211. <h1>Obiekt <code><?php echo $label; ?></code> <small><?php echo $btnCheckInstall; ?></small></h1>
  212. <?php if (!empty($parentList)) : ?>
  213. <ol class="breadcrumb">
  214. <li>Dziedziczy z:</li>
  215. <?php foreach ($linksParentList as $parentLink) : ?>
  216. <li><?php echo $parentLink; ?></li>
  217. <?php endforeach; ?>
  218. <!-- <li class="active">Data</li> -->
  219. </ol>
  220. <!-- <p> <?php echo implode(", ", $parentList); ?></p> -->
  221. <?php endif; ?>
  222. <?php
  223. $tableOne = array();
  224. $tableOne['caption'] = 'Klasy';
  225. $tableOne['rows'] = array();
  226. $parentList = OBJ::getParentList($json);
  227. $tableOne['rows'][] = array('__primary_key' => $objectName, 'name' => $objectName);
  228. $linksParentList = array(); foreach ($parentList as $parentName) {
  229. // $parentLink = '<a href="index.php?_route=Storage&_task=coreObjectStruct&object=' . str_replace('/', '-', $parentName) . '">' . $parentName . '</a>';
  230. // array_unshift($linksParentList, $parentLink);
  231. $tableOne['rows'][] = array('__primary_key' => $parentName, 'name' => $parentName);
  232. }
  233. $tableTwo = array();
  234. $tableTwo['caption'] = 'Rekordy w tabeli głównej';
  235. $mainTable = OBJ::getMainTableName($json);
  236. $sqlFields = OBJ::getTableFields($json);
  237. $tableTwo['rows'] = $this->getTableRows($mainTable, $sqlFields);
  238. foreach ($tableTwo['rows'] as $idx => $row) {
  239. // $tableTwo['rows'][] = array('__primary_key' => $objectName, 'name' => $objectName);
  240. $tableTwo['rows'][$idx]['__primary_key'] = $row['ID'];
  241. }
  242. echo '<hr>';
  243. // TODO: filter connected rows
  244. // TODO: filter not connected rows
  245. // TODO: action connect rows - args(schema, rows_primary_key_list)
  246. // TODO: action un connect rows - args(schema, rows_primary_key_list)
  247. $this->showConnectSchemaToTableWidget(compact('tableOne', 'tableTwo'));
  248. ?>
  249. </div>
  250. <script>
  251. jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:click', function(e, n, payload) {
  252. console.log('event p5UIBtnAjax:Storage:checkObjectInstallAjax:click', n, payload);
  253. });
  254. jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', function(e, n, payload) {
  255. console.log('event p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', n, payload);
  256. if ('success' == payload.type) {
  257. // jQuery(n).parents('td').text(payload.body.id);
  258. }
  259. jQuery.notify(payload.msg, payload.type);
  260. });
  261. </script>
  262. <?php
  263. DBG::_(true, true, "json", $json, __CLASS__, __FUNCTION__, __LINE__);
  264. } catch (Exception $e) {
  265. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  266. }
  267. UI::dol();
  268. }
  269. public function showConnectSchemaToTableWidget($params) {
  270. if (empty($params['tableOne'])) throw new Exception("Missing tableOne in Connect widget");
  271. if (empty($params['tableTwo'])) throw new Exception("Missing tableTwo in Connect widget");
  272. $tableOne = $params['tableOne'];
  273. $tableTwo = $params['tableTwo'];
  274. // TODO: add p5BtnAjax to table filters button
  275. // TODO: add p5BtnAjax to conn button
  276. $jsEventNamespace = 'ConnectTableWidget' . time();
  277. $htmlIdWrap = "{$jsEventNamespace}-wrap";
  278. $stateLogId = "{$jsEventNamespace}-state-log";
  279. $stateSelectedTotalId = "{$jsEventNamespace}-state-selected";
  280. $stateClearSelectedBtnId = "{$jsEventNamespace}-state-clear-selected-btn";
  281. foreach ($tableOne['rows'] as $idx => $r) {
  282. $tableOne['rows'][$idx]['@onClick'] = "return p5UI__Clickable(this, '{$jsEventNamespace}:tableOne', { primary_key: '{$r['__primary_key']}' });";
  283. }
  284. foreach ($tableTwo['rows'] as $idx => $r) {
  285. $tableTwo['rows'][$idx]['@onClick'] = "return p5UI__Clickable(this, '{$jsEventNamespace}:tableTwo', { primary_key: '{$r['__primary_key']}' });";
  286. }
  287. $tableOne['hidden_cols'] = $tableTwo['hidden_cols'] = array('__primary_key', '@onClick', '__html_id');
  288. $tableTwo['__html_id'] = "{$jsEventNamespace}-table-two";
  289. ?>
  290. <div id="<?php echo $htmlIdWrap; ?>">
  291. <?php UI::table($tableOne); ?>
  292. <div class="btn-group">
  293. <button class="btn btn-default" title="Wybierz rekordy wg instancji"><i class="glyphicon glyphicon-question-sign"></i></button>
  294. <button class="btn btn-default conn-btn-filter-yes">Przypisani</button>
  295. <button class="btn btn-default conn-btn-filter-no active">Nieprzypisani</button>
  296. <button class="btn btn-default conn-btn-filter-clear" title="Wszystkie"><i class="glyphicon glyphicon-remove"></i></button>
  297. </div>
  298. <div class="btn-group">
  299. <span style="padding-left:30px;">Zaznaczono
  300. <span class="conn-selected-total">0</span>
  301. <button class="conn-btn-clear-selected btn btn-link"
  302. onClick="return p5UI__Clickable(this, '<?php echo $jsEventNamespace; ?>:clearSelection', {});"
  303. style="display:none"><i class="glyphicon glyphicon-remove" style="color:red"></i></button>
  304. </span>
  305. </div>
  306. <?php UI::jsAjaxTable($tableTwo); ?>
  307. <pre class="conn-log"></pre>
  308. </div>
  309. <script>
  310. (function(){
  311. var state = {
  312. selectedTableOne: null,
  313. selectedTableTwo: [],
  314. filterSelected: 'no'
  315. }
  316. var props = {
  317. jsEventNamespace: '<?php echo $jsEventNamespace; ?>',
  318. htmlIdWrap: '<?php echo $htmlIdWrap; ?>',
  319. tableTwoId: '#<?php echo $tableTwo['__html_id']; ?>',
  320. stateSelectedTotalId: '#<?php echo $stateSelectedTotalId; ?>',
  321. stateClearSelectedBtnId: '#<?php echo $stateClearSelectedBtnId; ?>',
  322. stateLogId: '#<?php echo $stateLogId; ?>'
  323. }
  324. var wrap = jQuery('#' + props.htmlIdWrap);
  325. var jqNodes = {
  326. wrap: wrap,
  327. filter_yes: wrap.find('.conn-btn-filter-yes'),
  328. filter_no: wrap.find('.conn-btn-filter-no'),
  329. filter_clear: wrap.find('.conn-btn-filter-clear'),
  330. total_selected: wrap.find('.conn-selected-total'),
  331. btn_clear_selected: wrap.find('.conn-btn-clear-selected'),
  332. state_log: wrap.find('.conn-log')
  333. }
  334. function render() {
  335. jqNodes['total_selected'].text(state.selectedTableTwo.length);
  336. if (state.selectedTableTwo.length > 0) {
  337. jQuery(props.stateClearSelectedBtnId).show();
  338. } else {
  339. jQuery(props.stateClearSelectedBtnId).hide();
  340. }
  341. jqNodes['state_log'].text(JSON.stringify(state));
  342. switch (state.filterSelected) {
  343. case 'yes':
  344. jqNodes['filter_yes'].addClass('active');
  345. jqNodes['filter_no'].removeClass('active');
  346. jqNodes['filter_clear'].removeClass('active');
  347. break;
  348. case 'no':
  349. jqNodes['filter_yes'].removeClass('active');
  350. jqNodes['filter_no'].addClass('active');
  351. jqNodes['filter_clear'].removeClass('active');
  352. break;
  353. case 'clear':
  354. jqNodes['filter_yes'].removeClass('active');
  355. jqNodes['filter_no'].removeClass('active');
  356. jqNodes['filter_clear'].addClass('active');
  357. break;
  358. }
  359. }
  360. function action__selectTableOneRow(pk) {
  361. state.selectedTableOne = pk;
  362. render();
  363. }
  364. function action__unselectTableOneRow() {
  365. state.selectedTableOne = null;
  366. render();
  367. }
  368. function action__selectTableTwoRow(pk) {
  369. var idx = state.selectedTableTwo.indexOf(pk);
  370. if (-1 === idx) state.selectedTableTwo.push(pk);
  371. else console.log("Error selectedTableTwo - should be not set");
  372. render();
  373. }
  374. function action__unselectTableTwoRow(pk) {
  375. var idx = state.selectedTableTwo.indexOf(pk);
  376. if (-1 === idx) state.selectedTableTwo.push(pk);
  377. else state.selectedTableTwo.splice(idx, 1);
  378. render();
  379. }
  380. function action__clearSelection() {
  381. state.selectedTableTwo = [];
  382. jQuery(props.tableTwoId).find('tbody').children('.info').removeClass('info');
  383. render();
  384. }
  385. function action__filterSet(fltr) {
  386. state.filterSelected = fltr;
  387. render();
  388. // TODO: ajax load tableTwo based on filter
  389. }
  390. jQuery(document).on(props.jsEventNamespace + ':tableOne:click', function(e, n, payload) {
  391. var n$ = jQuery(n);
  392. console.log('event '+props.jsEventNamespace+':tableOne:click', n, payload);
  393. jQuery.notify('tableOne row clicked [' + payload.props.primary_key + ']', 'info');
  394. if (n$.hasClass('info')) {
  395. n$.removeClass('info');
  396. action__unselectTableOneRow();
  397. } else {
  398. n$.parent().children('.info').removeClass('info');
  399. n$.addClass('info');
  400. action__selectTableOneRow(payload.props.primary_key);
  401. }
  402. });
  403. jQuery(document).on(props.jsEventNamespace + ':tableTwo:click', function(e, n, payload) {
  404. var n$ = jQuery(n);
  405. console.log('event '+props.jsEventNamespace+':tableTwo:click', n, payload);
  406. jQuery.notify('tableTwo row clicked [' + payload.props.primary_key + ']', 'info');
  407. if (n$.hasClass('info')) {
  408. n$.removeClass('info');
  409. action__unselectTableTwoRow(payload.props.primary_key);
  410. } else {
  411. n$.addClass('info');
  412. action__selectTableTwoRow(payload.props.primary_key);
  413. }
  414. });
  415. jQuery(document).on(props.jsEventNamespace + ':clearSelection:click', function(e, n, payload) {
  416. action__clearSelection();
  417. });
  418. jqNodes['filter_yes'].on('click', function(e) {
  419. action__filterSet('yes');
  420. });
  421. jqNodes['filter_no'].on('click', function(e) {
  422. action__filterSet('no');
  423. });
  424. jqNodes['filter_clear'].on('click', function(e) {
  425. action__filterSet('clear');
  426. });
  427. })();
  428. </script>
  429. <?php
  430. }
  431. public function getTableRows($tblName, $fields) {
  432. $sqlFields = array();
  433. foreach ($fields as $fldName) {
  434. $sqlFields[] = "t.`{$fldName}`";
  435. }
  436. $sqlFields = (!empty($sqlFields))? implode(", ", $sqlFields) : "t.*";
  437. $rows = DB::getPDO()->fetchAll("
  438. select {$sqlFields}
  439. from `{$tblName}` t
  440. where 1=1
  441. limit 10
  442. ");
  443. return $rows;
  444. }
  445. public function showTableWidget($tblName, $fields) {
  446. $rows = $this->getTableRows($tblName, $fields);
  447. UI::table(array('caption' => "table({$tblName})", 'rows' => $rows));
  448. }
  449. public function coreObjectParseAllAction() {
  450. UI::gora();
  451. UI::menu();
  452. $this->navView();
  453. try {
  454. OBJ::parseAll();
  455. } catch (Exception $e) {
  456. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  457. }
  458. UI::dol();
  459. }
  460. public function coreObjectListAction() {
  461. UI::gora();
  462. UI::menu();
  463. $this->navView();
  464. try {
  465. $coreObjlist = OBJ::getCoreObjectList();
  466. $objectList = array();
  467. foreach ($coreObjlist as $objName) {
  468. $objItem = array();
  469. $objItem['name'] = $objName;
  470. $objItem['struktura'] = '<a href="index.php?_route=Storage&_task=coreObjectStruct&object=' . $objName . '">' . "struct" . '</a>';
  471. // $objItem['label'] = "";// TODO: read from json
  472. $objectList[] = $objItem;
  473. }
  474. usort($objectList, function($rowA, $rowB) {
  475. $a = $rowA['nazwa']; $b = $rowB['nazwa'];
  476. if ($a == $b) return 0;
  477. return ($a < $b) ? -1 : 1;
  478. });
  479. DBG::table("objectList", $objectList, __CLASS__, __FUNCTION__, __LINE__);
  480. } catch (Exception $e) {
  481. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  482. }
  483. UI::dol();
  484. }
  485. public function objectListAction() {
  486. UI::gora();
  487. UI::menu();
  488. try {
  489. } catch (Exception $e) {
  490. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  491. }
  492. UI::dol();
  493. }
  494. public function tableListAction() {
  495. UI::gora();
  496. UI::menu();
  497. $this->navView();
  498. UI::startContainer();
  499. try {
  500. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  501. if (empty($idStorage)) throw new Exception("Missing id storage");
  502. $sourceStorage = SchemaFactory::loadDefaultObject('SystemSource');
  503. $sourceItem = $sourceStorage->getItem($idStorage);
  504. if (!$sourceItem) throw new Exception("Storage id='{$idStorage}' not exists");
  505. DBG::log($sourceItem, 'array', '$sourceItem');
  506. // TODO: fetch SystemObject childrens from $sourceItem:
  507. // 1. 'SystemSource' -> getItems([ 'cols' => 'SystemObject/*', 'featureId' => $sourceItem['idZasob'] ])
  508. // 2. 'SystemObject' -> getItems([ 'refFrom' => $sourceItem['idZasob'] ])
  509. // 'default_objects' => _task=systemObjects
  510. $objectStorage = SchemaFactory::loadDefaultObject('SystemObject');
  511. try {
  512. $objectStorage->getTotal();
  513. } catch (Exception $e) {
  514. UI::alert('warning', $e->getMessage());
  515. DBG::log($e);
  516. $objectStorage->updateCache();
  517. UI::alert('info', "Lista obiketów zaktualizowana");
  518. }
  519. if ('1' == V::get('refreshObjectList', '', $_POST)) {
  520. $objectStorage->updateCache();
  521. UI::alert('info', "Lista obiketów zaktualizowana");
  522. }
  523. {
  524. echo UI::h('style', ['type' => "text/css"], "
  525. .p5UI__dropdown-content { min-width:300px; padding:8px; background-color: #f6f6f6; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2) }
  526. .p5UI__dropdown-content a { display:block; color:#000; padding:8px; text-decoration:none }
  527. .p5UI__dropdown-content a:hover { background-color:#ebebeb }
  528. ");
  529. echo UI::h('script', [], "
  530. function p5_Storage_actions_filterInput(n) {
  531. var input, filter, ul, li, a, i, div;
  532. input = n // .id-myInput
  533. filter = input.value.toUpperCase()
  534. div = n.parentNode // .id-myDropdown
  535. a = div.getElementsByTagName('a')
  536. for (i = 0; i < a.length; i++) {
  537. if (a[i].innerHTML.toUpperCase().indexOf(filter) > -1) {
  538. a[i].style.display = ''
  539. } else {
  540. a[i].style.display = 'none'
  541. }
  542. }
  543. }
  544. ");
  545. }
  546. UI::table([
  547. 'caption' => "Obiekty w bazie '{$sourceItem['name']}' " .
  548. UI::hButtonPost('<i class="glyphicon glyphicon-refresh"></i>' . " odśwież", [
  549. 'class' => "btn btn-xs btn-link",
  550. 'data' => [
  551. 'refreshObjectList' => '1'
  552. ]
  553. ]),
  554. 'rows' => array_map(function ($item) use ($idStorage) {
  555. $addToZasobyLink = $this->getLink('addAclObjectToZasoby', ['idStorage' => $idStorage, 'namespace' => $item['namespace']]);
  556. // $typeName = Api_WfsNs::typeName($item['namespace']);
  557. $typeName = $item['typeName'];
  558. return [
  559. 'namespace' => '<span style="color:#888">' . substr($item['namespace'], 0, strlen($item['namespace']) - strlen($item['name'])) . '</span>' .
  560. '<span>' . $item['name'] . '</span>',
  561. '_type' => $item['_type'], // TODO: editable?
  562. 'Nr zasobu' => ($item['idZasob'] > 0)
  563. ? $item['idZasob']
  564. : UI::h('button', [
  565. 'class' => "btn btn-xs btn-primary",
  566. 'onClick' => "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addAclObjectToZasoby', { href: '{$addToZasobyLink}' })"
  567. ], "Dodaj do Zasobów"),
  568. // 'opis' => $item['description'],
  569. 'active?' => ($item['isActive']) ? '<span class="label label-success">TAK</span>' : '<span class="text text-muted">nie</span>',
  570. 'installed' => $item['isStructInstalled'] ? '<span class="label label-success">TAK</span>' : '<span class="text text-muted">nie</span>',
  571. 'menu' => UI::h('div', ['class'=>"p5UI__dropdown-wrap"], [
  572. UI::h('button', ['onClick' => "p5UI__dropdown(event, this, 'left bottom')", 'class' => "btn btn-xs btn-default p5UI__dropdown-btn"], [
  573. '<i class="glyphicon glyphicon-menu-hamburger"></i>',
  574. " menu"
  575. ]),
  576. UI::h('div', ['class' => "p5UI__dropdown-content"], [
  577. UI::h('input', ['type' => "text", 'placeholder' => "Search..", 'class' => "p5UI__dropdown-input", 'onkeyup' => "p5_Storage_actions_filterInput(this)"], null),
  578. UI::h('a', [ 'href' => $item['reinstallLink'] ], "reinstall"),
  579. UI::h('a', [ 'href' => $this->getLink('tableStruct', [ 'idStorage' => $idStorage, 'table' => $item['name'] ]) ], "struktura"),
  580. UI::h('a', [ 'href' => $this->getLink('objectStruct', [ 'idStorage' => $idStorage, 'namespace' => $item['namespace'] ]) ], "obj struct"),
  581. UI::h('a', [ 'href' => $this->getLink('rawInfo', [ 'idStorage' => $idStorage, 'table' => $item['name'] ]) ], "raw info"),
  582. UI::h('a', [ 'href' => Router::getRoute('ViewTableAjax')->getLink('', ['namespace' => $item['namespace']]) ], "view table"),
  583. UI::h('a', [ 'href' => Router::getRoute('ViewObject')->getLink('', ['namespace' => $item['namespace']]) ], "view object"),
  584. // 'xsd' => UI::h('a', [ 'href' => $this->getLink('xsd', [ 'idStorage' => $idStorage ]) ], "xsd"),
  585. UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=DescribeFeatureType&TYPENAME={$typeName}" ], "wfs DescribeFeatureType"),
  586. UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=DescribeFeatureTypeAdvanced&TYPENAME={$typeName}" ], "wfs DescribeFeatureTypeAdvanced"),
  587. UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=GetFeature&TYPENAME={$typeName}&MAXFEATURES=10" ], "wfs GetFeature (max: 10)"),
  588. UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=GetFeatureAdvanced&TYPENAME={$typeName}&MAXFEATURES=10" ], "wfs GetFeatureAdvanced (max: 10)"),
  589. UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=DescribeFeatureType&TYPENAME={$typeName}&root=1" ], "wfs root DescribeFeatureType"),
  590. UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=DescribeFeatureTypeAdvanced&TYPENAME={$typeName}&root=1" ], "wfs root DescribeFeatureTypeAdvanced"),
  591. UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=GetFeature&TYPENAME={$typeName}&MAXFEATURES=10&root=1" ], "wfs root GetFeature (max: 10)"),
  592. UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=GetFeatureAdvanced&TYPENAME={$typeName}&MAXFEATURES=10&root=1" ], "wfs root GetFeatureAdvanced (max: 10)"),
  593. ])
  594. ]),
  595. ];
  596. }, $objectStorage->getItems([
  597. '#refFrom' => [
  598. 'namespace' => 'default_objects/SystemSource',
  599. 'primaryKey' => $sourceItem['idZasob']
  600. ],
  601. 'order_by' => 'namespace',
  602. 'order_dir' => 'asc'
  603. ]))
  604. ]);
  605. echo UI::h('script', [], "
  606. jQuery(document).on('p5UIBtnAjax:Storage:addAclObjectToZasoby:click', function(e, n, payload) {
  607. console.log('event p5UIBtnAjax:Storage:addAclObjectToZasoby:click', n, payload);
  608. });
  609. jQuery(document).on('p5UIBtnAjax:Storage:addAclObjectToZasoby:ajaxLoaded', function(e, n, payload) {
  610. console.log('event p5UIBtnAjax:Storage:addAclObjectToZasoby:ajaxLoaded', n, payload);
  611. if ('success' == payload.type && payload.body && payload.body.id > 0) {
  612. jQuery(n).parents('td').text(payload.body.id);
  613. }
  614. jQuery.notify(payload.msg, payload.type);
  615. });
  616. ");
  617. } catch (Exception $e) {
  618. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  619. DBG::log($e);
  620. }
  621. UI::endContainer();
  622. UI::dol();
  623. }
  624. public function rawInfoAction() {
  625. UI::gora();
  626. UI::menu();
  627. $this->navView();
  628. try {
  629. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  630. if (empty($idStorage)) throw new Exception("Missing id storage");
  631. $storageList = $this->getStorageList();
  632. if (empty($storageList)) throw new Exception("No storage defined");
  633. if (!array_key_exists($idStorage, $storageList)) throw new Exception("Storage not exists");
  634. $storagePdo = DB::getStorage($idStorage);
  635. $rawInfo = $storagePdo->getTableListWithInfo();
  636. DBG::table("rawInfo", $rawInfo, __CLASS__, __FUNCTION__, __LINE__);
  637. } catch (Exception $e) {
  638. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  639. }
  640. UI::dol();
  641. }
  642. public function objectStructAction() {
  643. UI::gora();
  644. UI::menu();
  645. $this->navView();
  646. UI::startTag('div', [ 'class' => 'container-fluid' ]);
  647. try {
  648. $namespace = V::get('namespace', '', $_GET);
  649. if (empty($namespace)) throw new Exception("Missing param namespace");
  650. $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
  651. DBG::nicePrint($item, '$item');
  652. usort($item['field'], function ($a, $b) {
  653. if ($a['fieldNamespace'] > $b['fieldNamespace']) return 1;
  654. if ($a['fieldNamespace'] < $b['fieldNamespace']) return -1;
  655. return 0;
  656. });
  657. echo ($item['idZasob'] > 0)
  658. ? UI::h('h3', [], "Nr zasobu {$item['idZasob']}")
  659. : UI::h('h3', [], "Nr zasobu ???");// TODO: UI::hButtonAjax(...)
  660. UI::table([
  661. 'caption' => UI::h('h3', [], "Struktura obiektu '{$item['namespace']}'"),
  662. 'rows' => array_map(function ($field) {
  663. $tblItem = []; foreach ($field as $k => $v) $tblItem[$k] = $v;
  664. $tblItem['namespace'] = UI::h('span', [], [
  665. UI::h('span', ['style' => "color:#aaa"], substr($field['namespace'], 0, strlen($field['objectNamespace']) + 1)),
  666. UI::h('span', ['style' => "color:#000"], substr($field['namespace'], strlen($field['objectNamespace']) + 1)),
  667. ]);
  668. $tblItem['idZasob'] = ($field['idZasob'] > 0)
  669. ? $field['idZasob']
  670. : UI::hButtonAjax("+ do zasobów", 'addFieldToZasoby', [
  671. 'class' => "btn btn-xs btn-primary",
  672. 'href' => Request::getPathUri() . "index.php?_route=Storage&_task=addFieldToZasoby",
  673. 'data' => [
  674. 'namespace' => $field['namespace'],
  675. ]
  676. ]);
  677. unset($tblItem['objectNamespace']);
  678. unset($tblItem['fieldNamespace']);
  679. return $tblItem;
  680. }, $item['field'])
  681. ]);
  682. UI::hButtonAjaxOnResponse('addFieldToZasoby', "
  683. if (!payload.type) return false
  684. console.log('TODO: addFieldToZasoby response', payload);
  685. if (payload.data && payload.data.id && payload.data.id > 0) { // if ('success' == payload.type) {
  686. n.parentNode.replaceChild(document.createTextNode(payload.data.id), n)
  687. } else {
  688. console.log('TODO: addFieldToZasoby unknown response', payload);
  689. }
  690. ");
  691. } catch (Exception $e) {
  692. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  693. DBG::log($e);
  694. }
  695. UI::endTag('div'); // .container-fluid
  696. UI::dol();
  697. }
  698. public function tableStructAction() {
  699. UI::gora();
  700. UI::menu();
  701. $this->navView();
  702. try {
  703. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  704. if (empty($idStorage)) throw new Exception("Missing id storage");
  705. $storageList = $this->getStorageList();
  706. if (empty($storageList)) throw new Exception("No storage defined");
  707. if (!array_key_exists($idStorage, $storageList)) throw new Exception("Storage not exists");
  708. $tblName = V::get('table', '', $_REQUEST, 'word');
  709. if (empty($tblName)) throw new Exception("No table name");
  710. $storagePdo = DB::getStorage($idStorage);
  711. $tblStruct = $storagePdo->getTableStruct($tblName);
  712. $idTable = $this->fetchTableId($idStorage, $tblName);
  713. if ($idTable <= 0) {
  714. UI::alert('warning', "Zasob tabela '{$tblName}' nie istnieje");// TODO: add p5UI btn
  715. DBG::table("tblStruct", $tblStruct, __CLASS__, __FUNCTION__, __LINE__);
  716. throw new Exception("Zasob tabela '{$tblName}' nie istnieje");
  717. }
  718. $cellZasobList = array();
  719. foreach (DB::getPDO()->fetchAllByKey("
  720. select z.ID, z.`DESC`, z.`TYPE` as ZASOB_TYPE, z.A_STATUS
  721. from CRM_LISTA_ZASOBOW z
  722. where z.PARENT_ID = '{$idTable}'
  723. ", $key = 'DESC') as $ind => $row) {
  724. $cellZasobList[strtolower($ind)] = $row;
  725. }
  726. $emptyItem = array();
  727. $emptyItem['name'] = '';
  728. $emptyItem['id_zasob'] = '';
  729. $emptyItem['zasob_type'] = '';
  730. $emptyItem['uwagi'] = '';
  731. $emptyItem['type'] = '';
  732. $emptyItem['is_nullable'] = '';
  733. $emptyItem['default_value'] = '';
  734. $emptyItem['default_is_null'] = '';
  735. $emptyItem['max_length'] = '';
  736. $emptyItem['num_precision'] = '';
  737. $emptyItem['num_scale'] = '';
  738. $emptyItem['char_encoding'] = '';
  739. $emptyItem['char_collation'] = '';
  740. $emptyItem['extra'] = '';
  741. $emptyItem['raw_storage_type'] = '';
  742. $tableList = array();
  743. foreach ($tblStruct as $row) {
  744. $cellName = $row['name'];
  745. $tblItem = V::cloneArray($emptyItem);
  746. $tblItem['name'] = $cellName;
  747. foreach ($row as $fldName => $fldVal) {
  748. if (array_key_exists($fldName, $tblItem)) $tblItem[$fldName] = $fldVal;
  749. }
  750. $tblItem['uwagi'] = '';
  751. $lowerCellName = strtolower($cellName);
  752. $tblZasob = V::get($lowerCellName, '', $cellZasobList);
  753. if ($tblZasob) {
  754. $cellZasobList[$lowerCellName]['_checked'] = true;
  755. $tblItem['id_zasob'] = $tblZasob['ID'];
  756. $tblItem['zasob_type'] = $tblZasob['ZASOB_TYPE'];
  757. } else {
  758. $tblItem['uwagi'] .= '!Zasob';//'TODO: ADD ZASOB';
  759. $ajaxAddZasobLink = Request::getPathUri() . "index.php?_route=Storage&_task=addCellToZasoby&idStorage={$idStorage}&tblName={$tblName}&cellName={$cellName}";
  760. $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addCellToZasoby', { href: '{$ajaxAddZasobLink}' })";
  761. $tblItem['id_zasob'] = '<a onclick="'.$onClick.'" class="btn btn-xs btn-primary" href="#">TODO: ADD ZASOB</a>';
  762. }
  763. $tableList[] = $tblItem;
  764. }
  765. foreach ($cellZasobList as $cellName => $row) {
  766. if ('URL_ACTION' == $row['ZASOB_TYPE']) continue;
  767. if (!$row['_checked']) {
  768. $tblItem = V::cloneArray($emptyItem);
  769. $tblItem['name'] = $cellName;
  770. $tblItem['id_zasob'] = $row['ID'];
  771. $tblItem['zasob_type'] = $row['ZASOB_TYPE'];
  772. $tblItem['uwagi'] = '!DB';//'TODO: nie istnieje w bazie danych';
  773. $tableList[] = $tblItem;
  774. }
  775. }
  776. usort($tableList, function($rowA, $rowB) {
  777. $a = $rowA['name']; $b = $rowB['name'];
  778. if ('ID' == $a) return -1;
  779. if ('ID' == $b) return 1;
  780. if ($a == $b) return 0;
  781. $a1 = substr($a, 0, 1); $b1 = substr($b, 0, 1);
  782. if (('_' == $a1 || '_' == $b1) && $a1 != $b1) {
  783. return ($a1 < $b1) ? 1 : -1;
  784. }
  785. return ($a < $b) ? -1 : 1;
  786. });
  787. UI::table([
  788. 'caption' => UI::h('span', [], [
  789. "Komórki [{$idTable}] ",
  790. UI::h('a', [
  791. 'href' => "index.php?_route=ViewTableAjax&namespace=default_db/{$tblName}",
  792. 'class' => "btn btn-md btn-link"
  793. ], "Przeglądaj tabelę"),
  794. UI::h('a', [
  795. 'href' => "procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id={$idTable}&filtr_ids=%2B&filtr_ob=%2B",
  796. 'class' => "btn btn-md btn-link",
  797. 'title' => "Struktura aktualnie przeglądanej tabeli"
  798. ], "Zasoby"),
  799. UI::h('a', [
  800. 'href' => "index.php?FUNCTION_INIT=PROCES_MENU&HEADER_NOT_INIT=YES&_task=PROCES_FOR_TABLE&tblId={$idTable}",
  801. 'class' => "btn btn-md btn-link",
  802. 'title' => "Procesy dla aktualnie przeglądanej tabeli"
  803. ], "Procesy"),
  804. ]),
  805. 'cols' => array_keys($emptyItem),
  806. 'rows' => $tableList
  807. ]);
  808. echo UI::h('script', [], "
  809. jQuery(document).on('p5UIBtnAjax:Storage:addCellToZasoby:click', function(e, n, payload) {
  810. console.log('event p5UIBtnAjax:Storage:addCellToZasoby:click', n, payload);
  811. });
  812. jQuery(document).on('p5UIBtnAjax:Storage:addCellToZasoby:ajaxLoaded', function(e, n, payload) {
  813. console.log('event p5UIBtnAjax:Storage:addCellToZasoby:ajaxLoaded', n, payload);
  814. if ('success' == payload.type && payload.body && payload.body.id > 0) {
  815. var cellUwagiJQNode = jQuery(n).parents('td').next('td');
  816. cellUwagiJQNode.text(cellUwagiJQNode.text().replace('!Zasob', ''))
  817. jQuery(n).parents('td').text(payload.body.id);
  818. jQuery(n).remove();
  819. }
  820. jQuery.notify(payload.msg, payload.type);
  821. });
  822. ");
  823. $ajaxAddZasobLink = Request::getPathUri() . "index.php?_route=Storage&_task=addGeomEtykietaCells&idStorage={$idStorage}&tblName={$tblName}";
  824. $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addGeomEtykietaCells', { href: '{$ajaxAddZasobLink}' })";
  825. UI::tag('a', ['onclick'=>$onClick, 'class'=>"btn btn-xs btn-default", 'href'=>"#"], "Dodaj komórki etykiet", true);
  826. echo "<i>(<code>`etykieta_x`</code>, <code>`etykieta_y`</code>, <code>`etykieta_obrot`</code>)</i>";
  827. echo UI::h('script', [], "
  828. jQuery(document).on('p5UIBtnAjax:Storage:addGeomEtykietaCells:ajaxLoaded', function(e, n, payload) {
  829. console.log('event p5UIBtnAjax:Storage:addGeomEtykietaCells:ajaxLoaded', n, payload);
  830. if ('success' == payload.type && payload.body && payload.body.id > 0) {
  831. var cellUwagiJQNode = jQuery(n).parents('td').next('td');
  832. cellUwagiJQNode.text(cellUwagiJQNode.text().replace('!Zasob', ''))
  833. jQuery(n).parents('td').text(payload.body.id);
  834. jQuery(n).remove();
  835. }
  836. jQuery.notify(payload.msg, payload.type);
  837. });
  838. ");
  839. $tableActions = array_filter($cellZasobList, function ($row) {
  840. return ('URL_ACTION' == $row['ZASOB_TYPE']);
  841. });
  842. UI::table([
  843. 'caption' => "tableActions",
  844. // 'cols' => array_keys($emptyItem),
  845. 'rows' => array_map(function ($item) {
  846. $sqlIdAction = DB::getPDO()->quote($item['ID'], PDO::PARAM_INT);
  847. $args = DB::getPDO()->fetchAll("
  848. select z.`DESC`
  849. , a.ID as ALIAS_ID, a.`DESC` as ALIAS_DESC, a.OPIS as ALIAS_OPIS
  850. from CRM_LISTA_ZASOBOW z
  851. left join CRM_LISTA_ZASOBOW a on(a.ID = z.ALIAS_ID)
  852. where z.PARENT_ID = {$sqlIdAction}
  853. and z.`TYPE` = 'PARAM_IN'
  854. ");
  855. $definitionArgs = DB::getPDO()->fetchAll("
  856. select p.ID, p.`DESC`
  857. from CRM_LISTA_ZASOBOW z
  858. join CRM_LISTA_ZASOBOW d on(d.ID = z.ALIAS_ID)
  859. left join CRM_LISTA_ZASOBOW p on(p.PARENT_ID = d.ID)
  860. where z.ID = {$sqlIdAction}
  861. and p.`TYPE` = 'PARAM_IN'
  862. ");
  863. $flatDefinitionArgs = implode(";", array_map(function ($arg) {
  864. return "{$arg['ID']}={$arg['DESC']}";
  865. }, $definitionArgs));
  866. return [
  867. 'label' => DB::getPDO()->fetchValue(" select z.OPIS from CRM_LISTA_ZASOBOW z where z.ID = {$sqlIdAction} ") . " " .
  868. UI::h('i', [
  869. 'class' => "glyphicon glyphicon-pencil",
  870. 'style' => "cursor:pointer",
  871. 'onClick' => "return Storage__tableStruct__editActionLabel(this, {$sqlIdAction})"], ''),
  872. 'args' => implode("<br>&", array_map(function ($item) {
  873. return (NULL === $item['ALIAS_ID'])
  874. ? $item['DESC']
  875. : "{$item['DESC']}=" . '{$row["' . $item['ALIAS_DESC'] . '"]}';// TODO: add rmParam btn
  876. }, $args)) . " " .
  877. UI::h('i', [
  878. 'class' => "glyphicon glyphicon-plus-sign",
  879. 'style' => "cursor:pointer",
  880. 'title' => "Dodaj PARAM_IN",
  881. 'onClick' => "return Storage__tableStruct__addParamAction(this, {$sqlIdAction}, '{$flatDefinitionArgs}')"], ''),
  882. // 'args_info' => '<pre>' . var_export($args, true) . '</pre>',
  883. 'ID' => $item['ID'],
  884. 'DESC' => $item['DESC'],
  885. 'A_STATUS' => $item['A_STATUS'],
  886. 'definition args' => implode("", array_map(function ($item) {
  887. return '<div style="white-space:nowrap">' . "[{$item['ID']}] {$item['DESC']}" . '</div>';
  888. }, $definitionArgs)),
  889. ];
  890. }, $tableActions)
  891. ]);
  892. echo UI::h('button', [
  893. 'onClick'=>"Storage__tableStruct__addAction()",
  894. 'class'=>"btn btn-xs btn-default"
  895. ], "Dodaj Akcję");
  896. echo UI::h('link', ['rel'=>"stylesheet", 'type'=>"text/css", 'href'=>"static/sweetalert2.min.css"]);
  897. echo UI::h('script', ['src'=>"static/sweetalert2.min.js"]);
  898. echo UI::h('style', [], "
  899. .swal2-radio.p5-swal-radio-as-list { text-align:left }
  900. .swal2-radio.p5-swal-radio-as-list > label { display:block; margin-left:20px }
  901. ");
  902. UI::inlineJS(__FILE__ . '.tableActions.js', [
  903. 'ID_STORAGE' => $idStorage,
  904. 'TABLE_NAME' => $tblName,
  905. 'FETCH_URL' => Request::getPathUri() . 'index.php?_route=Storage&_task=fetchActionListAjax',
  906. 'ADD_ACTION_URL' => Request::getPathUri() . 'index.php?_route=Storage&_task=addActionAjax'
  907. ]);
  908. echo '<hr>';
  909. $ajaxAddBaseProcesLink = Request::getPathUri() . "index.php?_route=Storage&_task=addBaseProces&idStorage={$idStorage}&tblName={$tblName}";
  910. $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addBaseProces', { href: '{$ajaxAddBaseProcesLink}' })";
  911. UI::tag('a', ['onclick'=>$onClick, 'class'=>"btn btn-xs btn-default", 'href'=>"#"], "Dodaj podstawowy proces dla tabeli '{$tblName}' - read only", true);
  912. echo UI::h('script', [], "
  913. jQuery(document).on('p5UIBtnAjax:Storage:addBaseProces:ajaxLoaded', function(e, n, payload) {
  914. jQuery.notify(payload.msg, payload.type);
  915. });
  916. ");
  917. } catch (Exception $e) {
  918. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  919. }
  920. UI::dol();
  921. }
  922. public function fetchActionListAjaxAction() {
  923. Response::sendTryCatchJson(array($this, 'fetchActionListAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  924. }
  925. public function fetchActionListAjax($args) {
  926. return [
  927. 'type' => 'success',
  928. '__args' => $args,
  929. 'options' => DB::getPDO()->fetchAll("
  930. select z.ID, z.`DESC`, z.OPIS
  931. from CRM_LISTA_ZASOBOW z
  932. where z.`TYPE` = 'URL_ACTION'
  933. and z.A_STATUS != 'DELETED'
  934. and z.ALIAS_ID = 0
  935. ")
  936. ];
  937. }
  938. public function addActionAjaxAction() {
  939. Response::sendTryCatchJson(array($this, 'addActionAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  940. }
  941. public function addActionAjax($args) {
  942. $idStorage = V::get('idStorage', 0, $args, 'int');
  943. if ($idStorage <= 0) throw new Exception("Missing id storage");
  944. $idAction = V::get('idAction', 0, $args, 'int');
  945. if ($idAction <= 0) throw new Exception("Missing id action");
  946. $storageList = $this->getStorageList();
  947. if (empty($storageList)) throw new Exception("No storage defined");
  948. if (!array_key_exists($idStorage, $storageList)) throw new Exception("Storage not exists");
  949. $tblName = V::get('table', '', $args, 'word');
  950. if (empty($tblName)) throw new Exception("No table name");
  951. $storagePdo = DB::getStorage($idStorage);
  952. // $tblStruct = $storagePdo->getTableStruct($tblName);
  953. $idTable = $this->fetchTableId($idStorage, $tblName);
  954. if ($idTable <= 0) throw new Exception("Zasob tabela '{$tblName}' nie istnieje");
  955. $action = DB::getPDO()->fetchFirst("
  956. select z.ID, z.`DESC`, z.OPIS
  957. from CRM_LISTA_ZASOBOW z
  958. where z.ID = {$idAction}
  959. ");
  960. if (empty($action)) throw new Exception("Action '{$idAction}' not exists");
  961. $idInsertedAction = DB::getPDO()->insert('CRM_LISTA_ZASOBOW', [
  962. 'PARENT_ID' => $idTable,
  963. 'ALIAS_ID' => $idAction,
  964. 'TYPE' => 'URL_ACTION',
  965. 'DESC' => $action['DESC'],
  966. 'OPIS' => V::get('OPIS', $action['DESC'], $action),
  967. ]);
  968. if (!$idInsertedAction) throw new Exception("Nie udało się dodać akcji");
  969. try {
  970. DB::getPDO()->insert('CRM_LISTA_ZASOBOW_HIST', [
  971. 'ID_USERS2' => $idInsertedAction,
  972. 'PARENT_ID' => $idTable,
  973. 'ALIAS_ID' => $idAction,
  974. 'TYPE' => 'URL_ACTION',
  975. 'DESC' => $action['DESC'],
  976. 'OPIS' => V::get('OPIS', $action['DESC'], $action),
  977. ]);
  978. } catch (Exception $e) {
  979. DBG::log($e);
  980. }
  981. return [
  982. 'type' => 'success',
  983. 'msg' => "Dodano akcję - rekord nr {$idInsertedAction}",
  984. '__DBG__' => [
  985. '$args' => $args,
  986. '$idStorage' => $idStorage,
  987. '$tblName' => $tblName,
  988. // '$tblStruct' => $tblStruct,
  989. '$idTable' => $idTable,
  990. '$action' => $action,
  991. ]
  992. ];
  993. }
  994. public function addBaseProcesAction() {
  995. Response::sendTryCatchJson(array($this, 'addBaseProces'), $_REQUEST);
  996. }
  997. public function addBaseProces($args) {
  998. $return = [
  999. 'type' => 'error',
  1000. 'msg' => 'todo: F.' . __FUNCTION__ . ' L.' . __LINE__,
  1001. ];
  1002. $idStorage = V::get('idStorage', 0, $args, 'int');
  1003. if ($idStorage <= 0) throw new HttpException("Missing idStorage", 400);
  1004. $storage = DB::getStorage($idStorage);
  1005. $tblName = V::get('tblName', 0, $args, 'word');
  1006. if (empty($tblName)) throw new HttpException("Missing tblName", 400);
  1007. $tableStruct = $storage->getTableStruct($tblName);
  1008. $return['$tableStruct'] = $tableStruct;
  1009. $idTable = $this->fetchTableId($idStorage, $tblName);
  1010. if ($idTable <= 0) {
  1011. UI::alert('warning', "Zasob tabela '{$tblName}' nie istnieje");// TODO: add p5UI btn
  1012. DBG::table("tblStruct", $tblStruct, __CLASS__, __FUNCTION__, __LINE__);
  1013. throw new Exception("Zasob tabela '{$tblName}' nie istnieje");
  1014. }
  1015. $cellZasobList = array();
  1016. foreach (DB::getPDO()->fetchAllByKey("
  1017. select z.ID, z.`DESC`, z.A_STATUS
  1018. from CRM_LISTA_ZASOBOW z
  1019. where z.PARENT_ID = '{$idTable}'
  1020. ", $key = 'DESC') as $ind => $row) {
  1021. $cellZasobList[strtolower($ind)] = $row;
  1022. }
  1023. $return['$cellZasobList'] = $cellZasobList;
  1024. $idProces = DB::getDB()->ADD_NEW_OBJ('CRM_PROCES', (object)[
  1025. 'TYPE' => 'PROCES_INIT',
  1026. 'DESC' => "Proces dla tabeli '{$tblName}'",
  1027. ]);
  1028. if (!$idProces) throw new Exception("DB ERROR - nie udało się dodać procesu");
  1029. foreach ($cellZasobList as $loverName => $row) {
  1030. DB::getDB()->ADD_NEW_OBJ('CRM_WSKAZNIK', (object)[
  1031. 'ID_PROCES' => $idProces,
  1032. 'ID_ZASOB' => $row['ID'],
  1033. 'TYP' => 'P',
  1034. 'ID_PRZYPADEK' => 2
  1035. ]);
  1036. }
  1037. $return['type'] = 'success';
  1038. $return['msg'] = "Utworzono proces {{$idProces}}";
  1039. return $return;
  1040. }
  1041. public function addGeomEtykietaCellsAction() {
  1042. Response::sendTryCatchJson(array($this, 'addGeomEtykietaCells'), $_REQUEST);
  1043. }
  1044. public function addGeomEtykietaCells($args) {
  1045. $return = [
  1046. 'type' => 'error',
  1047. 'msg' => 'todo: F.' . __FUNCTION__ . ' L.' . __LINE__,
  1048. ];
  1049. $return['_DBG_request'] = $args;
  1050. // idStorage: "36"
  1051. // tblName: "test_geom_linestring"
  1052. $idStorage = V::get('idStorage', 0, $args, 'int');
  1053. if ($idStorage <= 0) throw new HttpException("Missing idStorage", 400);
  1054. $storage = DB::getStorage($idStorage);
  1055. $tblName = V::get('tblName', 0, $args, 'word');
  1056. if (empty($tblName)) throw new HttpException("Missing tblName", 400);
  1057. $tableStruct = $storage->getTableStruct($tblName);
  1058. $return['_DBG_$tableStruct'] = $tableStruct;
  1059. if ('mysql' == DB::getPDO($idStorage)->getType()) {
  1060. $dbName = DB::getPDO($idStorage)->getDatabaseName();
  1061. $fixedTableName = DB::getPDO($idStorage)->fetchValue("
  1062. select t.TABLE_NAME
  1063. from `information_schema`.`TABLES` t
  1064. where t.TABLE_SCHEMA = '{$dbName}'
  1065. and t.TABLE_NAME LIKE '{$tblName}'
  1066. ");
  1067. $return['_DBG_sql_fix__$tblName'] = "
  1068. select t.TABLE_NAME
  1069. from `information_schema`.`TABLES` t
  1070. where t.TABLE_SCHEMA = '{$dbName}'
  1071. and t.TABLE_NAME LIKE '{$tblName}'
  1072. ";
  1073. if (empty($fixedTableName)) return $return;
  1074. if (empty($fixedTableName)) throw new HttpException("Database Error", 500);
  1075. $return['_DBG_$fixedTableName'] = $fixedTableName;
  1076. $tblName = $fixedTableName;
  1077. }
  1078. $return['_DBG_$tableStruct'] = $tableStruct;
  1079. $return['_DBG_has_field__etykieta_x'] = (null != V::geti('etykieta_x', null, $tableStruct));
  1080. $return['_DBG_has_field__etykieta_y'] = (null != V::geti('etykieta_y', null, $tableStruct));
  1081. $return['_DBG_has_field__etykieta_obrot'] = (null != V::geti('etykieta_obrot', null, $tableStruct));
  1082. if (!V::geti('etykieta_x', null, $tableStruct)) {
  1083. try {
  1084. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}_HIST` ADD `etykieta_x` varchar(16) DEFAULT 'N/S;'");
  1085. } catch (Exception $e) {
  1086. $return['__DBG_hist_errors__etykieta_x'] = $e->getMessage();
  1087. }
  1088. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}` ADD `etykieta_x` decimal(16,10) DEFAULT NULL COMMENT 'przesuniecie etykiety elementu w GIS'");
  1089. }
  1090. if (!V::geti('etykieta_y', null, $tableStruct)) {
  1091. try {
  1092. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}_HIST` ADD `etykieta_y` varchar(16) DEFAULT 'N/S;'");
  1093. } catch (Exception $e) {
  1094. $return['__DBG_hist_errors__etykieta_y'] = $e->getMessage();
  1095. }
  1096. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}` ADD `etykieta_y` decimal(16,10) DEFAULT NULL COMMENT 'przesuniecie etykiety elementu w GIS'");
  1097. }
  1098. if (!V::geti('etykieta_obrot', null, $tableStruct)) {
  1099. try {
  1100. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}_HIST` ADD `etykieta_obrot` varchar(16) DEFAULT 'N/S;'");
  1101. } catch (Exception $e) {
  1102. $return['__DBG_hist_errors__etykieta_obrot'] = $e->getMessage();
  1103. }
  1104. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}` ADD `etykieta_obrot` decimal(16,10) DEFAULT NULL");
  1105. }
  1106. return $return;
  1107. }
  1108. public function xsdAction() {
  1109. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  1110. $storage = DB::getStorage($idStorage);
  1111. $tableRealList = $storage->getTableList();
  1112. $srvName = $_SERVER['SERVER_NAME'];
  1113. $storageZasobId = $storage->getZasobId();
  1114. $objNs = "p5_{$storageZasobId}_{$tblName}";
  1115. $objNsUri = "https://biuro.biall-net.pl/api/{$storageZasobId}/{$tblName}";
  1116. $p5TypePrefix = "p5Type";
  1117. $p5TypeNsUri = "http://biuro.biall-net.pl/p5/schema/types";
  1118. $p5TypeNsLocation = "http://biuro.biall-net.pl/p5/schema/types.xsd";
  1119. header('Content-type: text/plain; charset=utf-8');// TODO: test
  1120. //header('Content-type: application/xml; charset=utf-8');
  1121. $xmlWriter = new XMLWriter();
  1122. $xmlWriter->openUri('php://output');
  1123. $xmlWriter->setIndent(true);
  1124. if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404);
  1125. $xmlWriter->startDocument('1.0', 'UTF-8');
  1126. $xmlWriter->startElement('xs:schema');
  1127. $xmlWriter->writeAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema');
  1128. $xmlWriter->writeAttribute('xmlns:vc', 'http://www.w3.org/2007/XMLSchema-versioning');
  1129. $xmlWriter->writeAttribute("xmlns:{$p5TypePrefix}", $p5TypeNsUri);
  1130. $xmlWriter->writeAttribute('elementFormDefault', 'qualified');
  1131. $xmlWriter->writeAttribute('targetNamespace', $objNsUri);
  1132. $xmlWriter->writeAttribute('vc:minVersion', '1.1');
  1133. $xmlWriter->startElement('xs:import');
  1134. $xmlWriter->writeAttribute('namespace', $p5TypeNsUri);
  1135. $xmlWriter->writeAttribute('schemaLocation', $p5TypeNsLocation);
  1136. $xmlWriter->endElement();// xs:import
  1137. foreach ($tableRealList as $tbl) {
  1138. $tblName = $tbl['table_name'];
  1139. $this->tableXsdViewXmlWriter($xmlWriter, $idStorage, $tblName);
  1140. }
  1141. $xmlWriter->endElement();// xs:schema
  1142. $xmlWriter->endDocument();
  1143. }
  1144. public function tableXsdAction() {
  1145. $idStorage = V::get('idStorage', '', $_GET);
  1146. $tblName = V::get('table', '', $_GET, 'word');
  1147. if (empty($tblName)) die("Wrong table name");
  1148. header('Content-type: text/plain; charset=utf-8');// TODO: test
  1149. $storage = DB::getStorage($idStorage);
  1150. $storageZasobId = $storage->getZasobId();
  1151. $objNs = "p5_{$storageZasobId}_{$tblName}";
  1152. $objNsUri = "https://biuro.biall-net.pl/api/{$storageZasobId}/{$tblName}";
  1153. $p5TypePrefix = "p5Type";
  1154. $p5TypeNsUri = "http://biuro.biall-net.pl/p5/schema/types";
  1155. $p5TypeNsLocation = "http://biuro.biall-net.pl/p5/schema/types.xsd";
  1156. //header('Content-type: application/xml; charset=utf-8');
  1157. $xmlWriter = new XMLWriter();
  1158. $xmlWriter->openUri('php://output');
  1159. $xmlWriter->setIndent(true);
  1160. if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404);
  1161. $xmlWriter->startDocument('1.0', 'UTF-8');
  1162. $xmlWriter->startElement('xs:schema');
  1163. $xmlWriter->writeAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema');
  1164. $xmlWriter->writeAttribute('xmlns:vc', 'http://www.w3.org/2007/XMLSchema-versioning');
  1165. $xmlWriter->writeAttribute("xmlns:{$p5TypePrefix}", $p5TypeNsUri);
  1166. $xmlWriter->writeAttribute('elementFormDefault', 'qualified');
  1167. $xmlWriter->writeAttribute('targetNamespace', $objNsUri);
  1168. $xmlWriter->writeAttribute('vc:minVersion', '1.1');
  1169. $xmlWriter->startElement('xs:import');
  1170. $xmlWriter->writeAttribute('namespace', $p5TypeNsUri);
  1171. $xmlWriter->writeAttribute('schemaLocation', $p5TypeNsLocation);
  1172. $xmlWriter->endElement();// xs:import
  1173. $this->tableXsdViewXmlWriter($xmlWriter, $idStorage, $tblName);
  1174. $xmlWriter->endElement();// xs:schema
  1175. $xmlWriter->endDocument();
  1176. }
  1177. public function tableXsdViewXmlWriter(&$xmlWriter, $idStorage, $tblName) {
  1178. $storage = DB::getStorage($idStorage);
  1179. $schema = Schema_TableFactory::build($tblName, $idStorage, $_SERVER['SERVER_NAME']);
  1180. $struct = $schema->getStruct();
  1181. DBG::_('DBG', '>1', "struct", $struct, __CLASS__, __FUNCTION__, __LINE__);
  1182. $typeName = "{$tblName}Type";
  1183. $xmlWriter->startElement('xs:complexType');
  1184. $xmlWriter->writeAttribute('name', $typeName);
  1185. $xmlWriter->startElement('xs:sequence');
  1186. foreach ($struct as $field) {
  1187. $xmlWriter->startElement('xs:element');
  1188. $xmlWriter->writeAttribute('name', $field['name']);
  1189. $xmlWriter->writeAttribute('minOccurs', 0);// TODO: set minOccurs by default, etc.
  1190. if ($field['is_nullable']) $xmlWriter->writeAttribute('nillable', 'true');
  1191. if (null !== $field['default_value']) {
  1192. $xmlWriter->writeAttribute('default', $field['default_value']);
  1193. } else if (null === $field['default_value'] && $field['is_nullable']) {
  1194. $xmlWriter->writeAttribute('default', $field['default_value']);
  1195. } else {
  1196. // TODO: Schema BUG?
  1197. }
  1198. if (empty($field['p5_restrictions'])) {
  1199. $xmlWriter->writeAttribute('type', "p5Type:{$field['p5_type']}");
  1200. } else {
  1201. $xmlWriter->startElement('xs:simpleType');
  1202. $xmlWriter->writeAttribute('base', "p5Type:{$field['p5_type']}");
  1203. $xmlWriter->startElement('xs:restriction');
  1204. if (!empty($field['p5_restrictions']['enumeration'])) {
  1205. foreach ($field['p5_restrictions']['enumeration'] as $enumValue) {
  1206. $xmlWriter->startElement('xs:enumeration');
  1207. $xmlWriter->writeAttribute('value', $enumValue);
  1208. $xmlWriter->endElement();// xs:enumeration
  1209. }
  1210. } else {
  1211. // TODO: another restrictions...
  1212. }
  1213. $xmlWriter->endElement();// xs:restriction
  1214. $xmlWriter->endElement();// xs:simpleType
  1215. }
  1216. $xmlWriter->endElement();// xs:element
  1217. }
  1218. $xmlWriter->endElement();// xs:sequence
  1219. $xmlWriter->endElement();// xs:complexType
  1220. return;
  1221. // <xs:element maxOccurs="1" minOccurs="0" name="{$fldName}" nillable="true" type="xs:integer"/>
  1222. $pKeyField = 'ID';//$storageObject->getPrimaryKeyFieldName();
  1223. //DBG::_(true, true, "struct", $struct, __CLASS__, __FUNCTION__, __LINE__);
  1224. foreach ($struct as $field) {
  1225. $fldName = $vField->getName();
  1226. $fldType = $vField->getType();
  1227. $xsdType = $fldType->getTypeForXsd();
  1228. if ($fldType->hasDefault()) {
  1229. $fldDefault = $fldType->getDefault();
  1230. if (!empty($fldDefault) || '0' === $fldDefault) {
  1231. $elNode->setAttribute('default', $fldDefault);
  1232. }
  1233. }
  1234. $fldRestrictions = $fldType->getRestrictions();
  1235. if (empty($fldRestrictions)) {
  1236. $elNode->setAttribute('type', "{$p5TypePrefix}:{$xsdType}");
  1237. } else {
  1238. $sType = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:simpleType');
  1239. $elNode->appendChild($sType);
  1240. $sTypeRes = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:restriction');
  1241. $sType->appendChild($sTypeRes);
  1242. $sTypeRes->setAttribute('base', "{$p5TypePrefix}:{$xsdType}");
  1243. $enumList = $fldType->getEnumeration();
  1244. if (empty($enumList)) {
  1245. foreach ($fldRestrictions as $restricionName => $restrictionValue) {
  1246. if ('maxLength' == $restricionName) {
  1247. $sTypeResMaxLength = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:maxLength');
  1248. $sTypeRes->appendChild($sTypeResMaxLength);
  1249. $sTypeResMaxLength->setAttribute('value', $restrictionValue);
  1250. } else if ('minLength' == $restricionName) {
  1251. $sTypeResMinLength = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:minLength');
  1252. $sTypeRes->appendChild($sTypeResMinLength);
  1253. $sTypeResMinLength->setAttribute('value', $restrictionValue);
  1254. } else if ('pattern' == $restricionName) {
  1255. $sTypeResPattern = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:pattern');
  1256. $sTypeRes->appendChild($sTypeResPattern);
  1257. $sTypeResPattern->setAttribute('value', $restrictionValue);
  1258. } else if ('fractionDigits' == $restricionName) {
  1259. $sTypeResFractionDigits = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:fractionDigits');
  1260. $sTypeRes->appendChild($sTypeResFractionDigits);
  1261. $sTypeResFractionDigits->setAttribute('value', $restrictionValue);
  1262. } else if ('totalDigits' == $restricionName) {
  1263. $sTypeResTotalDigits = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:totalDigits');
  1264. $sTypeRes->appendChild($sTypeResTotalDigits);
  1265. $sTypeResTotalDigits->setAttribute('value', $restrictionValue);
  1266. } else if ('maxExclusive' == $restricionName) {
  1267. $sTypeResMaxExclusive = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:maxExclusive');
  1268. $sTypeRes->appendChild($sTypeResMaxExclusive);
  1269. $sTypeResMaxExclusive->setAttribute('value', $restrictionValue);
  1270. } else if ('minExclusive' == $restricionName) {
  1271. $sTypeResMinExclusive = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:minExclusive');
  1272. $sTypeRes->appendChild($sTypeResMinExclusive);
  1273. $sTypeResMinExclusive->setAttribute('value', $restrictionValue);
  1274. } else if ('maxInclusive' == $restricionName) {
  1275. $sTypeResMaxInclusive = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:maxInclusive');
  1276. $sTypeRes->appendChild($sTypeResMaxInclusive);
  1277. $sTypeResMaxInclusive->setAttribute('value', $restrictionValue);
  1278. } else if ('minInclusive' == $restricionName) {
  1279. $sTypeResMinInclusive = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:minInclusive');
  1280. $sTypeRes->appendChild($sTypeResMinInclusive);
  1281. $sTypeResMinInclusive->setAttribute('value', $restrictionValue);
  1282. }
  1283. /* TODO: xsd restrictions:
  1284. enumeration Defines a list of acceptable values
  1285. fractionDigits Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero
  1286. length Specifies the exact number of characters or list items allowed. Must be equal to or greater than zero
  1287. maxExclusive Specifies the upper bounds for numeric values (the value must be less than this value)
  1288. maxInclusive Specifies the upper bounds for numeric values (the value must be less than or equal to this value)
  1289. maxLength Specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero
  1290. minExclusive Specifies the lower bounds for numeric values (the value must be greater than this value)
  1291. minInclusive Specifies the lower bounds for numeric values (the value must be greater than or equal to this value)
  1292. minLength Specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero
  1293. pattern Defines the exact sequence of characters that are acceptable
  1294. totalDigits Specifies the exact number of digits allowed. Must be greater than zero
  1295. whiteSpace Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled
  1296. */
  1297. }
  1298. } else {
  1299. foreach ($enumList as $enumValue) {
  1300. $sTypeResEnum = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:enumeration');
  1301. $sTypeRes->appendChild($sTypeResEnum);
  1302. $sTypeResEnum->setAttribute('value', $enumValue);
  1303. }
  1304. }
  1305. }
  1306. }
  1307. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:element');
  1308. $rootNode->appendChild($elNode);
  1309. $elNode->setAttribute('name', $tblName);
  1310. $elNode->setAttribute('type', "{$objNs}:{$typeName}");
  1311. header('Content-type: application/xml');
  1312. echo $dom->saveXML();
  1313. exit;
  1314. }
  1315. public function navView() {
  1316. $backLabel = 'back';
  1317. $backLink = 'index.php?_route=Storage';
  1318. $backDisabled = true;
  1319. $currentLabel = 'Storage';
  1320. $currentLink = 'index.php?_route=Storage';
  1321. if ($task = V::get('_task', '', $_REQUEST)) {
  1322. $currentLink = "index.php?_route=Storage&_task={$task}";
  1323. $backDisabled = false;
  1324. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  1325. $tblName = V::get('table', '', $_REQUEST, 'word');
  1326. $objName = V::get('object', '', $_REQUEST, 'word');
  1327. $namespace = V::get('namespace', '', $_REQUEST, 'word');
  1328. switch ($task) {
  1329. case 'obejctList':
  1330. case 'tableList':
  1331. case 'viewList':
  1332. case 'rawInfo':
  1333. $backLabel = 'Storage';
  1334. $backLink = $this->getLink();
  1335. $currentLink = $this->getLink($task, ['idStorage' => $idStorage]);
  1336. break;
  1337. case 'tableStruct':
  1338. $backLabel = "Tabele [{$idStorage}]";
  1339. $backLink = $this->getLink('tableList', ['idStorage' => $idStorage]);
  1340. $currentLink = $this->getLink($task, ['idStorage' => $idStorage, 'table' => $tblName]);
  1341. break;
  1342. case 'objectStruct':
  1343. $backLabel = "Obiekty [{$idStorage}]";
  1344. $backLink = $this->getLink('tableList', ['idStorage' => $idStorage]);// TODO: mv tableList to objectList
  1345. $currentLink = $this->getLink($task, ['idStorage' => $idStorage, 'namespace' => $namespace]);
  1346. break;
  1347. case 'coreObjectStruct':
  1348. $backLabel = "Obiekty podstawowe";
  1349. $backLink = $this->getLink('coreObjectList', ['idStorage' => $idStorage]);
  1350. $currentLink = $this->getLink($task, ['idStorage' => $idStorage, 'object' => $objName]);
  1351. break;
  1352. }
  1353. switch ($task) {
  1354. case 'tableList': $currentLabel = "Tabele [{$idStorage}]"; break;
  1355. case 'viewList': $currentLabel = "Widoki [{$idStorage}]"; break;
  1356. case 'rawInfo': $currentLabel = "Raw info [{$idStorage}]"; break;
  1357. case 'tableStruct': $currentLabel = "Struktura tabeli '{$tblName}'"; break;
  1358. case 'objectStruct': $currentLabel = "Obiekt '{$namespace}'"; break;
  1359. case 'coreObjectList': $currentLabel = "Obiekty podstawowe"; break;
  1360. case 'coreObjectStruct': $currentLabel = "Obiekt '{$objName}'"; break;
  1361. case 'objectList': $currentLabel = "Obiekty z aktualnej domeny"; break;// TODO: domain from $_GET
  1362. }
  1363. }
  1364. echo UI::h('nav', ['class'=>"navbar navbar-default navbar-static-top", 'style'=>"z-index:999"], [
  1365. UI::h('div', ['class'=>"container-fluid"], [
  1366. UI::h('div', ['class'=>"navbar-left"], [
  1367. UI::h('ul', ['class'=>"nav navbar-nav navbar-center"], [
  1368. UI::h('li', [], [
  1369. UI::h('a', ['href'=>$backLink, 'class'=>"btn" . ($backDisabled ? ' disabled' : '')], '<i class="glyphicon glyphicon-chevron-left"></i> ' . $backLabel)
  1370. ])
  1371. ])
  1372. ]),
  1373. UI::h('div', ['class'=>"navbar-left"], [
  1374. UI::h('ul', ['class'=>"nav navbar-nav navbar-center"], [
  1375. UI::h('li', [], [
  1376. UI::h('a', ['href'=>$currentLink, 'class'=>"btn"], $currentLabel)
  1377. ])
  1378. ])
  1379. ]),
  1380. UI::h('div', ['class'=>"navbar-right"], [
  1381. // <ul class="nav navbar-nav navbar-right">
  1382. // <li><a href="#">Link</a></li>
  1383. // <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
  1384. // <ul class="dropdown-menu">
  1385. // <li><a href="#">Action</a></li>
  1386. // <li><a href="#">Another action</a></li>
  1387. // <li><a href="#">Something else here</a></li>
  1388. // <li role="separator" class="divider"></li>
  1389. // <li><a href="#">Separated link</a></li>
  1390. // </ul>
  1391. // </li>
  1392. // </ul>
  1393. ])
  1394. ])
  1395. ]);
  1396. }
  1397. public function getStorageList() {
  1398. $storageList = array();
  1399. $sth = DB::getPDO()->prepare("
  1400. select z.ID, z.`DESC`, z.`TYPE`
  1401. from CRM_LISTA_ZASOBOW z
  1402. where z.TYPE in('BAZA_DANYCH','DATABASE_MYSQL','DATABASE_POSTGRESQL')
  1403. ");
  1404. $sth->execute();
  1405. $rows = $sth->fetchAll();
  1406. foreach ($rows as $row) {
  1407. $storageList[$row['ID']] = $row;
  1408. }
  1409. return $storageList;
  1410. }
  1411. public function addAclObjectToZasobyAction() {// sends JSON
  1412. $response = new stdClass();
  1413. try {
  1414. $idStorage = V::get('idStorage', '', $_GET);
  1415. $namespace = V::get('namespace', '', $_GET);
  1416. if (empty($idStorage)) throw new HttpException("Missing idStorage param");
  1417. if (empty($namespace)) throw new HttpException("Missing namespace param");
  1418. $objectStorage = SchemaFactory::loadDefaultObject('SystemObject');
  1419. $items = $objectStorage->getItems([
  1420. 'f_namespace' => "={$namespace}",
  1421. ]);
  1422. if (empty($items)) throw new Exception("SystemObject '{$namespace}' not found");
  1423. $objectItem = reset($items);
  1424. if (empty($objectItem)) throw new Exception("SystemObject '{$namespace}' not found");
  1425. DBG::log($objectItem, 'array', 'object acl $objectItem');
  1426. if ($objectItem['idZasob'] > 0) {
  1427. // TODO: check if realy exists? @see SchemaFactory::loadDefaultObject('SystemObject')::updateCache()
  1428. $response->_replaceButtonNode = "[{$objectItem['idZasob']}]";
  1429. throw new AlertInfoException("Zasob '{$objectItem['namespace']}' już istnieje - nr '{$objectItem['idZasob']}'");
  1430. }
  1431. $idZasobFound = 0;
  1432. switch ($objectItem['_type']) {
  1433. case 'TableAcl': $idZasobFound = DB::getPDO()->fetchValue(" select ID from CRM_LISTA_ZASOBOW where PARENT_ID = {$objectItem['idDatabase']} and `DESC` = '{$objectItem['name']}' "); break;
  1434. case 'AntAcl': $idZasobFound = DB::getPDO()->fetchValue(" select ID from CRM_LISTA_ZASOBOW where PARENT_ID = {$objectItem['idDatabase']} and `DESC` = '{$objectItem['namespace']}' "); break;
  1435. default: throw new Exception("Not implemented acl type '{$objectItem['_type']}'");
  1436. }
  1437. if ($idZasobFound > 0) {
  1438. DB::getPDO()->update($objectStorage->_rootTableName, 'namespace', $objectItem['namespace'], [
  1439. 'idZasob' => $idZasobFound
  1440. ]);
  1441. $response->id = $idZasobFound;
  1442. throw new AlertSuccessException("Zasob '{$objectItem['namespace']}' już istnieje - nr '{$idZasobFound}' - cache zaktualizowany");
  1443. }
  1444. try {
  1445. $acl = User::getAcl()->getObjectAcl('default_db', 'crm_lista_zasobow');
  1446. } catch (Exception $e) {
  1447. DBG::log($e);
  1448. throw new Exception("Brak dostępu do tabeli Zasoby");
  1449. }
  1450. if (empty($objectItem['idDatabase'])) throw new Exception("Missing database id");
  1451. if ($idStorage != $objectItem['idDatabase']) throw new Exception("Database id must be the same");
  1452. if (empty($objectItem['_rootTableName'])) throw new Exception("Missing root table name");
  1453. switch ($objectItem['_type']) {
  1454. case 'TableAcl':
  1455. $newZasobItem = [
  1456. 'PARENT_ID' => $objectItem['idDatabase'],
  1457. 'TYPE' => 'TABELA',
  1458. 'DESC' => $objectItem['_rootTableName'],
  1459. 'DESC_PL' => $objectItem['name'],
  1460. ];
  1461. break;
  1462. case 'AntAcl':
  1463. $newZasobItem = [
  1464. 'PARENT_ID' => $objectItem['idDatabase'],
  1465. 'TYPE' => 'TABELA',
  1466. 'DESC' => $objectItem['namespace'],
  1467. 'DESC_PL' => $objectItem['name'],
  1468. ];
  1469. break;
  1470. default: throw new Exception("Not implemented acl type '{$objectItem['_type']}'");
  1471. }
  1472. $idCreated = $acl->addItem($newZasobItem);
  1473. if (!$idCreated) throw new Exception("Nie udało się utworzyć nowego rekordu!");
  1474. try {
  1475. DB::getPDO()->update($objectStorage->_rootTableName, 'namespace', $objectItem['namespace'], [
  1476. 'idZasob' => $idCreated
  1477. ]);
  1478. } catch (Exception $e) {
  1479. DBG::log($e);
  1480. }
  1481. $response->id = $idCreated;
  1482. $response->record = $acl->getItem($idCreated);
  1483. $response->_replaceButtonNode = "[{$idCreated}]";
  1484. throw new AlertSuccessException("Utworzono pomyślnie rekord nr {$idCreated}");
  1485. } catch (AlertSuccessException $e) {
  1486. $response->type = 'success';
  1487. $response->msg = $e->getMessage();
  1488. } catch (AlertInfoException $e) {
  1489. $response->type = 'info';
  1490. $response->msg = $e->getMessage();
  1491. } catch (Exception $e) {
  1492. $response->type = 'error';
  1493. $response->msg = $e->getMessage();
  1494. DBG::log($e);
  1495. }
  1496. Response::sendJsonExit($response);
  1497. }
  1498. public function addFieldToZasobyAction() {
  1499. DBG::log($_REQUEST, 'array', '$_REQUEST');
  1500. Response::sendTryCatchJson(array($this, 'addFieldToZasoby'), $_REQUEST);
  1501. }
  1502. public function addFieldToZasoby($args) {
  1503. $namespace = V::get('namespace', '', $args);
  1504. if (empty($namespace)) throw new HttpException("Missing namespace");
  1505. $fieldItem = SchemaFactory::loadDefaultObject('SystemObjectField')->getItem($namespace);
  1506. $zasobTableName = substr($fieldItem['objectNamespace'], strlen('default_db/'));
  1507. $zasobTableName = (false !== strpos($zasobTableName, '/'))
  1508. ? $fieldItem['objectNamespace']
  1509. : $zasobTableName;
  1510. $zasobItem = DB::getPDO()->fetchFirst("
  1511. select zField.ID, zField.`DESC`, zField.`TYPE`, zField.PARENT_ID
  1512. from CRM_LISTA_ZASOBOW as zField
  1513. join CRM_LISTA_ZASOBOW as zTable on(zTable.ID = zField.PARENT_ID)
  1514. where zTable.PARENT_ID = {$fieldItem['idDatabase']}
  1515. and zTable.`DESC` = '{$zasobTableName}'
  1516. and zTable.`TYPE` = 'TABELA'
  1517. and zField.`DESC` = '{$fieldItem['fieldNamespace']}'
  1518. and zField.`TYPE` = 'KOMORKA'
  1519. ");
  1520. if ($zasobItem) {
  1521. SchemaFactory::loadDefaultObject('SystemObjectField')->updateItem([
  1522. 'namespace' => $namespace,
  1523. 'idZasob' => $zasobItem['ID']
  1524. ]);
  1525. return [
  1526. 'type' => 'success',
  1527. 'msg' => "Zasob już istnieje",
  1528. 'data' => [
  1529. 'id' => $zasobItem['ID']
  1530. ],
  1531. '__DBG__' => [
  1532. $zasobItem,
  1533. $fieldItem,
  1534. $args,
  1535. ]
  1536. ];
  1537. }
  1538. return [
  1539. 'type' => 'success',
  1540. 'msg' => "TODO: addFieldToZasoby",
  1541. 'data' => [
  1542. 'id' => 123
  1543. ],
  1544. '__DBG__' => [
  1545. $zasobItem,
  1546. $fieldItem,
  1547. $args,
  1548. ]
  1549. ];
  1550. // throw new Exception("TODO: F.addFieldToZasoby");
  1551. return [
  1552. 'type' => 'success',
  1553. 'msg' => "TODO: addFieldToZasoby",
  1554. 'data' => [
  1555. 'id' => 123
  1556. ],
  1557. '__DBG__args' => $args
  1558. ];
  1559. }
  1560. public function addCellToZasobyAction() {// sends JSON
  1561. $response = new stdClass();
  1562. try {
  1563. $idStorage = V::get('storageId', '', $_GET);
  1564. $tblName = V::get('tblName', '', $_GET, 'word');
  1565. $cellName = V::get('cellName', '', $_GET, 'word');
  1566. if (empty($tblName)) throw new HttpException("Wrong table name");
  1567. if (empty($tblName)) throw new HttpException("Wrong cell name");
  1568. $storage = DB::getStorage($idStorage);
  1569. $tableStruct = $storage->getTableStruct($tblName);
  1570. $zasobStorageId = $storage->getZasobId();
  1571. if (!is_numeric($zasobStorageId)) throw new HttpException("Storage id is not set in config file");
  1572. $idTable = $this->fetchTableId($zasobStorageId, $tblName);
  1573. if ($idTable <= 0) throw new Exception("Zasob tabela '{$tblName}' nie istnieje");
  1574. try {
  1575. $acl = User::getAcl()->getObjectAcl('default_db', 'crm_lista_zasobow');
  1576. } catch (Exception $e) {
  1577. throw new Exception("Brak dostępu do tabeli Zasoby");
  1578. }
  1579. $item = array();
  1580. $item['PARENT_ID'] = $idTable;
  1581. $item['TYPE'] = 'KOMORKA';
  1582. $item['DESC'] = $cellName;
  1583. $item['DESC_PL'] = $cellName;
  1584. if (DBG::isActive()) $response->_itemToCreate = $item;
  1585. $createdId = $acl->addItem($item);
  1586. if (!$createdId) throw new Exception("Nie udało się utworzyć nowego rekordu!");
  1587. $response->id = $createdId;
  1588. $response->record = $acl->getItem($createdId);
  1589. $response->_replaceButtonNode = "[{$createdId}]";
  1590. throw new AlertSuccessException("Utworzono pomyślnie rekord nr {$createdId}");
  1591. } catch (AlertSuccessException $e) {
  1592. $response->type = 'success';
  1593. $response->msg = $e->getMessage();
  1594. } catch (AlertInfoException $e) {
  1595. $response->type = 'info';
  1596. $response->msg = $e->getMessage();
  1597. } catch (Exception $e) {
  1598. $response->type = 'error';
  1599. $response->msg = $e->getMessage();
  1600. }
  1601. Response::sendJsonExit($response);
  1602. }
  1603. public function fetchTableId($idZasobStorage, $tblName) {
  1604. $rows = DB::getPDO()->fetchAll("
  1605. select z.`ID`, z.`DESC`
  1606. from `CRM_LISTA_ZASOBOW` z
  1607. where z.`PARENT_ID`='{$idZasobStorage}'
  1608. and z.`DESC`='{$tblName}'
  1609. and z.`A_STATUS` in('NORMAL','WAITING')
  1610. ");
  1611. if (!empty($rows)) return (int)$rows[0]['ID'];
  1612. return null;
  1613. }
  1614. public function systemObjectsStructAction() {
  1615. UI::gora();
  1616. UI::menu();
  1617. $this->navView();
  1618. try {
  1619. throw new Exception("TODO: F." . __FUNCTION__ . ' L.' . __LINE__);
  1620. // $coreObjlist = OBJXSD::getSystemObjectsStruct();
  1621. // $objectList = array();
  1622. // foreach ($coreObjlist as $objName) {
  1623. // $objItem = array();
  1624. // $objItem['name'] = $objName;
  1625. // $objItem['struktura'] = '<a href="index.php?_route=Storage&_task=systemObjectsStruct&object=' . $objName . '">' . "struct" . '</a>';
  1626. // // $objItem['label'] = "";// TODO: read from json
  1627. // $objectList[] = $objItem;
  1628. // }
  1629. // usort($objectList, function($rowA, $rowB) {
  1630. // $a = $rowA['nazwa']; $b = $rowB['nazwa'];
  1631. // if ($a == $b) return 0;
  1632. // return ($a < $b) ? -1 : 1;
  1633. // });
  1634. //
  1635. // DBG::table("objectList", $objectList, __CLASS__, __FUNCTION__, __LINE__);
  1636. } catch (Exception $e) {
  1637. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  1638. }
  1639. UI::dol();
  1640. }
  1641. public function systemObjectsAction() {// TableAjax view: index.php?_route=ViewTableAjax&namespace=default_objects/SystemObject
  1642. UI::gora();
  1643. UI::menu();
  1644. $this->navView();
  1645. try {
  1646. Lib::loadClass('Schema_SystemObjectStorageAcl');
  1647. $acl = new Schema_SystemObjectStorageAcl();
  1648. UI::table([
  1649. 'rows' => array_map(
  1650. function ($item) {
  1651. return [
  1652. 'ns' => $item['namespace'],
  1653. 'nazwa' => $item['name'],
  1654. 'type' => $item['_type'],
  1655. 'edit' => '<a href="index.php?_route=ViewTableAjax&namespace=' . $item['namespace'] . '">edit</a>',
  1656. 'wfs Describe' => '<a href="wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=DescribeFeatureType&TYPENAME=' . $item['typeName'] . '">DescribeFeatureType</a>',
  1657. 'wfs getFeature' => '<a href="wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=GetFeature&TYPENAME=' . $item['typeName'] . '&MAXFEATURES=10">GetFeature</a> (max:10)'
  1658. ];
  1659. }
  1660. , $acl->getItems([
  1661. 'order_by' => 'namespace',
  1662. 'order_dir' => 'asc'
  1663. ])
  1664. )
  1665. ]);
  1666. } catch (Exception $e) {
  1667. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  1668. DBG::log($e);
  1669. }
  1670. UI::dol();
  1671. }
  1672. public function objectReinstallAction() {
  1673. UI::gora();
  1674. UI::startContainer();
  1675. try {
  1676. $namespace = V::get('namespace', '', $_GET);
  1677. if (empty($namespace)) throw new Exception("Missing param namespace");
  1678. echo UI::h('h3', [], $namespace);
  1679. Lib::loadClass('Schema_SystemObjectFieldStorageAcl');
  1680. $objFieldAcl = new Schema_SystemObjectFieldStorageAcl();
  1681. $objFieldAcl->updateCache($namespace);
  1682. } catch (Exception $e) {
  1683. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  1684. DBG::log($e);
  1685. }
  1686. UI::endContainer();
  1687. UI::dol();
  1688. }
  1689. }