Storage.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. <?php
  2. // @requires $_SERVER['SERVER_NAME']
  3. Lib::loadClass('RouteBase');
  4. Lib::loadClass('Router');
  5. Lib::loadClass('Schema_TableFactory');
  6. Lib::loadClass('Response');
  7. Lib::loadClass('UI');
  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' => Router::getRoute('Storage_TestXsd')->getLink('', [ 'idStorage' => $item['idZasob'] ]) ], "xsd"),
  59. ];
  60. }, $sourceStorage->getItems())
  61. , [
  62. [
  63. 'Nr zasobu' => '',
  64. 'nazwa' => "Narzędzia systemowe",
  65. 'opis' => "SystemObjects",
  66. 'config?' => '<span class="text text-muted">n/d</span>',
  67. 'obiekty' => UI::h('a', [ 'href' => Router::getRoute('Storage_Tools')->getLink() ], "narzędzia"),
  68. ],
  69. [
  70. 'Nr zasobu' => '',
  71. 'nazwa' => '<span style="color:silver">' . "Obiekty" . '</span>',
  72. 'opis' => '<span style="color:silver">' . "SystemObjects" . '</span>',
  73. 'config?' => '<span class="text text-muted">brak</span>',
  74. 'obiekty' => UI::h('a', [ 'href' => $this->getLink('systemObjects') ], "obiekty"),
  75. ],
  76. [
  77. 'Nr zasobu' => '',
  78. 'nazwa' => '<span style="color:silver">' . "Obiekty Test" . '</span>',
  79. 'opis' => '<span style="color:silver">' . "Obiekty podstawowe (test json)" . '</span>',
  80. 'config?' => '<span class="text text-muted">brak</span>',
  81. 'obiekty' => UI::h('a', [ 'href' => Router::getRoute('Storage_TestObj')->getLink('coreObjectList') ], "obiekty"),
  82. 'raw info' => UI::h('a', [ 'href' => Router::getRoute('Storage_TestObj')->getLink('coreObjectParseAll') ], "raw info"),
  83. ],
  84. [
  85. 'Nr zasobu' => '',
  86. 'nazwa' => '<span style="color:silver">' . "Obiekty Test" . '</span>',
  87. 'opis' => '<span style="color:silver">' . "Obiekty dla domeny '" . str_replace(array(".", "-"), '_', $_SERVER['SERVER_NAME']) . "' (test json)" . '</span>',
  88. 'config?' => '<span class="text text-muted">brak</span>',
  89. 'obiekty' => UI::h('a', [ 'href' => Router::getRoute('Storage_TestObj')->getLink('objectList') ], "obiekty"),
  90. // 'raw info' => UI::h('a', [ 'href' => $this->getLink('objectRawInfo') ], "raw info"),
  91. ],
  92. ]
  93. )
  94. ]);
  95. // $sourceStorage = SchemaFactory::loadDefaultObject('SystemObject');
  96. // $sourceStorage->updateCache();
  97. } catch (Exception $e) {
  98. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  99. }
  100. UI::endContainer();
  101. UI::dol();
  102. }
  103. public function getTableRows($tblName, $fields) {
  104. $sqlFields = array();
  105. foreach ($fields as $fldName) {
  106. $sqlFields[] = "t.`{$fldName}`";
  107. }
  108. $sqlFields = (!empty($sqlFields))? implode(", ", $sqlFields) : "t.*";
  109. $rows = DB::getPDO()->fetchAll("
  110. select {$sqlFields}
  111. from `{$tblName}` t
  112. where 1=1
  113. limit 10
  114. ");
  115. return $rows;
  116. }
  117. public function showTableWidget($tblName, $fields) {
  118. $rows = $this->getTableRows($tblName, $fields);
  119. UI::table(array('caption' => "table({$tblName})", 'rows' => $rows));
  120. }
  121. public function tableListAction() {
  122. UI::gora();
  123. UI::menu();
  124. $this->navView();
  125. UI::startContainer();
  126. try {
  127. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  128. if (empty($idStorage)) throw new Exception("Missing id storage");
  129. $sourceStorage = SchemaFactory::loadDefaultObject('SystemSource');
  130. $sourceItem = $sourceStorage->getItem($idStorage);
  131. if (!$sourceItem) throw new Exception("Storage id='{$idStorage}' not exists");
  132. DBG::log($sourceItem, 'array', '$sourceItem');
  133. // TODO: fetch SystemObject childrens from $sourceItem:
  134. // 1. 'SystemSource' -> getItems([ 'cols' => 'SystemObject/*', 'featureId' => $sourceItem['idZasob'] ])
  135. // 2. 'SystemObject' -> getItems([ 'refFrom' => $sourceItem['idZasob'] ])
  136. // 'default_objects' => _task=systemObjects
  137. $objectStorage = SchemaFactory::loadDefaultObject('SystemObject');
  138. try {
  139. $objectStorage->getTotal();
  140. } catch (Exception $e) {
  141. UI::alert('warning', $e->getMessage());
  142. DBG::log($e);
  143. $objectStorage->updateCache();
  144. UI::alert('info', "Lista obiketów zaktualizowana");
  145. }
  146. if ('1' == V::get('refreshObjectList', '', $_POST)) {
  147. $objectStorage->updateCache();
  148. UI::alert('info', "Lista obiketów zaktualizowana");
  149. }
  150. {
  151. echo UI::h('style', ['type' => "text/css"], "
  152. .p5UI__dropdown-content { min-width:300px; padding:8px; background-color: #f6f6f6; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2) }
  153. .p5UI__dropdown-content a { display:block; color:#000; padding:8px; text-decoration:none }
  154. .p5UI__dropdown-content a:hover { background-color:#ebebeb }
  155. ");
  156. echo UI::h('script', [], "
  157. function p5_Storage_actions_filterInput(n) {
  158. var input, filter, ul, li, a, i, div;
  159. input = n // .id-myInput
  160. filter = input.value.toUpperCase()
  161. div = n.parentNode // .id-myDropdown
  162. a = div.getElementsByTagName('a')
  163. for (i = 0; i < a.length; i++) {
  164. if (a[i].innerHTML.toUpperCase().indexOf(filter) > -1) {
  165. a[i].style.display = ''
  166. } else {
  167. a[i].style.display = 'none'
  168. }
  169. }
  170. }
  171. ");
  172. }
  173. $thisGetLink = array($this, 'getLink');
  174. UI::table([
  175. 'caption' => "Obiekty w bazie '{$sourceItem['name']}' " .
  176. UI::hButtonPost('<i class="glyphicon glyphicon-refresh"></i>' . " odśwież", [
  177. 'class' => "btn btn-xs btn-link",
  178. 'data' => [
  179. 'refreshObjectList' => '1'
  180. ]
  181. ]),
  182. 'rows' => array_map(function ($item) use ($idStorage, $thisGetLink) {
  183. $typeName = $item['typeName']; // $typeName = Api_WfsNs::typeName($item['namespace']);
  184. return [
  185. 'namespace' => '<span style="color:#888">' . substr($item['namespace'], 0, strlen($item['namespace']) - strlen($item['name'])) . '</span>' .
  186. '<span>' . $item['name'] . '</span>',
  187. '_type' => $item['_type'], // TODO: editable?
  188. 'Nr zasobu' => ($item['idZasob'] > 0)
  189. ? $item['idZasob']
  190. : UI::hButtonAjax("Dodaj do zasobów", 'addAclObjectToZasobyAjax', [
  191. 'class' => "btn btn-xs btn-primary",
  192. 'href' => $this->getLink('addAclObjectToZasobyAjax'),
  193. 'data' => [
  194. 'idStorage' => $idStorage,
  195. 'namespace' => $item['namespace'],
  196. ]
  197. ]),
  198. // 'opis' => $item['description'],
  199. 'hasStruct' => ($item['hasStruct']) ? '<span class="label label-success">TAK</span>' : '<span class="text text-muted">nie</span>',
  200. 'installed' => $item['isStructInstalled'] ? '<span class="label label-success">TAK</span>' : '<span class="text text-muted">nie</span>',
  201. 'active?' => $item['isObjectActive'] ? '<span class="label label-success">TAK</span>' : '<span class="text text-muted">nie</span>',
  202. 'menu' => UI::h('div', ['class'=>"p5UI__dropdown-wrap"], [
  203. UI::h('button', ['onClick' => "p5UI__dropdown(event, this, 'left bottom')", 'class' => "btn btn-xs btn-default p5UI__dropdown-btn"], [
  204. '<i class="glyphicon glyphicon-menu-hamburger"></i>',
  205. " menu"
  206. ]),
  207. UI::h('div', ['class' => "p5UI__dropdown-content"], [
  208. UI::h('input', ['type' => "text", 'placeholder' => "Search..", 'class' => "p5UI__dropdown-input", 'onkeyup' => "p5_Storage_actions_filterInput(this)"], null),
  209. UI::h('a', [ 'href' => Router::getRoute('Storage_AclStruct')->getLink('', [ 'namespace' => $item['namespace'] ]) ], "struktura"),
  210. UI::h('a', [ 'href' => $item['reinstallLink'] ], "reinstall"),
  211. UI::h('a', [ 'href' => $this->getLink('rawInfo', [ 'idStorage' => $idStorage, 'table' => $item['name'] ]) ], "raw info"),
  212. UI::h('a', [ 'href' => Router::getRoute('ViewTableAjax')->getLink('', ['namespace' => $item['namespace']]) ], "view table"),
  213. UI::h('a', [ 'href' => Router::getRoute('ViewObject')->getLink('', ['namespace' => $item['namespace']]) ], "view object"),
  214. // 'xsd' => UI::h('a', [ 'href' => Router::getRoute('Storage_TestXsd')->getLink('', [ 'idStorage' => $idStorage ]) ], "xsd"),
  215. UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=DescribeFeatureType&TYPENAME={$typeName}" ], "wfs DescribeFeatureType"),
  216. UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=DescribeFeatureTypeAdvanced&TYPENAME={$typeName}" ], "wfs DescribeFeatureTypeAdvanced"),
  217. 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)"),
  218. 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)"),
  219. UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=GetFeature&TYPENAME={$typeName}&MAXFEATURES=3&resolve=all&resolveDepth=3" ], "wfs GetFeature (max: 3, resolveDepth: 3)"),
  220. UI::h('a', [ 'href' => "index.php?_route=WfsJsRequestPanel&namespace={$item['namespace']}" ], "JavaScript WFS Panel"),
  221. ])
  222. ]),
  223. ];
  224. }, $objectStorage->getItems([
  225. '#refFrom' => [
  226. 'namespace' => 'default_objects/SystemSource',
  227. 'primaryKey' => $sourceItem['idZasob']
  228. ],
  229. 'order_by' => 'namespace',
  230. 'order_dir' => 'asc'
  231. ]))
  232. ]);
  233. UI::hButtonAjaxOnResponse('addAclObjectToZasobyAjax', /* payload, n */ "
  234. if (!payload.type) return false
  235. if ('success' === payload.type || 'info' === payload.type) {
  236. if (payload.body && payload.body.id && payload.body.id > 0) {
  237. n.parentNode.replaceChild(document.createTextNode(payload.body.id), n)
  238. } else {
  239. console.log('TODO: addAclObjectToZasobyAjax unknown response', payload);
  240. }
  241. jQuery.notify(payload.msg, payload.type);
  242. }
  243. ");
  244. } catch (Exception $e) {
  245. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  246. DBG::log($e);
  247. }
  248. UI::endContainer();
  249. UI::dol();
  250. }
  251. public function rawInfoAction() {
  252. UI::gora();
  253. UI::menu();
  254. $this->navView();
  255. try {
  256. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  257. if (empty($idStorage)) throw new Exception("Missing id storage");
  258. $storageList = $this->getStorageList();
  259. if (empty($storageList)) throw new Exception("No storage defined");
  260. if (!array_key_exists($idStorage, $storageList)) throw new Exception("Storage not exists");
  261. $storagePdo = DB::getStorage($idStorage);
  262. $rawInfo = $storagePdo->getTableListWithInfo();
  263. DBG::table("rawInfo", $rawInfo, __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 fetchActionListAjaxAction() {
  270. Response::sendTryCatchJson(array($this, 'fetchActionListAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  271. }
  272. public function fetchActionListAjax($args) {
  273. return [
  274. 'type' => 'success',
  275. '__args' => $args,
  276. 'options' => DB::getPDO()->fetchAll("
  277. select z.ID, z.`DESC`, z.OPIS
  278. from CRM_LISTA_ZASOBOW z
  279. where z.`TYPE` = 'URL_ACTION'
  280. and z.A_STATUS != 'DELETED'
  281. and z.ALIAS_ID = 0
  282. ")
  283. ];
  284. }
  285. public function addActionAjaxAction() {
  286. Response::sendTryCatchJson(array($this, 'addActionAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  287. }
  288. public function addActionAjax($args) {
  289. $idStorage = V::get('idStorage', 0, $args, 'int');
  290. if ($idStorage <= 0) throw new Exception("Missing id storage");
  291. $idAction = V::get('idAction', 0, $args, 'int');
  292. if ($idAction <= 0) throw new Exception("Missing id action");
  293. $storageList = $this->getStorageList();
  294. if (empty($storageList)) throw new Exception("No storage defined");
  295. if (!array_key_exists($idStorage, $storageList)) throw new Exception("Storage not exists");
  296. $tblName = V::get('table', '', $args, 'word');
  297. if (empty($tblName)) throw new Exception("No table name");
  298. $storagePdo = DB::getStorage($idStorage);
  299. // $tblStruct = $storagePdo->getTableStruct($tblName);
  300. $idTable = $this->fetchTableId($idStorage, $tblName);
  301. if ($idTable <= 0) throw new Exception("Zasob tabela '{$tblName}' nie istnieje");
  302. $action = DB::getPDO()->fetchFirst("
  303. select z.ID, z.`DESC`, z.OPIS
  304. from CRM_LISTA_ZASOBOW z
  305. where z.ID = {$idAction}
  306. ");
  307. if (empty($action)) throw new Exception("Action '{$idAction}' not exists");
  308. $idInsertedAction = DB::getPDO()->insert('CRM_LISTA_ZASOBOW', [
  309. 'PARENT_ID' => $idTable,
  310. 'ALIAS_ID' => $idAction,
  311. 'TYPE' => 'URL_ACTION',
  312. 'DESC' => $action['DESC'],
  313. 'OPIS' => V::get('OPIS', $action['DESC'], $action),
  314. ]);
  315. if (!$idInsertedAction) throw new Exception("Nie udało się dodać akcji");
  316. try {
  317. DB::getPDO()->insert('CRM_LISTA_ZASOBOW_HIST', [
  318. 'ID_USERS2' => $idInsertedAction,
  319. 'PARENT_ID' => $idTable,
  320. 'ALIAS_ID' => $idAction,
  321. 'TYPE' => 'URL_ACTION',
  322. 'DESC' => $action['DESC'],
  323. 'OPIS' => V::get('OPIS', $action['DESC'], $action),
  324. ]);
  325. } catch (Exception $e) {
  326. DBG::log($e);
  327. }
  328. return [
  329. 'type' => 'success',
  330. 'msg' => "Dodano akcję - rekord nr {$idInsertedAction}",
  331. '__DBG__' => [
  332. '$args' => $args,
  333. '$idStorage' => $idStorage,
  334. '$tblName' => $tblName,
  335. // '$tblStruct' => $tblStruct,
  336. '$idTable' => $idTable,
  337. '$action' => $action,
  338. ]
  339. ];
  340. }
  341. public function addTableBaseProcesAction() {
  342. Response::sendTryCatchJson(array($this, 'addTableBaseProces'), $_REQUEST);
  343. }
  344. public function addTableBaseProces($args) {
  345. $return = [
  346. 'type' => 'error',
  347. 'msg' => 'todo: F.' . __FUNCTION__ . ' L.' . __LINE__,
  348. ];
  349. $idStorage = V::get('idStorage', 0, $args, 'int');
  350. if ($idStorage <= 0) throw new HttpException("Missing idStorage", 400);
  351. $storage = DB::getStorage($idStorage);
  352. $tblName = V::get('tblName', 0, $args, 'word');
  353. if (empty($tblName)) throw new HttpException("Missing tblName", 400);
  354. $tableStruct = $storage->getTableStruct($tblName);
  355. $return['$tableStruct'] = $tableStruct;
  356. $idTable = $this->fetchTableId($idStorage, $tblName);
  357. if ($idTable <= 0) {
  358. UI::alert('warning', "Zasob tabela '{$tblName}' nie istnieje");// TODO: add p5UI btn
  359. DBG::table("tblStruct", $tblStruct, __CLASS__, __FUNCTION__, __LINE__);
  360. throw new Exception("Zasob tabela '{$tblName}' nie istnieje");
  361. }
  362. $cellZasobList = array();
  363. foreach (DB::getPDO()->fetchAllByKey("
  364. select z.ID, z.`DESC`, z.A_STATUS
  365. from CRM_LISTA_ZASOBOW z
  366. where z.PARENT_ID = '{$idTable}'
  367. ", $key = 'DESC') as $ind => $row) {
  368. $cellZasobList[strtolower($ind)] = $row;
  369. }
  370. $return['$cellZasobList'] = $cellZasobList;
  371. $idProces = DB::getDB()->ADD_NEW_OBJ('CRM_PROCES', (object)[
  372. 'TYPE' => 'PROCES_INIT',
  373. 'DESC' => "Proces dla tabeli '{$tblName}'",
  374. ]);
  375. if (!$idProces) throw new Exception("DB ERROR - nie udało się dodać procesu");
  376. foreach ($cellZasobList as $loverName => $row) {
  377. DB::getDB()->ADD_NEW_OBJ('CRM_WSKAZNIK', (object)[
  378. 'ID_PROCES' => $idProces,
  379. 'ID_ZASOB' => $row['ID'],
  380. 'TYP' => 'P',
  381. 'ID_PRZYPADEK' => 2
  382. ]);
  383. }
  384. $return['type'] = 'success';
  385. $return['msg'] = "Utworzono proces {{$idProces}}";
  386. return $return;
  387. }
  388. public function addObjectBaseProcesAjaxAction() {
  389. Response::sendTryCatchJson(array($this, 'addObjectBaseProcesAjax'), $_REQUEST);
  390. }
  391. public function addObjectBaseProcesAjax($args) {
  392. $return = [
  393. 'type' => 'error',
  394. 'msg' => 'todo: F.' . __FUNCTION__ . ' L.' . __LINE__,
  395. ];
  396. $namespace = V::get('namespace', 0, $args);
  397. if (empty($namespace)) throw new HttpException("Missing namespace", 400);
  398. $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
  399. DBG::log($item, 'array', "TODO: addObjectBaseProcesAjax for \$item");
  400. if (!$item['idZasob']) throw new Exception("Missing id zasob for object '{$namespace}'");
  401. if (!$item['idDatabase']) throw new Exception("Missing id database for object '{$namespace}'");
  402. if (!$item['_rootTableName']) throw new Exception("Missing root table name for object '{$namespace}'");
  403. if ('AntAcl' != $item['_type']) throw new Exception("Not implemented type '{$item['_type']}' for namespace '{$namespace}' - only AntAcl supported");
  404. if (!$item['hasStruct']) throw new Exception("Missing structure for object '{$namespace}'");
  405. if (!$item['isStructInstalled']) throw new Exception("Structure not installed for object '{$namespace}'");
  406. if (!$item['isObjectActive']) throw new Exception("Object is not active '{$namespace}'");
  407. $fieldsWithIdZasob = array_filter($item['field'], function ($field) {
  408. if (!$field['idZasob']) return false;
  409. return true;
  410. });
  411. if (empty($fieldsWithIdZasob)) throw new Exception("Missing fields with id zasob in object '{$namespace}'");
  412. $idProces = DB::getDB()->ADD_NEW_OBJ('CRM_PROCES', (object)[
  413. 'TYPE' => 'PROCES_INIT',
  414. 'DESC' => "TODO: Proces dla obiektu '{$namespace}'",
  415. ]);
  416. if (!$idProces) throw new Exception("DB ERROR - nie udało się dodać procesu");
  417. array_map(function ($field) use ($idProces) {
  418. DB::getDB()->ADD_NEW_OBJ('CRM_WSKAZNIK', (object)[
  419. 'ID_PROCES' => $idProces,
  420. 'ID_ZASOB' => $field['idZasob'],
  421. 'TYP' => 'P',
  422. 'ID_PRZYPADEK' => 2
  423. ]);
  424. }, $fieldsWithIdZasob);
  425. $return['type'] = 'success';
  426. $return['msg'] = "Utworzono proces {{$idProces}}";
  427. return $return;
  428. }
  429. public function addGeomEtykietaCellsAction() {
  430. Response::sendTryCatchJson(array($this, 'addGeomEtykietaCells'), $_REQUEST);
  431. }
  432. public function addGeomEtykietaCells($args) {
  433. $return = [
  434. 'type' => 'error',
  435. 'msg' => 'todo: F.' . __FUNCTION__ . ' L.' . __LINE__,
  436. ];
  437. $return['_DBG_request'] = $args;
  438. // idStorage: "36"
  439. // tblName: "test_geom_linestring"
  440. $idStorage = V::get('idStorage', 0, $args, 'int');
  441. if ($idStorage <= 0) throw new HttpException("Missing idStorage", 400);
  442. $storage = DB::getStorage($idStorage);
  443. $tblName = V::get('tblName', 0, $args, 'word');
  444. if (empty($tblName)) throw new HttpException("Missing tblName", 400);
  445. $tableStruct = $storage->getTableStruct($tblName);
  446. $return['_DBG_$tableStruct'] = $tableStruct;
  447. if ('mysql' == DB::getPDO($idStorage)->getType()) {
  448. $dbName = DB::getPDO($idStorage)->getDatabaseName();
  449. $fixedTableName = DB::getPDO($idStorage)->fetchValue("
  450. select t.TABLE_NAME
  451. from `information_schema`.`TABLES` t
  452. where t.TABLE_SCHEMA = '{$dbName}'
  453. and t.TABLE_NAME LIKE '{$tblName}'
  454. ");
  455. $return['_DBG_sql_fix__$tblName'] = "
  456. select t.TABLE_NAME
  457. from `information_schema`.`TABLES` t
  458. where t.TABLE_SCHEMA = '{$dbName}'
  459. and t.TABLE_NAME LIKE '{$tblName}'
  460. ";
  461. if (empty($fixedTableName)) return $return;
  462. if (empty($fixedTableName)) throw new HttpException("Database Error", 500);
  463. $return['_DBG_$fixedTableName'] = $fixedTableName;
  464. $tblName = $fixedTableName;
  465. }
  466. $return['_DBG_$tableStruct'] = $tableStruct;
  467. $return['_DBG_has_field__etykieta_x'] = (null != V::geti('etykieta_x', null, $tableStruct));
  468. $return['_DBG_has_field__etykieta_y'] = (null != V::geti('etykieta_y', null, $tableStruct));
  469. $return['_DBG_has_field__etykieta_obrot'] = (null != V::geti('etykieta_obrot', null, $tableStruct));
  470. if (!V::geti('etykieta_x', null, $tableStruct)) {
  471. try {
  472. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}_HIST` ADD `etykieta_x` varchar(16) DEFAULT 'N/S;'");
  473. } catch (Exception $e) {
  474. $return['__DBG_hist_errors__etykieta_x'] = $e->getMessage();
  475. }
  476. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}` ADD `etykieta_x` decimal(16,10) DEFAULT NULL COMMENT 'przesuniecie etykiety elementu w GIS'");
  477. }
  478. if (!V::geti('etykieta_y', null, $tableStruct)) {
  479. try {
  480. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}_HIST` ADD `etykieta_y` varchar(16) DEFAULT 'N/S;'");
  481. } catch (Exception $e) {
  482. $return['__DBG_hist_errors__etykieta_y'] = $e->getMessage();
  483. }
  484. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}` ADD `etykieta_y` decimal(16,10) DEFAULT NULL COMMENT 'przesuniecie etykiety elementu w GIS'");
  485. }
  486. if (!V::geti('etykieta_obrot', null, $tableStruct)) {
  487. try {
  488. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}_HIST` ADD `etykieta_obrot` varchar(16) DEFAULT 'N/S;'");
  489. } catch (Exception $e) {
  490. $return['__DBG_hist_errors__etykieta_obrot'] = $e->getMessage();
  491. }
  492. DB::getPDO($idStorage)->exec("ALTER TABLE `{$tblName}` ADD `etykieta_obrot` decimal(16,10) DEFAULT NULL");
  493. }
  494. return $return;
  495. }
  496. public function navView() {
  497. $backLabel = 'back';
  498. $backLink = 'index.php?_route=Storage';
  499. $backDisabled = true;
  500. $currentLabel = 'Storage';
  501. $currentLink = 'index.php?_route=Storage';
  502. if ($task = V::get('_task', '', $_REQUEST)) {
  503. $currentLink = "index.php?_route=Storage&_task={$task}";
  504. $backDisabled = false;
  505. $idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
  506. $tblName = V::get('table', '', $_REQUEST, 'word');
  507. $objName = V::get('object', '', $_REQUEST, 'word');
  508. $namespace = V::get('namespace', '', $_REQUEST, 'word');
  509. switch ($task) {
  510. case 'obejctList':
  511. $backLabel = 'Storage';
  512. $backLink = $this->getLink();
  513. $currentLink = $this->getLink('obejctList', ['idStorage' => $idStorage]);
  514. break;
  515. case 'tableList':
  516. $backLabel = 'Storage';
  517. $backLink = $this->getLink();
  518. $currentLink = $this->getLink('tableList', ['idStorage' => $idStorage]);
  519. break;
  520. case 'viewList':
  521. $backLabel = 'Storage';
  522. $backLink = $this->getLink();
  523. $currentLink = $this->getLink('viewList', ['idStorage' => $idStorage]);
  524. break;
  525. case 'rawInfo':
  526. $backLabel = 'Storage';
  527. $backLink = $this->getLink();
  528. $currentLink = $this->getLink('rawInfo', ['idStorage' => $idStorage]);
  529. break;
  530. case 'tableStruct':
  531. $backLabel = "Tabele [{$idStorage}]";
  532. $backLink = $this->getLink('tableList', ['idStorage' => $idStorage]);
  533. $currentLink = $this->getLink('tableStruct', ['idStorage' => $idStorage, 'table' => $tblName]);
  534. break;
  535. case 'objectStruct':
  536. $backLabel = "Obiekty [{$idStorage}]";
  537. $backLink = $this->getLink('tableList', ['idStorage' => $idStorage]);// TODO: mv tableList to objectList
  538. $currentLink = $this->getLink('objectStruct', ['idStorage' => $idStorage, 'namespace' => $namespace]);
  539. break;
  540. case 'coreObjectStruct':
  541. $backLabel = "Obiekty podstawowe";
  542. $backLink = Router::getRoute('Storage_TestObj')->getLink('coreObjectList', ['idStorage' => $idStorage]);
  543. $currentLink = $this->getLink('coreObjectStruct', ['idStorage' => $idStorage, 'object' => $objName]);
  544. break;
  545. }
  546. switch ($task) {
  547. case 'tableList': $currentLabel = "Tabele [{$idStorage}]"; break;
  548. case 'viewList': $currentLabel = "Widoki [{$idStorage}]"; break;
  549. case 'rawInfo': $currentLabel = "Raw info [{$idStorage}]"; break;
  550. case 'tableStruct': $currentLabel = "Struktura tabeli '{$tblName}'"; break;
  551. case 'objectStruct': $currentLabel = "Obiekt '{$namespace}'"; break;
  552. case 'coreObjectList': $currentLabel = "Obiekty podstawowe"; break;
  553. case 'coreObjectStruct': $currentLabel = "Obiekt '{$objName}'"; break;
  554. case 'objectList': $currentLabel = "Obiekty z aktualnej domeny"; break;// TODO: domain from $_GET
  555. }
  556. }
  557. echo UI::h('nav', ['class'=>"navbar navbar-default navbar-static-top", 'style'=>"z-index:999"], [
  558. UI::h('div', ['class'=>"container-fluid"], [
  559. UI::h('div', ['class'=>"navbar-left"], [
  560. UI::h('ul', ['class'=>"nav navbar-nav navbar-center"], [
  561. UI::h('li', [], [
  562. UI::h('a', ['href'=>$backLink, 'class'=>"btn" . ($backDisabled ? ' disabled' : '')], '<i class="glyphicon glyphicon-chevron-left"></i> ' . $backLabel)
  563. ])
  564. ])
  565. ]),
  566. UI::h('div', ['class'=>"navbar-left"], [
  567. UI::h('ul', ['class'=>"nav navbar-nav navbar-center"], [
  568. UI::h('li', [], [
  569. UI::h('a', ['href'=>$currentLink, 'class'=>"btn"], $currentLabel)
  570. ])
  571. ])
  572. ]),
  573. UI::h('div', ['class'=>"navbar-right"], [
  574. // <ul class="nav navbar-nav navbar-right">
  575. // <li><a href="#">Link</a></li>
  576. // <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>
  577. // <ul class="dropdown-menu">
  578. // <li><a href="#">Action</a></li>
  579. // <li><a href="#">Another action</a></li>
  580. // <li><a href="#">Something else here</a></li>
  581. // <li role="separator" class="divider"></li>
  582. // <li><a href="#">Separated link</a></li>
  583. // </ul>
  584. // </li>
  585. // </ul>
  586. ])
  587. ])
  588. ]);
  589. }
  590. public function getStorageList() {
  591. $storageList = array();
  592. $sth = DB::getPDO()->prepare("
  593. select z.ID, z.`DESC`, z.`TYPE`
  594. from CRM_LISTA_ZASOBOW z
  595. where z.TYPE in('BAZA_DANYCH','DATABASE_MYSQL','DATABASE_POSTGRESQL')
  596. ");
  597. $sth->execute();
  598. $rows = $sth->fetchAll();
  599. foreach ($rows as $row) {
  600. $storageList[$row['ID']] = $row;
  601. }
  602. return $storageList;
  603. }
  604. public function addAclObjectToZasobyAction() {// sends JSON
  605. $response = new stdClass();
  606. try {
  607. $idStorage = V::get('idStorage', '', $_GET);
  608. $namespace = V::get('namespace', '', $_GET);
  609. if (empty($idStorage)) throw new HttpException("Missing idStorage param");
  610. if (empty($namespace)) throw new HttpException("Missing namespace param");
  611. $objectStorage = SchemaFactory::loadDefaultObject('SystemObject');
  612. $items = $objectStorage->getItems([
  613. 'f_namespace' => "={$namespace}",
  614. ]);
  615. if (empty($items)) throw new Exception("SystemObject '{$namespace}' not found");
  616. $objectItem = reset($items);
  617. if (empty($objectItem)) throw new Exception("SystemObject '{$namespace}' not found");
  618. DBG::log($objectItem, 'array', 'object acl $objectItem');
  619. if ($objectItem['idZasob'] > 0) {
  620. // TODO: check if realy exists? @see SchemaFactory::loadDefaultObject('SystemObject')::updateCache()
  621. $response->_replaceButtonNode = "[{$objectItem['idZasob']}]";
  622. throw new AlertInfoException("Zasob '{$objectItem['namespace']}' już istnieje - nr '{$objectItem['idZasob']}'");
  623. }
  624. $idZasobFound = 0;
  625. switch ($objectItem['_type']) {
  626. case 'TableAcl': $idZasobFound = DB::getPDO()->fetchValue(" select ID from CRM_LISTA_ZASOBOW where PARENT_ID = {$objectItem['idDatabase']} and `DESC` = '{$objectItem['name']}' "); break;
  627. case 'AntAcl': $idZasobFound = DB::getPDO()->fetchValue(" select ID from CRM_LISTA_ZASOBOW where PARENT_ID = {$objectItem['idDatabase']} and `DESC` = '{$objectItem['namespace']}' "); break;
  628. default: throw new Exception("Not implemented acl type '{$objectItem['_type']}'");
  629. }
  630. if ($idZasobFound > 0) {
  631. DB::getPDO()->update($objectStorage->_rootTableName, 'namespace', $objectItem['namespace'], [
  632. 'idZasob' => $idZasobFound
  633. ]);
  634. $response->id = $idZasobFound;
  635. throw new AlertSuccessException("Zasob '{$objectItem['namespace']}' już istnieje - nr '{$idZasobFound}' - cache zaktualizowany");
  636. }
  637. try {
  638. $acl = User::getAcl()->getObjectAcl('default_db', 'crm_lista_zasobow');
  639. } catch (Exception $e) {
  640. DBG::log($e);
  641. throw new Exception("Brak dostępu do tabeli Zasoby");
  642. }
  643. if (empty($objectItem['idDatabase'])) throw new Exception("Missing database id");
  644. if ($idStorage != $objectItem['idDatabase']) throw new Exception("Database id must be the same");
  645. if (empty($objectItem['_rootTableName'])) throw new Exception("Missing root table name");
  646. switch ($objectItem['_type']) {
  647. case 'TableAcl':
  648. $newZasobItem = [
  649. 'PARENT_ID' => $objectItem['idDatabase'],
  650. 'TYPE' => 'TABELA',
  651. 'DESC' => $objectItem['_rootTableName'],
  652. 'DESC_PL' => $objectItem['name'],
  653. ];
  654. break;
  655. case 'AntAcl':
  656. $newZasobItem = [
  657. 'PARENT_ID' => $objectItem['idDatabase'],
  658. 'TYPE' => 'TABELA',
  659. 'DESC' => $objectItem['namespace'],
  660. 'DESC_PL' => $objectItem['name'],
  661. ];
  662. break;
  663. default: throw new Exception("Not implemented acl type '{$objectItem['_type']}'");
  664. }
  665. $idCreated = $acl->addItem($newZasobItem);
  666. if (!$idCreated) throw new Exception("Nie udało się utworzyć nowego rekordu!");
  667. try {
  668. DB::getPDO()->update($objectStorage->_rootTableName, 'namespace', $objectItem['namespace'], [
  669. 'idZasob' => $idCreated
  670. ]);
  671. } catch (Exception $e) {
  672. DBG::log($e);
  673. }
  674. $response->id = $idCreated;
  675. $response->record = $acl->getItem($idCreated);
  676. $response->_replaceButtonNode = "[{$idCreated}]";
  677. throw new AlertSuccessException("Utworzono pomyślnie rekord nr {$idCreated}");
  678. } catch (AlertSuccessException $e) {
  679. $response->type = 'success';
  680. $response->msg = $e->getMessage();
  681. } catch (AlertInfoException $e) {
  682. $response->type = 'info';
  683. $response->msg = $e->getMessage();
  684. } catch (Exception $e) {
  685. $response->type = 'error';
  686. $response->msg = $e->getMessage();
  687. DBG::log($e);
  688. }
  689. Response::sendJsonExit($response);
  690. }
  691. public function addAclObjectToZasobyAjaxAction() {
  692. DBG::log($_REQUEST, 'array', '$_REQUEST');
  693. Response::sendTryCatchJson(array($this, 'addAclObjectToZasobyAjax'), $_REQUEST);
  694. }
  695. public function addAclObjectToZasobyAjax($args) {
  696. $namespace = V::get('namespace', '', $args);
  697. if (empty($namespace)) throw new HttpException("Missing namespace");
  698. $idStorage = V::get('idStorage', '', $args);
  699. if (empty($idStorage)) throw new HttpException("Missing idStorage");
  700. $objectStorage = SchemaFactory::loadDefaultObject('SystemObject');
  701. $items = $objectStorage->getItems([
  702. 'f_namespace' => "={$namespace}",
  703. ]);
  704. if (empty($items)) throw new Exception("SystemObject '{$namespace}' not found");
  705. $objectItem = reset($items);
  706. if (empty($objectItem)) throw new Exception("SystemObject '{$namespace}' not found");
  707. DBG::log($objectItem, 'array', 'object acl $objectItem');
  708. try {
  709. $acl = User::getAcl()->getObjectAcl('default_db', 'crm_lista_zasobow');
  710. } catch (Exception $e) {
  711. DBG::log($e);
  712. throw new Exception("Brak dostępu do tabeli Zasoby");
  713. }
  714. if ($objectItem['idZasob'] > 0) {
  715. // TODO: check if realy exists? @see SchemaFactory::loadDefaultObject('SystemObject')::updateCache()
  716. return [
  717. 'type' => 'info',
  718. 'msg' => "Zasob '{$objectItem['namespace']}' już istnieje - nr '{$objectItem['idZasob']}'",
  719. 'body' => [
  720. 'id' => $objectItem['idZasob'],
  721. 'record' => $acl->getItem($objectItem['idZasob']),
  722. '_replaceButtonNode' => "[{$objectItem['idZasob']}]",
  723. ]
  724. ];
  725. }
  726. $idZasobFound = 0;
  727. if ('StorageAcl' === $objectItem['_type']) {
  728. if (!$objectItem['idDatabase']) throw new Exception("Brak idDatabase dla '{$objectItem['namespace']}'");
  729. }
  730. switch ($objectItem['_type']) {
  731. case 'TableAcl': $idZasobFound = DB::getPDO()->fetchValue(" select ID from CRM_LISTA_ZASOBOW where PARENT_ID = {$objectItem['idDatabase']} and `DESC` = '{$objectItem['name']}' "); break;
  732. case 'AntAcl': $idZasobFound = DB::getPDO()->fetchValue(" select ID from CRM_LISTA_ZASOBOW where PARENT_ID = {$objectItem['idDatabase']} and `DESC` = '{$objectItem['namespace']}' "); break;
  733. case 'StorageAcl': $idZasobFound = DB::getPDO()->fetchValue(" select ID from CRM_LISTA_ZASOBOW where PARENT_ID = {$objectItem['idDatabase']} and `DESC` = '{$objectItem['namespace']}' "); break;
  734. default: throw new Exception("Not implemented acl type '{$objectItem['_type']}'");
  735. }
  736. if ($idZasobFound > 0) {
  737. DB::getPDO()->update($objectStorage->_rootTableName, 'namespace', $objectItem['namespace'], [
  738. 'idZasob' => $idZasobFound
  739. ]);
  740. return [
  741. 'type' => 'info',
  742. 'msg' => "Zasob '{$objectItem['namespace']}' już istnieje - nr '{$idZasobFound}' - cache zaktualizowany",
  743. 'body' => [
  744. 'id' => $idZasobFound,
  745. 'record' => $acl->getItem($idZasobFound),
  746. '_replaceButtonNode' => "[{$idZasobFound}]",
  747. ]
  748. ];
  749. }
  750. if (empty($objectItem['idDatabase'])) throw new Exception("Missing database id");
  751. if ($idStorage != $objectItem['idDatabase']) throw new Exception("Database id must be the same");
  752. if (empty($objectItem['_rootTableName'])) throw new Exception("Missing root table name");
  753. switch ($objectItem['_type']) {
  754. case 'TableAcl':
  755. $newZasobItem = [
  756. 'PARENT_ID' => $objectItem['idDatabase'],
  757. 'TYPE' => 'TABELA',
  758. 'DESC' => $objectItem['_rootTableName'],
  759. 'DESC_PL' => $objectItem['name'],
  760. ];
  761. break;
  762. case 'AntAcl':
  763. $newZasobItem = [
  764. 'PARENT_ID' => $objectItem['idDatabase'],
  765. 'TYPE' => 'TABELA',
  766. 'DESC' => $objectItem['namespace'],
  767. 'DESC_PL' => $objectItem['name'],
  768. ];
  769. break;
  770. case 'StorageAcl':
  771. $newZasobItem = [
  772. 'PARENT_ID' => $objectItem['idDatabase'],
  773. 'TYPE' => 'TABELA',
  774. 'DESC' => $objectItem['namespace'],
  775. 'DESC_PL' => $objectItem['name'],
  776. ];
  777. break;
  778. default: throw new Exception("Not implemented acl type '{$objectItem['_type']}'");
  779. }
  780. $idCreated = $acl->addItem($newZasobItem);
  781. if (!$idCreated) throw new Exception("Nie udało się utworzyć nowego rekordu!");
  782. try {
  783. DB::getPDO()->update($objectStorage->_rootTableName, 'namespace', $objectItem['namespace'], [
  784. 'idZasob' => $idCreated
  785. ]);
  786. } catch (Exception $e) {
  787. DBG::log($e);
  788. }
  789. return [
  790. 'type' => 'success',
  791. 'msg' => "Utworzono pomyślnie rekord nr {$idCreated}",
  792. 'body' => [
  793. 'id' => $idCreated,
  794. 'record' => $acl->getItem($idCreated),
  795. '_replaceButtonNode' => "[{$idCreated}]",
  796. ]
  797. ];
  798. }
  799. public function addCellToZasobyAction() {// sends JSON
  800. $response = new stdClass();
  801. try {
  802. $idStorage = V::get('storageId', '', $_GET);
  803. $tblName = V::get('tblName', '', $_GET, 'word');
  804. $cellName = V::get('cellName', '', $_GET, 'word');
  805. if (empty($tblName)) throw new HttpException("Wrong table name");
  806. if (empty($tblName)) throw new HttpException("Wrong cell name");
  807. $storage = DB::getStorage($idStorage);
  808. $tableStruct = $storage->getTableStruct($tblName);
  809. $zasobStorageId = $storage->getZasobId();
  810. if (!is_numeric($zasobStorageId)) throw new HttpException("Storage id is not set in config file");
  811. $idTable = $this->fetchTableId($zasobStorageId, $tblName);
  812. if ($idTable <= 0) throw new Exception("Zasob tabela '{$tblName}' nie istnieje");
  813. try {
  814. $acl = User::getAcl()->getObjectAcl('default_db', 'crm_lista_zasobow');
  815. } catch (Exception $e) {
  816. throw new Exception("Brak dostępu do tabeli Zasoby");
  817. }
  818. $item = array();
  819. $item['PARENT_ID'] = $idTable;
  820. $item['TYPE'] = 'KOMORKA';
  821. $item['DESC'] = $cellName;
  822. $item['DESC_PL'] = $cellName;
  823. if (DBG::isActive()) $response->_itemToCreate = $item;
  824. $createdId = $acl->addItem($item);
  825. if (!$createdId) throw new Exception("Nie udało się utworzyć nowego rekordu!");
  826. $response->id = $createdId;
  827. $response->record = $acl->getItem($createdId);
  828. $response->_replaceButtonNode = "[{$createdId}]";
  829. throw new AlertSuccessException("Utworzono pomyślnie rekord nr {$createdId}");
  830. } catch (AlertSuccessException $e) {
  831. DBG::log($e);
  832. $response->type = 'success';
  833. $response->msg = $e->getMessage();
  834. } catch (AlertInfoException $e) {
  835. DBG::log($e);
  836. $response->type = 'info';
  837. $response->msg = $e->getMessage();
  838. } catch (Exception $e) {
  839. DBG::log($e);
  840. $response->type = 'error';
  841. $response->msg = $e->getMessage();
  842. }
  843. Response::sendJsonExit($response);
  844. }
  845. public function fetchTableId($idZasobStorage, $tblName) {
  846. $rows = DB::getPDO()->fetchAll("
  847. select z.`ID`, z.`DESC`
  848. from `CRM_LISTA_ZASOBOW` z
  849. where z.`PARENT_ID`='{$idZasobStorage}'
  850. and z.`DESC`='{$tblName}'
  851. and z.`A_STATUS` in('NORMAL','WAITING')
  852. ");
  853. if (!empty($rows)) return (int)$rows[0]['ID'];
  854. return null;
  855. }
  856. public function systemObjectsStructAction() {
  857. UI::gora();
  858. UI::menu();
  859. $this->navView();
  860. try {
  861. throw new Exception("TODO: F." . __FUNCTION__ . ' L.' . __LINE__);
  862. // $coreObjlist = OBJXSD::getSystemObjectsStruct();
  863. // $objectList = array();
  864. // foreach ($coreObjlist as $objName) {
  865. // $objItem = array();
  866. // $objItem['name'] = $objName;
  867. // $objItem['struktura'] = '<a href="index.php?_route=Storage&_task=systemObjectsStruct&object=' . $objName . '">' . "struct" . '</a>';
  868. // // $objItem['label'] = "";// TODO: read from json
  869. // $objectList[] = $objItem;
  870. // }
  871. // usort($objectList, function($rowA, $rowB) {
  872. // $a = $rowA['nazwa']; $b = $rowB['nazwa'];
  873. // if ($a == $b) return 0;
  874. // return ($a < $b) ? -1 : 1;
  875. // });
  876. //
  877. // DBG::table("objectList", $objectList, __CLASS__, __FUNCTION__, __LINE__);
  878. } catch (Exception $e) {
  879. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  880. }
  881. UI::dol();
  882. }
  883. public function systemObjectsAction() {// TableAjax view: index.php?_route=ViewTableAjax&namespace=default_objects/SystemObject
  884. UI::gora();
  885. UI::menu();
  886. $this->navView();
  887. try {
  888. Lib::loadClass('Schema_SystemObjectStorageAcl');
  889. $acl = new Schema_SystemObjectStorageAcl();
  890. UI::table([
  891. 'rows' => array_map(
  892. function ($item) {
  893. return [
  894. 'ns' => $item['namespace'],
  895. 'nazwa' => $item['name'],
  896. 'type' => $item['_type'],
  897. 'edit' => '<a href="index.php?_route=ViewTableAjax&namespace=' . $item['namespace'] . '">edit</a>',
  898. '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>',
  899. '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)'
  900. ];
  901. }
  902. , $acl->getItems([
  903. 'order_by' => 'namespace',
  904. 'order_dir' => 'asc'
  905. ])
  906. )
  907. ]);
  908. } catch (Exception $e) {
  909. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  910. DBG::log($e);
  911. }
  912. UI::dol();
  913. }
  914. public function activateObjectAjaxAction() {
  915. DBG::log($_REQUEST, 'array', '$_REQUEST');
  916. Response::sendTryCatchJson(array($this, 'activateObjectAjax'), $_REQUEST);
  917. }
  918. public function activateObjectAjax($args) {
  919. $namespace = V::get('namespace', '', $args);
  920. if (empty($namespace)) throw new Exception("Missing param namespace");
  921. $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
  922. if (empty($item)) throw new HttpException("Namespace not found", 404);
  923. DBG::log($item, 'array', "activateObjectAjax \$item");
  924. if ($item['isObjectActive']) throw new AlertSuccessException("Namespace '{$namespace}' already active");
  925. if (!$item['hasStruct']) throw new Exception("Missing struct for namespace '{$namespace}'");
  926. if (!$item['isStructInstalled']) throw new Exception("Namespace struct not installed '{$namespace}'");
  927. $activeFields = array_filter($item['field'], function ($field) {
  928. if (!$field['isActive']) return false;
  929. if (!$field['idZasob']) return false;
  930. return true;
  931. });
  932. if (empty($activeFields)) throw new Exception("Missing active fields for namespace '{$namespace}'");
  933. $affected = SchemaFactory::loadDefaultObject('SystemObject')->updateItem([
  934. 'namespace' => $item['namespace'],
  935. 'isObjectActive' => 1
  936. ]);
  937. if ($affected < 0) throw new Exception("Nie udało się aktywować obiektu '{$namespace}'");
  938. return [
  939. 'type' => "success",
  940. 'msg' => "Aktywowano obiekt '{$namespace}'",
  941. 'body' => [
  942. 'isObjectActive' => 1
  943. ]
  944. ];
  945. }
  946. }