Storage.php 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434
  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. /*
  9. # Storage:
  10. - [x] view available storage (from Zasoby - type 'BAZA_DANYCH', 'DATABASE_MYSQL', ...)
  11. - [x] check config for connection
  12. - [x] add cells to Zasoby
  13. - [ ] create cells in Storage
  14. - [x] use PDO
  15. */
  16. class Route_Storage extends RouteBase {
  17. public function handleAuth() {
  18. if (!User::logged()) {
  19. User::authByRequest();
  20. }
  21. }
  22. public function defaultAction() {
  23. UI::gora();
  24. UI::menu();
  25. $this->navView();
  26. try {
  27. $storageList = $this->getStorageList();
  28. if (empty($storageList)) throw new Exception("No storage defined");
  29. $storageMenu = array();
  30. foreach ($storageList as $storage) {
  31. $menuItem = array();
  32. $menuItem['id'] = $id = $storage['ID'];
  33. $menuItem['nazwa'] = $storage['DESC'];
  34. $menuItem['typ'] = $storage['TYPE'];
  35. $menuItem['tabele i widoki'] = '<a href="index.php?_route=Storage&_task=tableList&idStorage=' . $id . '">' . "tabele" . '</a>';
  36. //$menuItem['views'] = '<a href="index.php?_route=Storage&_task=viewList&idStorage=' . $id . '">' . "views" . '</a>';
  37. $menuItem['raw info'] = '<a href="index.php?_route=Storage&_task=rawInfo&idStorage=' . $id . '">' . "raw info" . '</a>';
  38. $menuItem['xsd'] = '<a href="index.php?_route=Storage&_task=xsd&idStorage=' . $id . '" target="_blank">' . "xsd" . '</a>';
  39. $storageMenu[] = $menuItem;
  40. }
  41. {// core object list
  42. $menuItem = array();
  43. //$menuItem['id'] = 'Obiekty';
  44. $menuItem['nazwa'] = 'Obiekty podstawowe';
  45. $menuItem['typ'] = 'OBJECTS';
  46. $menuItem['tabele i widoki'] = '<a href="index.php?_route=Storage&_task=coreObjectList">' . "obiekty" . '</a>';
  47. //$menuItem['views'] = '<a href="index.php?_route=Storage&_task=viewList&idStorage=' . $id . '">' . "views" . '</a>';
  48. $menuItem['raw info'] = '<a href="index.php?_route=Storage&_task=coreObjectParseAll">' . "parse All" . '</a>';
  49. // TODO: $menuItem['xsd'] = '<a href="index.php?_route=Storage&_task=xsd&idStorage=' . $id . '" target="_blank">' . "xsd" . '</a>';
  50. $storageMenu[] = $menuItem;
  51. }
  52. {// object list - for current company
  53. $hostName = $_SERVER['SERVER_NAME'];
  54. $cleanHostName = str_replace(array(".", "-"), '_', $hostName);
  55. $menuItem = array();
  56. //$menuItem['id'] = 'Obiekty';
  57. $menuItem['nazwa'] = "Obiekty dla domeny '{$cleanHostName}'";
  58. $menuItem['typ'] = 'OBJECTS';
  59. $menuItem['tabele i widoki'] = '<a href="index.php?_route=Storage&_task=objectList">' . "obiekty" . '</a>';
  60. //$menuItem['views'] = '<a href="index.php?_route=Storage&_task=viewList&idStorage=' . $id . '">' . "views" . '</a>';
  61. //$menuItem['raw info'] = '<a href="index.php?_route=Storage&_task=objectRawInfo">' . "raw info" . '</a>';
  62. // TODO: $menuItem['xsd'] = '<a href="index.php?_route=Storage&_task=xsd&idStorage=' . $id . '" target="_blank">' . "xsd" . '</a>';
  63. $storageMenu[] = $menuItem;
  64. }
  65. {// core object list
  66. $menuItem = array();
  67. //$menuItem['id'] = 'Obiekty';
  68. $menuItem['nazwa'] = 'SystemObjects';
  69. $menuItem['typ'] = 'OBJECTS';
  70. $menuItem['tabele i widoki'] = '<a href="index.php?_route=Storage&_task=systemObjects">' . "SystemObjects" . '</a>';
  71. //$menuItem['views'] = '<a href="index.php?_route=Storage&_task=viewList&idStorage=' . $id . '">' . "views" . '</a>';
  72. // $menuItem['raw info'] = '<a href="index.php?_route=Storage&_task=coreObjectParseAll">' . "parse All" . '</a>';
  73. // TODO: $menuItem['xsd'] = '<a href="index.php?_route=Storage&_task=xsd&idStorage=' . $id . '" target="_blank">' . "xsd" . '</a>';
  74. $storageMenu[] = $menuItem;
  75. }
  76. DBG::table("storageMenu", $storageMenu, __CLASS__, __FUNCTION__, __LINE__);
  77. } catch (Exception $e) {
  78. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  79. }
  80. UI::dol();
  81. }
  82. public function checkObjectInstallAjaxAction() {
  83. $response = array();
  84. try {
  85. $objectName = V::get('object', '', $_REQUEST, 'word');
  86. if (empty($objectName)) throw new Exception("Missing Object name");
  87. $response['object'] = $objectName;
  88. $json = OBJ::getCoreObjectFromFile($objectName);
  89. OBJ::checkInstall($json);
  90. $response['type'] = 'success';
  91. $response['msg'] = "OK - object installed";
  92. } catch (Exception $e) {
  93. $response['type'] = 'error';
  94. $response['msg'] = $e->getMessage();
  95. $response['code'] = $e->getCode();
  96. $response['line'] = $e->getLine();
  97. }
  98. Response::sendJsonExit($response);
  99. }
  100. public function coreObjectStructAction() {
  101. UI::gora();
  102. UI::menu();
  103. $this->navView();
  104. try {
  105. $objectName = V::get('object', '', $_REQUEST, 'word');
  106. if (empty($objectName)) throw new Exception("Missing Object name");
  107. $json = OBJ::getCoreObjectFromFile($objectName);
  108. $label = OBJ::getLabel($json);
  109. $parentList = OBJ::getParentList($json);
  110. $linksParentList = array(); foreach ($parentList as $parentName) {
  111. $parentLink = '<a href="index.php?_route=Storage&_task=coreObjectStruct&object=' . str_replace('/', '-', $parentName) . '">' . $parentName . '</a>';
  112. array_unshift($linksParentList, $parentLink);
  113. }
  114. $ajaxCheckInstall = Request::getPathUri() . "index.php?_route=Storage&_task=checkObjectInstallAjax&object={$objectName}";
  115. $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:checkObjectInstallAjax', { href: '{$ajaxCheckInstall}' })";
  116. $btnCheckInstall = '<a onclick="'.$onClick.'" href="#" title="check install db tables"><i class="glyphicon glyphicon-cog"></i></a>';
  117. UI::startContainer();
  118. UI::tag('h1', [], "Obiekt <code>{$label}</code> <small>{$btnCheckInstall}</small>");
  119. if (!empty($parentList)) {
  120. UI::startTag('ol', ['class'=>"breadcrumb"]);
  121. UI::tag('li', [], "Dziedziczy z:");
  122. foreach ($linksParentList as $parentLink) {
  123. UI::tag('li', [], $parentLink);
  124. }
  125. // <!-- <li class="active">Data</li> -->
  126. UI::endTag('ol');
  127. // <!-- <p> implode(", ", $parentList);</p> -->
  128. }
  129. // TODO: UI::table(['rows'=>array_map()]);
  130. ?>
  131. <table class="table table-bordered table-hovered">
  132. <caption>Struktura:</caption>
  133. <thead>
  134. <tr>
  135. <th>nazwa</th>
  136. <th>typ</th>
  137. <th>label</th>
  138. <th>json</th>
  139. </tr>
  140. </thead>
  141. <tbody>
  142. <?php foreach (OBJ::getFields($json) as $fieldName => $field) : ?>
  143. <tr>
  144. <td><?php echo $fieldName; ?></td>
  145. <td><?php echo $field['type']; ?></td>
  146. <td><?php echo $field['label']; ?></td>
  147. <td><?php echo json_encode($field); ?></td>
  148. </tr>
  149. <?php endforeach; ?>
  150. </tbody>
  151. </table>
  152. <a href="index.php?_route=Storage&_task=coreObjectConnect&object=<?php echo $objectName; ?>" class="btn btn-primary">Przypisz rekordy do klasy</a>
  153. <?php
  154. $mainTable = OBJ::getMainTableName($json);
  155. $sqlFields = OBJ::getTableFields($json);
  156. $this->showTableWidget($mainTable, $sqlFields);
  157. ?>
  158. </div>
  159. <script>
  160. jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:click', function(e, n, payload) {
  161. console.log('event p5UIBtnAjax:Storage:checkObjectInstallAjax:click', n, payload);
  162. });
  163. jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', function(e, n, payload) {
  164. console.log('event p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', n, payload);
  165. if ('success' == payload.type) {
  166. // jQuery(n).parents('td').text(payload.body.id);
  167. }
  168. jQuery.notify(payload.msg, payload.type);
  169. });
  170. </script>
  171. <?php
  172. DBG::_(true, true, "json", $json, __CLASS__, __FUNCTION__, __LINE__);
  173. } catch (Exception $e) {
  174. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  175. }
  176. UI::dol();
  177. }
  178. public function coreObjectConnectAction() {
  179. UI::gora();
  180. UI::menu();
  181. $this->navView();
  182. try {
  183. $objectName = V::get('object', '', $_REQUEST, 'word');
  184. if (empty($objectName)) throw new Exception("Missing Object name");
  185. $json = OBJ::getCoreObjectFromFile($objectName);
  186. $label = OBJ::getLabel($json);
  187. $parentList = OBJ::getParentList($json);
  188. $linksParentList = array(); foreach ($parentList as $parentName) {
  189. $parentLink = '<a href="index.php?_route=Storage&_task=coreObjectStruct&object=' . str_replace('/', '-', $parentName) . '">' . $parentName . '</a>';
  190. array_unshift($linksParentList, $parentLink);
  191. }
  192. $ajaxCheckInstall = Request::getPathUri() . "index.php?_route=Storage&_task=checkObjectInstallAjax&object={$objectName}";
  193. $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:checkObjectInstallAjax', { href: '{$ajaxCheckInstall}' })";
  194. $btnCheckInstall = '<a onclick="'.$onClick.'" href="#" title="check install db tables"><i class="glyphicon glyphicon-cog"></i></a>';
  195. ?>
  196. <div class="container">
  197. <h1>Obiekt <code><?php echo $label; ?></code> <small><?php echo $btnCheckInstall; ?></small></h1>
  198. <?php if (!empty($parentList)) : ?>
  199. <ol class="breadcrumb">
  200. <li>Dziedziczy z:</li>
  201. <?php foreach ($linksParentList as $parentLink) : ?>
  202. <li><?php echo $parentLink; ?></li>
  203. <?php endforeach; ?>
  204. <!-- <li class="active">Data</li> -->
  205. </ol>
  206. <!-- <p> <?php echo implode(", ", $parentList); ?></p> -->
  207. <?php endif; ?>
  208. <?php
  209. $tableOne = array();
  210. $tableOne['caption'] = 'Klasy';
  211. $tableOne['rows'] = array();
  212. $parentList = OBJ::getParentList($json);
  213. $tableOne['rows'][] = array('__primary_key' => $objectName, 'name' => $objectName);
  214. $linksParentList = array(); foreach ($parentList as $parentName) {
  215. // $parentLink = '<a href="index.php?_route=Storage&_task=coreObjectStruct&object=' . str_replace('/', '-', $parentName) . '">' . $parentName . '</a>';
  216. // array_unshift($linksParentList, $parentLink);
  217. $tableOne['rows'][] = array('__primary_key' => $parentName, 'name' => $parentName);
  218. }
  219. $tableTwo = array();
  220. $tableTwo['caption'] = 'Rekordy w tabeli głównej';
  221. $mainTable = OBJ::getMainTableName($json);
  222. $sqlFields = OBJ::getTableFields($json);
  223. $tableTwo['rows'] = $this->getTableRows($mainTable, $sqlFields);
  224. foreach ($tableTwo['rows'] as $idx => $row) {
  225. // $tableTwo['rows'][] = array('__primary_key' => $objectName, 'name' => $objectName);
  226. $tableTwo['rows'][$idx]['__primary_key'] = $row['ID'];
  227. }
  228. echo '<hr>';
  229. // TODO: filter connected rows
  230. // TODO: filter not connected rows
  231. // TODO: action connect rows - args(schema, rows_primary_key_list)
  232. // TODO: action un connect rows - args(schema, rows_primary_key_list)
  233. $this->showConnectSchemaToTableWidget(compact('tableOne', 'tableTwo'));
  234. ?>
  235. </div>
  236. <script>
  237. jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:click', function(e, n, payload) {
  238. console.log('event p5UIBtnAjax:Storage:checkObjectInstallAjax:click', n, payload);
  239. });
  240. jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', function(e, n, payload) {
  241. console.log('event p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', n, payload);
  242. if ('success' == payload.type) {
  243. // jQuery(n).parents('td').text(payload.body.id);
  244. }
  245. jQuery.notify(payload.msg, payload.type);
  246. });
  247. </script>
  248. <?php
  249. DBG::_(true, true, "json", $json, __CLASS__, __FUNCTION__, __LINE__);
  250. } catch (Exception $e) {
  251. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  252. }
  253. UI::dol();
  254. }
  255. public function showConnectSchemaToTableWidget($params) {
  256. if (empty($params['tableOne'])) throw new Exception("Missing tableOne in Connect widget");
  257. if (empty($params['tableTwo'])) throw new Exception("Missing tableTwo in Connect widget");
  258. $tableOne = $params['tableOne'];
  259. $tableTwo = $params['tableTwo'];
  260. // TODO: add p5BtnAjax to table filters button
  261. // TODO: add p5BtnAjax to conn button
  262. $jsEventNamespace = 'ConnectTableWidget' . time();
  263. $htmlIdWrap = "{$jsEventNamespace}-wrap";
  264. $stateLogId = "{$jsEventNamespace}-state-log";
  265. $stateSelectedTotalId = "{$jsEventNamespace}-state-selected";
  266. $stateClearSelectedBtnId = "{$jsEventNamespace}-state-clear-selected-btn";
  267. foreach ($tableOne['rows'] as $idx => $r) {
  268. $tableOne['rows'][$idx]['@onClick'] = "return p5UI__Clickable(this, '{$jsEventNamespace}:tableOne', { primary_key: '{$r['__primary_key']}' });";
  269. }
  270. foreach ($tableTwo['rows'] as $idx => $r) {
  271. $tableTwo['rows'][$idx]['@onClick'] = "return p5UI__Clickable(this, '{$jsEventNamespace}:tableTwo', { primary_key: '{$r['__primary_key']}' });";
  272. }
  273. $tableOne['hidden_cols'] = $tableTwo['hidden_cols'] = array('__primary_key', '@onClick', '__html_id');
  274. $tableTwo['__html_id'] = "{$jsEventNamespace}-table-two";
  275. ?>
  276. <div id="<?php echo $htmlIdWrap; ?>">
  277. <?php UI::table($tableOne); ?>
  278. <div class="btn-group">
  279. <button class="btn btn-default" title="Wybierz rekordy wg instancji"><i class="glyphicon glyphicon-question-sign"></i></button>
  280. <button class="btn btn-default conn-btn-filter-yes">Przypisani</button>
  281. <button class="btn btn-default conn-btn-filter-no active">Nieprzypisani</button>
  282. <button class="btn btn-default conn-btn-filter-clear" title="Wszystkie"><i class="glyphicon glyphicon-remove"></i></button>
  283. </div>
  284. <div class="btn-group">
  285. <span style="padding-left:30px;">Zaznaczono
  286. <span class="conn-selected-total">0</span>
  287. <button class="conn-btn-clear-selected btn btn-link"
  288. onClick="return p5UI__Clickable(this, '<?php echo $jsEventNamespace; ?>:clearSelection', {});"
  289. style="display:none"><i class="glyphicon glyphicon-remove" style="color:red"></i></button>
  290. </span>
  291. </div>
  292. <?php UI::jsAjaxTable($tableTwo); ?>
  293. <pre class="conn-log"></pre>
  294. </div>
  295. <script>
  296. (function(){
  297. var state = {
  298. selectedTableOne: null,
  299. selectedTableTwo: [],
  300. filterSelected: 'no'
  301. }
  302. var props = {
  303. jsEventNamespace: '<?php echo $jsEventNamespace; ?>',
  304. htmlIdWrap: '<?php echo $htmlIdWrap; ?>',
  305. tableTwoId: '#<?php echo $tableTwo['__html_id']; ?>',
  306. stateSelectedTotalId: '#<?php echo $stateSelectedTotalId; ?>',
  307. stateClearSelectedBtnId: '#<?php echo $stateClearSelectedBtnId; ?>',
  308. stateLogId: '#<?php echo $stateLogId; ?>'
  309. }
  310. var wrap = jQuery('#' + props.htmlIdWrap);
  311. var jqNodes = {
  312. wrap: wrap,
  313. filter_yes: wrap.find('.conn-btn-filter-yes'),
  314. filter_no: wrap.find('.conn-btn-filter-no'),
  315. filter_clear: wrap.find('.conn-btn-filter-clear'),
  316. total_selected: wrap.find('.conn-selected-total'),
  317. btn_clear_selected: wrap.find('.conn-btn-clear-selected'),
  318. state_log: wrap.find('.conn-log')
  319. }
  320. function render() {
  321. jqNodes['total_selected'].text(state.selectedTableTwo.length);
  322. if (state.selectedTableTwo.length > 0) {
  323. jQuery(props.stateClearSelectedBtnId).show();
  324. } else {
  325. jQuery(props.stateClearSelectedBtnId).hide();
  326. }
  327. jqNodes['state_log'].text(JSON.stringify(state));
  328. switch (state.filterSelected) {
  329. case 'yes':
  330. jqNodes['filter_yes'].addClass('active');
  331. jqNodes['filter_no'].removeClass('active');
  332. jqNodes['filter_clear'].removeClass('active');
  333. break;
  334. case 'no':
  335. jqNodes['filter_yes'].removeClass('active');
  336. jqNodes['filter_no'].addClass('active');
  337. jqNodes['filter_clear'].removeClass('active');
  338. break;
  339. case 'clear':
  340. jqNodes['filter_yes'].removeClass('active');
  341. jqNodes['filter_no'].removeClass('active');
  342. jqNodes['filter_clear'].addClass('active');
  343. break;
  344. }
  345. }
  346. function action__selectTableOneRow(pk) {
  347. state.selectedTableOne = pk;
  348. render();
  349. }
  350. function action__unselectTableOneRow() {
  351. state.selectedTableOne = null;
  352. render();
  353. }
  354. function action__selectTableTwoRow(pk) {
  355. var idx = state.selectedTableTwo.indexOf(pk);
  356. if (-1 === idx) state.selectedTableTwo.push(pk);
  357. else console.log("Error selectedTableTwo - should be not set");
  358. render();
  359. }
  360. function action__unselectTableTwoRow(pk) {
  361. var idx = state.selectedTableTwo.indexOf(pk);
  362. if (-1 === idx) state.selectedTableTwo.push(pk);
  363. else state.selectedTableTwo.splice(idx, 1);
  364. render();
  365. }
  366. function action__clearSelection() {
  367. state.selectedTableTwo = [];
  368. jQuery(props.tableTwoId).find('tbody').children('.info').removeClass('info');
  369. render();
  370. }
  371. function action__filterSet(fltr) {
  372. state.filterSelected = fltr;
  373. render();
  374. // TODO: ajax load tableTwo based on filter
  375. }
  376. jQuery(document).on(props.jsEventNamespace + ':tableOne:click', function(e, n, payload) {
  377. var n$ = jQuery(n);
  378. console.log('event '+props.jsEventNamespace+':tableOne:click', n, payload);
  379. jQuery.notify('tableOne row clicked [' + payload.props.primary_key + ']', 'info');
  380. if (n$.hasClass('info')) {
  381. n$.removeClass('info');
  382. action__unselectTableOneRow();
  383. } else {
  384. n$.parent().children('.info').removeClass('info');
  385. n$.addClass('info');
  386. action__selectTableOneRow(payload.props.primary_key);
  387. }
  388. });
  389. jQuery(document).on(props.jsEventNamespace + ':tableTwo:click', function(e, n, payload) {
  390. var n$ = jQuery(n);
  391. console.log('event '+props.jsEventNamespace+':tableTwo:click', n, payload);
  392. jQuery.notify('tableTwo row clicked [' + payload.props.primary_key + ']', 'info');
  393. if (n$.hasClass('info')) {
  394. n$.removeClass('info');
  395. action__unselectTableTwoRow(payload.props.primary_key);
  396. } else {
  397. n$.addClass('info');
  398. action__selectTableTwoRow(payload.props.primary_key);
  399. }
  400. });
  401. jQuery(document).on(props.jsEventNamespace + ':clearSelection:click', function(e, n, payload) {
  402. action__clearSelection();
  403. });
  404. jqNodes['filter_yes'].on('click', function(e) {
  405. action__filterSet('yes');
  406. });
  407. jqNodes['filter_no'].on('click', function(e) {
  408. action__filterSet('no');
  409. });
  410. jqNodes['filter_clear'].on('click', function(e) {
  411. action__filterSet('clear');
  412. });
  413. })();
  414. </script>
  415. <?php
  416. }
  417. public function getTableRows($tblName, $fields) {
  418. $sqlFields = array();
  419. foreach ($fields as $fldName) {
  420. $sqlFields[] = "t.`{$fldName}`";
  421. }
  422. $sqlFields = (!empty($sqlFields))? implode(", ", $sqlFields) : "t.*";
  423. $rows = DB::getPDO()->fetchAll("
  424. select {$sqlFields}
  425. from `{$tblName}` t
  426. where 1=1
  427. limit 10
  428. ");
  429. return $rows;
  430. }
  431. public function showTableWidget($tblName, $fields) {
  432. $rows = $this->getTableRows($tblName, $fields);
  433. UI::table(array('caption' => "table({$tblName})", 'rows' => $rows));
  434. }
  435. public function coreObjectParseAllAction() {
  436. UI::gora();
  437. UI::menu();
  438. $this->navView();
  439. try {
  440. OBJ::parseAll();
  441. } catch (Exception $e) {
  442. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  443. }
  444. UI::dol();
  445. }
  446. public function coreObjectListAction() {
  447. UI::gora();
  448. UI::menu();
  449. $this->navView();
  450. try {
  451. $coreObjlist = OBJ::getCoreObjectList();
  452. $objectList = array();
  453. foreach ($coreObjlist as $objName) {
  454. $objItem = array();
  455. $objItem['name'] = $objName;
  456. $objItem['struktura'] = '<a href="index.php?_route=Storage&_task=coreObjectStruct&object=' . $objName . '">' . "struct" . '</a>';
  457. // $objItem['label'] = "";// TODO: read from json
  458. $objectList[] = $objItem;
  459. }
  460. usort($objectList, function($rowA, $rowB) {
  461. $a = $rowA['nazwa']; $b = $rowB['nazwa'];
  462. if ($a == $b) return 0;
  463. return ($a < $b) ? -1 : 1;
  464. });
  465. DBG::table("objectList", $objectList, __CLASS__, __FUNCTION__, __LINE__);
  466. } catch (Exception $e) {
  467. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  468. }
  469. UI::dol();
  470. }
  471. public function objectListAction() {
  472. UI::gora();
  473. UI::menu();
  474. try {
  475. } catch (Exception $e) {
  476. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  477. }
  478. UI::dol();
  479. }
  480. public function tableListAction() {
  481. UI::gora();
  482. UI::menu();
  483. $this->navView();
  484. try {
  485. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  486. if (empty($idStorage)) throw new Exception("No id storage");
  487. $storageList = $this->getStorageList();
  488. if (empty($storageList)) throw new Exception("No storage defined");
  489. if (!array_key_exists($idStorage, $storageList)) throw new Exception("Storage id='{$idStorage}' not exists");
  490. $storagePdo = DB::getStorage($idStorage);
  491. $viewRealList = $storagePdo->getViewList();
  492. $tableRealList = $storagePdo->getTableList();
  493. $tableZasobList = array();
  494. foreach (DB::getPDO()->fetchAllByKey("
  495. select z.ID, z.`DESC`, z.A_STATUS
  496. from CRM_LISTA_ZASOBOW z
  497. where z.PARENT_ID = '{$idStorage}'
  498. ", $key = 'DESC') as $ind => $row) {
  499. $tableZasobList[strtolower($ind)] = $row;
  500. }
  501. $emptyItem = array();
  502. $emptyItem['nazwa'] = '';
  503. $emptyItem['type'] = '';
  504. $emptyItem['id_zasob'] = '';
  505. $emptyItem['struktura'] = '';
  506. $emptyItem['objectTest'] = '';
  507. $emptyItem['xsd'] = '';
  508. $emptyItem['isHist'] = '';
  509. $emptyItem['uwagi'] = '';
  510. $tableList = array();
  511. foreach ($tableRealList as $row) {
  512. $tblName = $row['table_name'];
  513. $tblItem = V::cloneArray($emptyItem);
  514. $tblItem['nazwa'] = $tblName;
  515. $tblItem['type'] = $row['table_type'];
  516. $tblItem['struktura'] = '<a href="index.php?_route=Storage&_task=tableStruct&idStorage=' . $idStorage . '&table=' . $tblName . '">' . "struct" . '</a>';
  517. $tblItem['xsd'] = '<a href="index.php?_route=Storage&_task=tableXsd&idStorage=' . $idStorage . '&table=' . $tblName . '" target="_blank">' . "xsd" . '</a>';
  518. $tblItem['objectTest'] = '<a href="index.php?_route=Storage&_task=objectTest&idStorage=' . $idStorage . '&table=' . $tblName . '">' . "objectTest" . '</a>';
  519. $tblItem['isHist'] = ('_hist' == substr($tblName, -5));
  520. $tblItem['uwagi'] = '';
  521. $tblZasob = V::get($tblName, '', $tableZasobList);
  522. if ($tblZasob) {
  523. $tableZasobList[$tblName]['_checked'] = true;
  524. $tblItem['id_zasob'] = $tblZasob['ID'];
  525. } else {
  526. $tblItem['uwagi'] .= 'TODO: ADD ZASOB';
  527. $ajaxAddZasobLink = Request::getPathUri() . "index.php?_route=Storage&_task=addTableToZasoby&idStorage={$idStorage}&tblName={$tblName}";
  528. $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addTableToZasoby', { href: '{$ajaxAddZasobLink}' })";
  529. $tblItem['id_zasob'] = '<a onclick="'.$onClick.'" class="btn btn-xs btn-primary" href="#">TODO: ADD ZASOB</a>';
  530. }
  531. $tableList[] = $tblItem;
  532. }
  533. foreach ($viewRealList as $row) {
  534. $tblName = $row['table_name'];
  535. $tblItem = V::cloneArray($emptyItem);
  536. $tblItem['nazwa'] = $tblName;
  537. $tblItem['type'] = $row['table_type'];
  538. $tblItem['struktura'] = '<a href="index.php?_route=Storage&_task=viewStruct&idStorage=' . $idStorage . '&table=' . $tblName . '">' . "struct" . '</a>';
  539. $tblItem['uwagi'] = '';
  540. $tblZasob = V::get($tblName, '', $tableZasobList);
  541. if ($tblZasob) {
  542. $tableZasobList[$tblName]['_checked'] = true;
  543. $tblItem['id_zasob'] = $tblZasob['ID'];
  544. } else {
  545. $tblItem['uwagi'] .= 'TODO: ADD ZASOB';
  546. $tblItem['id_zasob'] = 'TODO: ADD ZASOB';
  547. }
  548. $tableList[] = $tblItem;
  549. }
  550. foreach ($tableZasobList as $tblName => $row) {
  551. if (!$row['_checked']) {
  552. $tblItem = V::cloneArray($emptyItem);
  553. $tblItem['nazwa'] = $tblName;
  554. $tblItem['id_zasob'] = $row['ID'];
  555. $tblItem['type'] = 'unknown';
  556. $tblItem['uwagi'] = 'TODO: nie istnieje w bazie danych';
  557. $tableList[] = $tblItem;
  558. }
  559. }
  560. usort($tableList, function($rowA, $rowB) {
  561. $a = $rowA['nazwa']; $b = $rowB['nazwa'];
  562. if ($a == $b) return 0;
  563. $a1 = substr($a, 0, 1); $b1 = substr($b, 0, 1);
  564. if (('_' == $a1 || '_' == $b1) && $a1 != $b1) {
  565. return ($a1 < $b1) ? 1 : -1;
  566. }
  567. return ($a < $b) ? -1 : 1;
  568. });
  569. DBG::table("tableList", $tableList, __CLASS__, __FUNCTION__, __LINE__);
  570. ?>
  571. <script>
  572. jQuery(document).on('p5UIBtnAjax:Storage:addTableToZasoby:click', function(e, n, payload) {
  573. console.log('event p5UIBtnAjax:Storage:addTableToZasoby:click', n, payload);
  574. });
  575. jQuery(document).on('p5UIBtnAjax:Storage:addTableToZasoby:ajaxLoaded', function(e, n, payload) {
  576. console.log('event p5UIBtnAjax:Storage:addTableToZasoby:ajaxLoaded', n, payload);
  577. if ('success' == payload.type && payload.body && payload.body.id > 0) {
  578. jQuery(n).parents('td').text(payload.body.id);
  579. }
  580. jQuery.notify(payload.msg, payload.type);
  581. });
  582. </script>
  583. <?php
  584. } catch (Exception $e) {
  585. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  586. }
  587. UI::dol();
  588. }
  589. public function rawInfoAction() {
  590. UI::gora();
  591. UI::menu();
  592. $this->navView();
  593. try {
  594. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  595. if (empty($idStorage)) throw new Exception("No id storage");
  596. $storageList = $this->getStorageList();
  597. if (empty($storageList)) throw new Exception("No storage defined");
  598. if (!array_key_exists($idStorage, $storageList)) throw new Exception("No id storage not exists");
  599. $storagePdo = DB::getStorage($idStorage);
  600. $rawInfo = $storagePdo->getTableListWithInfo();
  601. DBG::table("rawInfo", $rawInfo, __CLASS__, __FUNCTION__, __LINE__);
  602. } catch (Exception $e) {
  603. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  604. }
  605. UI::dol();
  606. }
  607. public function tableStructAction() {
  608. UI::gora();
  609. UI::menu();
  610. $this->navView();
  611. try {
  612. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  613. if (empty($idStorage)) throw new Exception("No id storage");
  614. $storageList = $this->getStorageList();
  615. if (empty($storageList)) throw new Exception("No storage defined");
  616. if (!array_key_exists($idStorage, $storageList)) throw new Exception("No id storage not exists");
  617. $tblName = V::get('table', '', $_REQUEST, 'word');
  618. if (empty($tblName)) throw new Exception("No table name");
  619. $storagePdo = DB::getStorage($idStorage);
  620. $tblStruct = $storagePdo->getTableStruct($tblName);
  621. $idTable = $this->fetchTableId($idStorage, $tblName);
  622. if ($idTable <= 0) {
  623. UI::alert('warning', "Zasob tabela '{$tblName}' nie istnieje");// TODO: add p5UI btn
  624. DBG::table("tblStruct", $tblStruct, __CLASS__, __FUNCTION__, __LINE__);
  625. throw new Exception("Zasob tabela '{$tblName}' nie istnieje");
  626. }
  627. $cellZasobList = array();
  628. foreach (DB::getPDO()->fetchAllByKey("
  629. select z.ID, z.`DESC`, z.A_STATUS
  630. from CRM_LISTA_ZASOBOW z
  631. where z.PARENT_ID = '{$idTable}'
  632. ", $key = 'DESC') as $ind => $row) {
  633. $cellZasobList[strtolower($ind)] = $row;
  634. }
  635. $emptyItem = array();
  636. $emptyItem['name'] = '';
  637. $emptyItem['id_zasob'] = '';
  638. $emptyItem['uwagi'] = '';
  639. $emptyItem['type'] = '';
  640. $emptyItem['is_nullable'] = '';
  641. $emptyItem['default_value'] = '';
  642. $emptyItem['default_is_null'] = '';
  643. $emptyItem['max_length'] = '';
  644. $emptyItem['num_precision'] = '';
  645. $emptyItem['num_scale'] = '';
  646. $emptyItem['char_encoding'] = '';
  647. $emptyItem['char_collation'] = '';
  648. $emptyItem['extra'] = '';
  649. $emptyItem['raw_storage_type'] = '';
  650. $tableList = array();
  651. foreach ($tblStruct as $row) {
  652. $cellName = $row['name'];
  653. $tblItem = V::cloneArray($emptyItem);
  654. $tblItem['name'] = $cellName;
  655. foreach ($row as $fldName => $fldVal) {
  656. if (array_key_exists($fldName, $tblItem)) $tblItem[$fldName] = $fldVal;
  657. }
  658. $tblItem['uwagi'] = '';
  659. $lowerCellName = strtolower($cellName);
  660. $tblZasob = V::get($lowerCellName, '', $cellZasobList);
  661. if ($tblZasob) {
  662. $cellZasobList[$lowerCellName]['_checked'] = true;
  663. $tblItem['id_zasob'] = $tblZasob['ID'];
  664. } else {
  665. $tblItem['uwagi'] .= '!Zasob';//'TODO: ADD ZASOB';
  666. $ajaxAddZasobLink = Request::getPathUri() . "index.php?_route=Storage&_task=addCellToZasoby&idStorage={$idStorage}&tblName={$tblName}&cellName={$cellName}";
  667. $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addCellToZasoby', { href: '{$ajaxAddZasobLink}' })";
  668. $tblItem['id_zasob'] = '<a onclick="'.$onClick.'" class="btn btn-xs btn-primary" href="#">TODO: ADD ZASOB</a>';
  669. }
  670. $tableList[] = $tblItem;
  671. }
  672. foreach ($cellZasobList as $cellName => $row) {
  673. if (!$row['_checked']) {
  674. $tblItem = V::cloneArray($emptyItem);
  675. $tblItem['name'] = $cellName;
  676. $tblItem['id_zasob'] = $row['ID'];
  677. $tblItem['uwagi'] = '!DB';//'TODO: nie istnieje w bazie danych';
  678. $tableList[] = $tblItem;
  679. }
  680. }
  681. usort($tableList, function($rowA, $rowB) {
  682. $a = $rowA['name']; $b = $rowB['name'];
  683. if ('ID' == $a) return -1;
  684. if ('ID' == $b) return 1;
  685. if ($a == $b) return 0;
  686. $a1 = substr($a, 0, 1); $b1 = substr($b, 0, 1);
  687. if (('_' == $a1 || '_' == $b1) && $a1 != $b1) {
  688. return ($a1 < $b1) ? 1 : -1;
  689. }
  690. return ($a < $b) ? -1 : 1;
  691. });
  692. DBG::table("tableList", $tableList, __CLASS__, __FUNCTION__, __LINE__);
  693. ?>
  694. <script>
  695. jQuery(document).on('p5UIBtnAjax:Storage:addCellToZasoby:click', function(e, n, payload) {
  696. console.log('event p5UIBtnAjax:Storage:addCellToZasoby:click', n, payload);
  697. });
  698. jQuery(document).on('p5UIBtnAjax:Storage:addCellToZasoby:ajaxLoaded', function(e, n, payload) {
  699. console.log('event p5UIBtnAjax:Storage:addCellToZasoby:ajaxLoaded', n, payload);
  700. if ('success' == payload.type && payload.body && payload.body.id > 0) {
  701. var cellUwagi$Node = jQuery(n).parents('td').next('td');
  702. cellUwagi$Node.text(cellUwagi$Node.text().replace('!Zasob', ''))
  703. jQuery(n).parents('td').text(payload.body.id);
  704. jQuery(n).remove();
  705. }
  706. jQuery.notify(payload.msg, payload.type);
  707. });
  708. </script>
  709. <?php
  710. $ajaxAddZasobLink = Request::getPathUri() . "index.php?_route=Storage&_task=addGeomEtykietaCells&idStorage={$idStorage}&tblName={$tblName}";
  711. $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addGeomEtykietaCells', { href: '{$ajaxAddZasobLink}' })";
  712. UI::tag('a', ['onclick'=>$onClick, 'class'=>"btn btn-xs btn-default", 'href'=>"#"], "Dodaj komórki etykiet", true);
  713. echo "<i>(<code>`etykieta_x`</code>, <code>`etykieta_y`</code>, <code>`etykieta_obrot`</code>)</i>";
  714. ?>
  715. <script>
  716. jQuery(document).on('p5UIBtnAjax:Storage:addGeomEtykietaCells:ajaxLoaded', function(e, n, payload) {
  717. console.log('event p5UIBtnAjax:Storage:addGeomEtykietaCells:ajaxLoaded', n, payload);
  718. if ('success' == payload.type && payload.body && payload.body.id > 0) {
  719. var cellUwagi$Node = jQuery(n).parents('td').next('td');
  720. cellUwagi$Node.text(cellUwagi$Node.text().replace('!Zasob', ''))
  721. jQuery(n).parents('td').text(payload.body.id);
  722. jQuery(n).remove();
  723. }
  724. jQuery.notify(payload.msg, payload.type);
  725. });
  726. </script>
  727. <?php
  728. echo '<hr>';
  729. $ajaxAddBaseProcesLink = Request::getPathUri() . "index.php?_route=Storage&_task=addBaseProces&idStorage={$idStorage}&tblName={$tblName}";
  730. $onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addBaseProces', { href: '{$ajaxAddBaseProcesLink}' })";
  731. UI::tag('a', ['onclick'=>$onClick, 'class'=>"btn btn-xs btn-default", 'href'=>"#"], "Dodaj podstawowy proces dla tabeli '{$tblName}' - read only", true);
  732. ?>
  733. <script>
  734. jQuery(document).on('p5UIBtnAjax:Storage:addBaseProces:ajaxLoaded', function(e, n, payload) {
  735. jQuery.notify(payload.msg, payload.type);
  736. });
  737. </script>
  738. <?php
  739. } catch (Exception $e) {
  740. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  741. }
  742. UI::dol();
  743. }
  744. public function addBaseProcesAction() {
  745. Response::sendTryCatchJson(array($this, 'addBaseProces'), $_REQUEST);
  746. }
  747. public function addBaseProces($args) {
  748. $return = [
  749. 'type' => 'error',
  750. 'msg' => 'todo: F.' . __FUNCTION__ . ' L.' . __LINE__,
  751. ];
  752. $idStorage = V::get('idStorage', 0, $args, 'int');
  753. if ($idStorage <= 0) throw new HttpException("Missing idStorage", 400);
  754. $storage = DB::getStorage($idStorage);
  755. $tblName = V::get('tblName', 0, $args, 'word');
  756. if (empty($tblName)) throw new HttpException("Missing tblName", 400);
  757. $tableStruct = $storage->getTableStruct($tblName);
  758. $return['$tableStruct'] = $tableStruct;
  759. $idTable = $this->fetchTableId($idStorage, $tblName);
  760. if ($idTable <= 0) {
  761. UI::alert('warning', "Zasob tabela '{$tblName}' nie istnieje");// TODO: add p5UI btn
  762. DBG::table("tblStruct", $tblStruct, __CLASS__, __FUNCTION__, __LINE__);
  763. throw new Exception("Zasob tabela '{$tblName}' nie istnieje");
  764. }
  765. $cellZasobList = array();
  766. foreach (DB::getPDO()->fetchAllByKey("
  767. select z.ID, z.`DESC`, z.A_STATUS
  768. from CRM_LISTA_ZASOBOW z
  769. where z.PARENT_ID = '{$idTable}'
  770. ", $key = 'DESC') as $ind => $row) {
  771. $cellZasobList[strtolower($ind)] = $row;
  772. }
  773. $return['$cellZasobList'] = $cellZasobList;
  774. $idProces = DB::getDB()->ADD_NEW_OBJ('CRM_PROCES', (object)[
  775. 'TYPE' => 'PROCES_INIT',
  776. 'DESC' => "Proces dla tabeli '{$tblName}'",
  777. ]);
  778. if (!$idProces) throw new Exception("DB ERROR - nie udało się dodać procesu");
  779. foreach ($cellZasobList as $loverName => $row) {
  780. DB::getDB()->ADD_NEW_OBJ('CRM_WSKAZNIK', (object)[
  781. 'ID_PROCES' => $idProces,
  782. 'ID_ZASOB' => $row['ID'],
  783. 'TYP' => 'P',
  784. 'ID_PRZYPADEK' => 2
  785. ]);
  786. }
  787. $return['type'] = 'success';
  788. $return['msg'] = "Utworzono proces {{$idProces}}";
  789. return $return;
  790. }
  791. public function addGeomEtykietaCellsAction() {
  792. Response::sendTryCatchJson(array($this, 'addGeomEtykietaCells'), $_REQUEST);
  793. }
  794. public function addGeomEtykietaCells($args) {
  795. $return = [
  796. 'type' => 'error',
  797. 'msg' => 'todo: F.' . __FUNCTION__ . ' L.' . __LINE__,
  798. ];
  799. $return['_DBG_request'] = $args;
  800. // idStorage: "36"
  801. // tblName: "test_geom_linestring"
  802. $idStorage = V::get('idStorage', 0, $args, 'int');
  803. if ($idStorage <= 0) throw new HttpException("Missing idStorage", 400);
  804. $storage = DB::getStorage($idStorage);
  805. $tblName = V::get('tblName', 0, $args, 'word');
  806. if (empty($tblName)) throw new HttpException("Missing tblName", 400);
  807. $tableStruct = $storage->getTableStruct($tblName);
  808. $return['_DBG_$tableStruct'] = $tableStruct;
  809. if ('mysql' == DB::getPDO($idStorage)->getType()) {
  810. $dbName = DB::getPDO($idStorage)->getDatabaseName();
  811. $fixedTableName = DB::getPDO($idStorage)->fetchValue("
  812. select t.TABLE_NAME
  813. from `information_schema`.`TABLES` t
  814. where t.TABLE_SCHEMA = '{$dbName}'
  815. and t.TABLE_NAME LIKE '{$tblName}'
  816. ");
  817. $return['_DBG_sql_fix__$tblName'] = "
  818. select t.TABLE_NAME
  819. from `information_schema`.`TABLES` t
  820. where t.TABLE_SCHEMA = '{$dbName}'
  821. and t.TABLE_NAME LIKE '{$tblName}'
  822. ";
  823. if (empty($fixedTableName)) return $return;
  824. if (empty($fixedTableName)) throw new HttpException("Database Error", 500);
  825. $return['_DBG_$fixedTableName'] = $fixedTableName;
  826. $tblName = $fixedTableName;
  827. }
  828. $return['_DBG_$tableStruct'] = $tableStruct;
  829. $return['_DBG_has_field__etykieta_x'] = (null != V::geti('etykieta_x', null, $tableStruct));
  830. $return['_DBG_has_field__etykieta_y'] = (null != V::geti('etykieta_y', null, $tableStruct));
  831. $return['_DBG_has_field__etykieta_obrot'] = (null != V::geti('etykieta_obrot', null, $tableStruct));
  832. if (!V::geti('etykieta_x', null, $tableStruct)) {
  833. try {
  834. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}_HIST` ADD `etykieta_x` varchar(16) DEFAULT 'N/S;'");
  835. } catch (Exception $e) {
  836. $return['__DBG_hist_errors__etykieta_x'] = $e->getMessage();
  837. }
  838. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}` ADD `etykieta_x` decimal(16,10) DEFAULT NULL COMMENT 'przesuniecie etykiety elementu w GIS'");
  839. }
  840. if (!V::geti('etykieta_y', null, $tableStruct)) {
  841. try {
  842. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}_HIST` ADD `etykieta_y` varchar(16) DEFAULT 'N/S;'");
  843. } catch (Exception $e) {
  844. $return['__DBG_hist_errors__etykieta_y'] = $e->getMessage();
  845. }
  846. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}` ADD `etykieta_y` decimal(16,10) DEFAULT NULL COMMENT 'przesuniecie etykiety elementu w GIS'");
  847. }
  848. if (!V::geti('etykieta_obrot', null, $tableStruct)) {
  849. try {
  850. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}_HIST` ADD `etykieta_obrot` varchar(16) DEFAULT 'N/S;'");
  851. } catch (Exception $e) {
  852. $return['__DBG_hist_errors__etykieta_obrot'] = $e->getMessage();
  853. }
  854. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}` ADD `etykieta_obrot` decimal(16,10) DEFAULT NULL");
  855. }
  856. return $return;
  857. }
  858. public function xsdAction() {
  859. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  860. $storage = DB::getStorage($idStorage);
  861. $tableRealList = $storage->getTableList();
  862. $srvName = $_SERVER['SERVER_NAME'];
  863. $storageZasobId = $storage->getZasobId();
  864. $objNs = "p5_{$storageZasobId}_{$tblName}";
  865. $objNsUri = "https://biuro.biall-net.pl/api/{$storageZasobId}/{$tblName}";
  866. $p5TypePrefix = "p5Type";
  867. $p5TypeNsUri = "http://biuro.biall-net.pl/p5/schema/types";
  868. $p5TypeNsLocation = "http://biuro.biall-net.pl/p5/schema/types.xsd";
  869. header('Content-type: text/plain; charset=utf-8');// TODO: test
  870. //header('Content-type: application/xml; charset=utf-8');
  871. $xmlWriter = new XMLWriter();
  872. $xmlWriter->openUri('php://output');
  873. $xmlWriter->setIndent(true);
  874. if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404);
  875. $xmlWriter->startDocument('1.0', 'UTF-8');
  876. $xmlWriter->startElement('xs:schema');
  877. $xmlWriter->writeAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema');
  878. $xmlWriter->writeAttribute('xmlns:vc', 'http://www.w3.org/2007/XMLSchema-versioning');
  879. $xmlWriter->writeAttribute("xmlns:{$p5TypePrefix}", $p5TypeNsUri);
  880. $xmlWriter->writeAttribute('elementFormDefault', 'qualified');
  881. $xmlWriter->writeAttribute('targetNamespace', $objNsUri);
  882. $xmlWriter->writeAttribute('vc:minVersion', '1.1');
  883. $xmlWriter->startElement('xs:import');
  884. $xmlWriter->writeAttribute('namespace', $p5TypeNsUri);
  885. $xmlWriter->writeAttribute('schemaLocation', $p5TypeNsLocation);
  886. $xmlWriter->endElement();// xs:import
  887. foreach ($tableRealList as $tbl) {
  888. $tblName = $tbl['table_name'];
  889. $this->tableXsdViewXmlWriter($xmlWriter, $idStorage, $tblName);
  890. }
  891. $xmlWriter->endElement();// xs:schema
  892. $xmlWriter->endDocument();
  893. }
  894. public function tableXsdAction() {
  895. $idStorage = V::get('idStorage', '', $_GET);
  896. $tblName = V::get('table', '', $_GET, 'word');
  897. if (empty($tblName)) die("Wrong table name");
  898. header('Content-type: text/plain; charset=utf-8');// TODO: test
  899. $storage = DB::getStorage($idStorage);
  900. $storageZasobId = $storage->getZasobId();
  901. $objNs = "p5_{$storageZasobId}_{$tblName}";
  902. $objNsUri = "https://biuro.biall-net.pl/api/{$storageZasobId}/{$tblName}";
  903. $p5TypePrefix = "p5Type";
  904. $p5TypeNsUri = "http://biuro.biall-net.pl/p5/schema/types";
  905. $p5TypeNsLocation = "http://biuro.biall-net.pl/p5/schema/types.xsd";
  906. //header('Content-type: application/xml; charset=utf-8');
  907. $xmlWriter = new XMLWriter();
  908. $xmlWriter->openUri('php://output');
  909. $xmlWriter->setIndent(true);
  910. if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404);
  911. $xmlWriter->startDocument('1.0', 'UTF-8');
  912. $xmlWriter->startElement('xs:schema');
  913. $xmlWriter->writeAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema');
  914. $xmlWriter->writeAttribute('xmlns:vc', 'http://www.w3.org/2007/XMLSchema-versioning');
  915. $xmlWriter->writeAttribute("xmlns:{$p5TypePrefix}", $p5TypeNsUri);
  916. $xmlWriter->writeAttribute('elementFormDefault', 'qualified');
  917. $xmlWriter->writeAttribute('targetNamespace', $objNsUri);
  918. $xmlWriter->writeAttribute('vc:minVersion', '1.1');
  919. $xmlWriter->startElement('xs:import');
  920. $xmlWriter->writeAttribute('namespace', $p5TypeNsUri);
  921. $xmlWriter->writeAttribute('schemaLocation', $p5TypeNsLocation);
  922. $xmlWriter->endElement();// xs:import
  923. $this->tableXsdViewXmlWriter($xmlWriter, $idStorage, $tblName);
  924. $xmlWriter->endElement();// xs:schema
  925. $xmlWriter->endDocument();
  926. }
  927. public function tableXsdViewXmlWriter(&$xmlWriter, $idStorage, $tblName) {
  928. $storage = DB::getStorage($idStorage);
  929. $schema = Schema_TableFactory::build($tblName, $idStorage, $_SERVER['SERVER_NAME']);
  930. $struct = $schema->getStruct();
  931. DBG::_('DBG', '>1', "struct", $struct, __CLASS__, __FUNCTION__, __LINE__);
  932. $typeName = "{$tblName}Type";
  933. $xmlWriter->startElement('xs:complexType');
  934. $xmlWriter->writeAttribute('name', $typeName);
  935. $xmlWriter->startElement('xs:sequence');
  936. foreach ($struct as $field) {
  937. $xmlWriter->startElement('xs:element');
  938. $xmlWriter->writeAttribute('name', $field['name']);
  939. $xmlWriter->writeAttribute('minOccurs', 0);// TODO: set minOccurs by default, etc.
  940. if ($field['is_nullable']) $xmlWriter->writeAttribute('nillable', 'true');
  941. if (null !== $field['default_value']) {
  942. $xmlWriter->writeAttribute('default', $field['default_value']);
  943. } else if (null === $field['default_value'] && $field['is_nullable']) {
  944. $xmlWriter->writeAttribute('default', $field['default_value']);
  945. } else {
  946. // TODO: Schema BUG?
  947. }
  948. if (empty($field['p5_restrictions'])) {
  949. $xmlWriter->writeAttribute('type', "p5Type:{$field['p5_type']}");
  950. } else {
  951. $xmlWriter->startElement('xs:simpleType');
  952. $xmlWriter->writeAttribute('base', "p5Type:{$field['p5_type']}");
  953. $xmlWriter->startElement('xs:restriction');
  954. if (!empty($field['p5_restrictions']['enumeration'])) {
  955. foreach ($field['p5_restrictions']['enumeration'] as $enumValue) {
  956. $xmlWriter->startElement('xs:enumeration');
  957. $xmlWriter->writeAttribute('value', $enumValue);
  958. $xmlWriter->endElement();// xs:enumeration
  959. }
  960. } else {
  961. // TODO: another restrictions...
  962. }
  963. $xmlWriter->endElement();// xs:restriction
  964. $xmlWriter->endElement();// xs:simpleType
  965. }
  966. $xmlWriter->endElement();// xs:element
  967. }
  968. $xmlWriter->endElement();// xs:sequence
  969. $xmlWriter->endElement();// xs:complexType
  970. return;
  971. // <xs:element maxOccurs="1" minOccurs="0" name="{$fldName}" nillable="true" type="xs:integer"/>
  972. $pKeyField = 'ID';//$storageObject->getPrimaryKeyFieldName();
  973. //DBG::_(true, true, "struct", $struct, __CLASS__, __FUNCTION__, __LINE__);
  974. foreach ($struct as $field) {
  975. $fldName = $vField->getName();
  976. $fldType = $vField->getType();
  977. $xsdType = $fldType->getTypeForXsd();
  978. if ($fldType->hasDefault()) {
  979. $fldDefault = $fldType->getDefault();
  980. if (!empty($fldDefault) || '0' === $fldDefault) {
  981. $elNode->setAttribute('default', $fldDefault);
  982. }
  983. }
  984. $fldRestrictions = $fldType->getRestrictions();
  985. if (empty($fldRestrictions)) {
  986. $elNode->setAttribute('type', "{$p5TypePrefix}:{$xsdType}");
  987. } else {
  988. $sType = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:simpleType');
  989. $elNode->appendChild($sType);
  990. $sTypeRes = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:restriction');
  991. $sType->appendChild($sTypeRes);
  992. $sTypeRes->setAttribute('base', "{$p5TypePrefix}:{$xsdType}");
  993. $enumList = $fldType->getEnumeration();
  994. if (empty($enumList)) {
  995. foreach ($fldRestrictions as $restricionName => $restrictionValue) {
  996. if ('maxLength' == $restricionName) {
  997. $sTypeResMaxLength = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:maxLength');
  998. $sTypeRes->appendChild($sTypeResMaxLength);
  999. $sTypeResMaxLength->setAttribute('value', $restrictionValue);
  1000. } else if ('minLength' == $restricionName) {
  1001. $sTypeResMinLength = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:minLength');
  1002. $sTypeRes->appendChild($sTypeResMinLength);
  1003. $sTypeResMinLength->setAttribute('value', $restrictionValue);
  1004. } else if ('pattern' == $restricionName) {
  1005. $sTypeResPattern = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:pattern');
  1006. $sTypeRes->appendChild($sTypeResPattern);
  1007. $sTypeResPattern->setAttribute('value', $restrictionValue);
  1008. } else if ('fractionDigits' == $restricionName) {
  1009. $sTypeResFractionDigits = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:fractionDigits');
  1010. $sTypeRes->appendChild($sTypeResFractionDigits);
  1011. $sTypeResFractionDigits->setAttribute('value', $restrictionValue);
  1012. } else if ('totalDigits' == $restricionName) {
  1013. $sTypeResTotalDigits = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:totalDigits');
  1014. $sTypeRes->appendChild($sTypeResTotalDigits);
  1015. $sTypeResTotalDigits->setAttribute('value', $restrictionValue);
  1016. } else if ('maxExclusive' == $restricionName) {
  1017. $sTypeResMaxExclusive = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:maxExclusive');
  1018. $sTypeRes->appendChild($sTypeResMaxExclusive);
  1019. $sTypeResMaxExclusive->setAttribute('value', $restrictionValue);
  1020. } else if ('minExclusive' == $restricionName) {
  1021. $sTypeResMinExclusive = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:minExclusive');
  1022. $sTypeRes->appendChild($sTypeResMinExclusive);
  1023. $sTypeResMinExclusive->setAttribute('value', $restrictionValue);
  1024. } else if ('maxInclusive' == $restricionName) {
  1025. $sTypeResMaxInclusive = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:maxInclusive');
  1026. $sTypeRes->appendChild($sTypeResMaxInclusive);
  1027. $sTypeResMaxInclusive->setAttribute('value', $restrictionValue);
  1028. } else if ('minInclusive' == $restricionName) {
  1029. $sTypeResMinInclusive = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:minInclusive');
  1030. $sTypeRes->appendChild($sTypeResMinInclusive);
  1031. $sTypeResMinInclusive->setAttribute('value', $restrictionValue);
  1032. }
  1033. /* TODO: xsd restrictions:
  1034. enumeration Defines a list of acceptable values
  1035. fractionDigits Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero
  1036. length Specifies the exact number of characters or list items allowed. Must be equal to or greater than zero
  1037. maxExclusive Specifies the upper bounds for numeric values (the value must be less than this value)
  1038. maxInclusive Specifies the upper bounds for numeric values (the value must be less than or equal to this value)
  1039. maxLength Specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero
  1040. minExclusive Specifies the lower bounds for numeric values (the value must be greater than this value)
  1041. minInclusive Specifies the lower bounds for numeric values (the value must be greater than or equal to this value)
  1042. minLength Specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero
  1043. pattern Defines the exact sequence of characters that are acceptable
  1044. totalDigits Specifies the exact number of digits allowed. Must be greater than zero
  1045. whiteSpace Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled
  1046. */
  1047. }
  1048. } else {
  1049. foreach ($enumList as $enumValue) {
  1050. $sTypeResEnum = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:enumeration');
  1051. $sTypeRes->appendChild($sTypeResEnum);
  1052. $sTypeResEnum->setAttribute('value', $enumValue);
  1053. }
  1054. }
  1055. }
  1056. }
  1057. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:element');
  1058. $rootNode->appendChild($elNode);
  1059. $elNode->setAttribute('name', $tblName);
  1060. $elNode->setAttribute('type', "{$objNs}:{$typeName}");
  1061. header('Content-type: application/xml');
  1062. echo $dom->saveXML();
  1063. exit;
  1064. }
  1065. public function navView() {
  1066. $backLabel = 'back';
  1067. $backLink = 'index.php?_route=Storage';
  1068. $backDisabled = true;
  1069. $currentLabel = 'Storage';
  1070. $currentLink = 'index.php?_route=Storage';
  1071. if ($task = V::get('_task', '', $_REQUEST)) {
  1072. $currentLink = "index.php?_route=Storage&_task={$task}";
  1073. $backDisabled = false;
  1074. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  1075. $tblName = V::get('table', '', $_REQUEST, 'word');
  1076. $objName = V::get('object', '', $_REQUEST, 'word');
  1077. switch ($task) {
  1078. case 'tableList':
  1079. case 'viewList':
  1080. case 'rawInfo':
  1081. $backLabel = 'Storage';
  1082. $backLink = 'index.php?_route=Storage';
  1083. $currentLink = "index.php?_route=Storage&_task={$task}&idStorage={$idStorage}";
  1084. break;
  1085. case 'tableStruct':
  1086. $backLabel = "Tabele [{$idStorage}]";
  1087. $backLink = "index.php?_route=Storage&_task=tableList&idStorage={$idStorage}";
  1088. $currentLink = "index.php?_route=Storage&_task={$task}&idStorage={$idStorage}&table={$tblName}";
  1089. break;
  1090. case 'objectStruct': break;
  1091. case 'coreObjectStruct':
  1092. $backLabel = "Obiekty podstawowe";
  1093. $backLink = "index.php?_route=Storage&_task=coreObjectList";
  1094. $currentLink = "index.php?_route=Storage&_task={$task}&object={$objName}";
  1095. break;
  1096. }
  1097. switch ($task) {
  1098. case 'tableList': $currentLabel = "Tabele [{$idStorage}]"; break;
  1099. case 'viewList': $currentLabel = "Widoki [{$idStorage}]"; break;
  1100. case 'rawInfo': $currentLabel = "Raw info [{$idStorage}]"; break;
  1101. case 'tableStruct': $currentLabel = "Struktura tabeli '{$tblName}'"; break;
  1102. case 'coreObjectList': $currentLabel = "Obiekty podstawowe"; break;
  1103. case 'coreObjectStruct': $currentLabel = "Obiekt '{$objName}'"; break;
  1104. case 'objectList': $currentLabel = "Obiekty z aktualnej domeny"; break;// TODO: domain from $_GET
  1105. }
  1106. }
  1107. UI::startTag('nav', ['class'=>"navbar navbar-default navbar-static-top", 'style'=>"z-index:999"]);
  1108. UI::startTag('div', ['class'=>"container-fluid"]);
  1109. UI::startTag('div', ['class'=>"navbar-left"]);
  1110. UI::startTag('ul', ['class'=>"nav navbar-nav navbar-center"]);
  1111. UI::startTag('li');
  1112. UI::tag('a', ['href'=>$backLink, 'class'=>"btn" . ($backDisabled ? ' disabled' : '')], '<i class="glyphicon glyphicon-chevron-left"></i> ' . $backLabel);
  1113. UI::endTag('li');
  1114. UI::endTag('ul');
  1115. UI::endTag('div');
  1116. UI::startTag('div', ['class'=>"navbar-left"]);
  1117. UI::startTag('ul', ['class'=>"nav navbar-nav navbar-center"]);
  1118. UI::startTag('li');
  1119. UI::tag('a', ['href'=>$currentLink, 'class'=>"btn"], $currentLabel);
  1120. UI::endTag('li');
  1121. UI::endTag('ul');
  1122. UI::endTag('div');
  1123. UI::startTag('div', ['class'=>"navbar-right"]);
  1124. // <ul class="nav navbar-nav navbar-right">
  1125. // <li><a href="#">Link</a></li>
  1126. // <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>
  1127. // <ul class="dropdown-menu">
  1128. // <li><a href="#">Action</a></li>
  1129. // <li><a href="#">Another action</a></li>
  1130. // <li><a href="#">Something else here</a></li>
  1131. // <li role="separator" class="divider"></li>
  1132. // <li><a href="#">Separated link</a></li>
  1133. // </ul>
  1134. // </li>
  1135. // </ul>
  1136. UI::endTag('div');
  1137. UI::endTag('div');// .container-fluid
  1138. UI::endTag('nav');
  1139. }
  1140. public function getStorageList() {
  1141. $storageList = array();
  1142. $sth = DB::getPDO()->prepare("
  1143. select z.ID, z.`DESC`, z.`TYPE`
  1144. from CRM_LISTA_ZASOBOW z
  1145. where z.TYPE in('BAZA_DANYCH','DATABASE_MYSQL','DATABASE_POSTGRESQL')
  1146. ");
  1147. $sth->execute();
  1148. $rows = $sth->fetchAll();
  1149. foreach ($rows as $row) {
  1150. $storageList[$row['ID']] = $row;
  1151. }
  1152. return $storageList;
  1153. }
  1154. public function addTableToZasobyAction() {// sends JSON
  1155. $response = new stdClass();
  1156. try {
  1157. $idStorage = V::get('storageId', '', $_GET);
  1158. $tblName = V::get('tblName', '', $_GET, 'word');
  1159. if (empty($tblName)) throw new HttpException("Wrong table name");
  1160. // $response->zasobTblId = $zasobItemFound->TABLE_ID;
  1161. // $response->zasobId = $zasobItemFound->ID;
  1162. $storage = DB::getStorage($idStorage);
  1163. $tableStruct = $storage->getTableStruct($tblName);
  1164. $zasobStorageId = $storage->getZasobId();
  1165. if (!is_numeric($zasobStorageId)) throw new HttpException("Storage id is not set in config file");
  1166. $zasobItem = array();
  1167. $zasobItem['PARENT_ID'] = $zasobStorageId;
  1168. $zasobItem['TYPE'] = 'TABELA';
  1169. $zasobItem['DESC'] = $tblName;
  1170. $zasobItem['DESC_PL'] = $tblName;
  1171. $zasobItemFound = null;
  1172. {
  1173. $rows = DB::getPDO()->fetchAll("
  1174. select z.`ID`, z.`DESC`
  1175. from `CRM_LISTA_ZASOBOW` z
  1176. where z.`PARENT_ID`='{$zasobStorageId}'
  1177. and z.`DESC`='{$tblName}'
  1178. and z.`A_STATUS` in('NORMAL','WAITING')
  1179. ");
  1180. if (!empty($rows)) {
  1181. $zasobItemFound = $rows[0]['ID'];
  1182. }
  1183. }
  1184. if ($zasobItemFound > 0) {
  1185. $response->_replaceButtonNode = "[{$zasobItemFound}]";
  1186. throw new AlertInfoException("Zasob tabela '{$tblName}' już istnieje - nr '{$zasobItemFound}'");
  1187. }
  1188. try {
  1189. $acl = User::getAcl()->getObjectAcl('default_db', 'crm_lista_zasobow');
  1190. } catch (Exception $e) {
  1191. throw new Exception("Brak dostępu do tabeli Zasoby");
  1192. }
  1193. $item = array();
  1194. $item['PARENT_ID'] = $zasobStorageId;
  1195. $item['TYPE'] = 'TABELA';
  1196. $item['DESC'] = $tblName;
  1197. $item['DESC_PL'] = $tblName;
  1198. if (DBG::isActive()) $response->_itemToCreate = $item;
  1199. $createdId = $acl->addItem($item);
  1200. if (!$createdId) throw new Exception("Nie udało się utworzyć nowego rekordu!");
  1201. $response->id = $createdId;
  1202. $response->record = $acl->getItem($createdId);
  1203. $response->_replaceButtonNode = "[{$createdId}]";
  1204. throw new AlertSuccessException("Utworzono pomyślnie rekord nr {$createdId}");
  1205. } catch (AlertSuccessException $e) {
  1206. $response->type = 'success';
  1207. $response->msg = $e->getMessage();
  1208. } catch (AlertInfoException $e) {
  1209. $response->type = 'info';
  1210. $response->msg = $e->getMessage();
  1211. } catch (Exception $e) {
  1212. $response->type = 'error';
  1213. $response->msg = $e->getMessage();
  1214. }
  1215. Response::sendJsonExit($response);
  1216. }
  1217. public function addCellToZasobyAction() {// sends JSON
  1218. $response = new stdClass();
  1219. try {
  1220. $idStorage = V::get('storageId', '', $_GET);
  1221. $tblName = V::get('tblName', '', $_GET, 'word');
  1222. $cellName = V::get('cellName', '', $_GET, 'word');
  1223. if (empty($tblName)) throw new HttpException("Wrong table name");
  1224. if (empty($tblName)) throw new HttpException("Wrong cell name");
  1225. $storage = DB::getStorage($idStorage);
  1226. $tableStruct = $storage->getTableStruct($tblName);
  1227. $zasobStorageId = $storage->getZasobId();
  1228. if (!is_numeric($zasobStorageId)) throw new HttpException("Storage id is not set in config file");
  1229. $idTable = $this->fetchTableId($zasobStorageId, $tblName);
  1230. if ($idTable <= 0) throw new Exception("Zasob tabela '{$tblName}' nie istnieje");
  1231. try {
  1232. $acl = User::getAcl()->getObjectAcl('default_db', 'crm_lista_zasobow');
  1233. } catch (Exception $e) {
  1234. throw new Exception("Brak dostępu do tabeli Zasoby");
  1235. }
  1236. $item = array();
  1237. $item['PARENT_ID'] = $idTable;
  1238. $item['TYPE'] = 'KOMORKA';
  1239. $item['DESC'] = $cellName;
  1240. $item['DESC_PL'] = $cellName;
  1241. if (DBG::isActive()) $response->_itemToCreate = $item;
  1242. $createdId = $acl->addItem($item);
  1243. if (!$createdId) throw new Exception("Nie udało się utworzyć nowego rekordu!");
  1244. $response->id = $createdId;
  1245. $response->record = $acl->getItem($createdId);
  1246. $response->_replaceButtonNode = "[{$createdId}]";
  1247. throw new AlertSuccessException("Utworzono pomyślnie rekord nr {$createdId}");
  1248. } catch (AlertSuccessException $e) {
  1249. $response->type = 'success';
  1250. $response->msg = $e->getMessage();
  1251. } catch (AlertInfoException $e) {
  1252. $response->type = 'info';
  1253. $response->msg = $e->getMessage();
  1254. } catch (Exception $e) {
  1255. $response->type = 'error';
  1256. $response->msg = $e->getMessage();
  1257. }
  1258. Response::sendJsonExit($response);
  1259. }
  1260. public function fetchTableId($idZasobStorage, $tblName) {
  1261. $rows = DB::getPDO()->fetchAll("
  1262. select z.`ID`, z.`DESC`
  1263. from `CRM_LISTA_ZASOBOW` z
  1264. where z.`PARENT_ID`='{$idZasobStorage}'
  1265. and z.`DESC`='{$tblName}'
  1266. and z.`A_STATUS` in('NORMAL','WAITING')
  1267. ");
  1268. if (!empty($rows)) return $rows[0]['ID'];
  1269. return null;
  1270. }
  1271. public function systemObjectsStructAction() {
  1272. UI::gora();
  1273. UI::menu();
  1274. $this->navView();
  1275. try {
  1276. throw new Exception("TODO: F." . __FUNCTION__ . ' L.' . __LINE__);
  1277. // $coreObjlist = OBJXSD::getSystemObjectsStruct();
  1278. // $objectList = array();
  1279. // foreach ($coreObjlist as $objName) {
  1280. // $objItem = array();
  1281. // $objItem['name'] = $objName;
  1282. // $objItem['struktura'] = '<a href="index.php?_route=Storage&_task=systemObjectsStruct&object=' . $objName . '">' . "struct" . '</a>';
  1283. // // $objItem['label'] = "";// TODO: read from json
  1284. // $objectList[] = $objItem;
  1285. // }
  1286. // usort($objectList, function($rowA, $rowB) {
  1287. // $a = $rowA['nazwa']; $b = $rowB['nazwa'];
  1288. // if ($a == $b) return 0;
  1289. // return ($a < $b) ? -1 : 1;
  1290. // });
  1291. //
  1292. // DBG::table("objectList", $objectList, __CLASS__, __FUNCTION__, __LINE__);
  1293. } catch (Exception $e) {
  1294. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  1295. }
  1296. UI::dol();
  1297. }
  1298. public function systemObjectsAction() {
  1299. UI::gora();
  1300. UI::menu();
  1301. $this->navView();
  1302. try {
  1303. Lib::loadClass('Schema_SystemObjectStorageAcl');
  1304. $acl = new Schema_SystemObjectStorageAcl();
  1305. UI::table([
  1306. 'rows' => array_map(
  1307. function ($item) {
  1308. return [
  1309. 'ns' => $item['namespace'],
  1310. 'nazwa' => $item['nazwa'],
  1311. 'edit' => '<a href="index.php?_route=ViewTableAjax&namespace=' . $item['namespace'] . '">edit</a>',
  1312. '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>',
  1313. '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)'
  1314. ];
  1315. }
  1316. , $acl->getItems([
  1317. 'order_by' => 'ID',
  1318. 'order_dir' => 'asc'
  1319. ])
  1320. )
  1321. ]);
  1322. } catch (Exception $e) {
  1323. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  1324. }
  1325. UI::dol();
  1326. }
  1327. }