ViewTableAjax.php 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('ProcesHelper');
  4. Lib::loadClass('TableAjax');
  5. // Lib::loadClass('Request');
  6. Lib::loadClass('Response');
  7. Lib::loadClass('UI');
  8. Lib::loadClass('Api_WfsNs');
  9. Lib::loadClass('Core_AclHelper');
  10. Lib::loadClass('Route_UrlAction');
  11. Lib::loadClass('Router');
  12. Lib::loadClass('Typespecial');
  13. Lib::loadClass('UserProfile');
  14. class Route_ViewTableAjax extends RouteBase {
  15. public function getTableAjaxWidget($acl, $backRefFilter = [], $childRefFilter = []) {
  16. $syncUrl = $this->getLink('', [ 'namespace' => $acl->getNamespace() ]);
  17. $tbl = new TableAjax($acl);
  18. $tbl->setRootUrl($syncUrl);
  19. if (!empty($backRefFilter['namespace']) && !empty($backRefFilter['primaryKey'])) {
  20. $tbl->setBackRefFilter($backRefFilter);
  21. $syncUrl = $this->getLink('', [
  22. 'namespace' => $acl->getNamespace(),
  23. 'backRefNS' => $backRefFilter['namespace'],
  24. 'backRefPK' => $backRefFilter['primaryKey'],
  25. 'backRefField' => $backRefFilter['fieldName'],
  26. ]);
  27. }
  28. if (!empty($childRefFilter['namespace']) && !empty($childRefFilter['primaryKey'])) {
  29. $tbl->setChildRefFilter($childRefFilter);
  30. $syncUrl = $this->getLink('', [
  31. 'namespace' => $acl->getNamespace(),
  32. 'childRefNS' => $childRefFilter['namespace'],
  33. 'childRefPK' => $childRefFilter['primaryKey'],
  34. ]);
  35. }
  36. $tblLabel = $acl->getNamespace();
  37. if ('default_db' == $acl->getSourceName()) {
  38. $tblLabel = array();
  39. $zasobObj = ProcesHelper::getZasobTableInfo($acl->getID());
  40. if (!$zasobObj) throw new Exception("Zasob TABELA ID=" . $acl->getID() . " nie istnieje");
  41. if (!empty($zasobObj->DESC_PL)) $tblLabel[] = $zasobObj->DESC_PL;
  42. if (!empty($zasobObj->OPIS)) $tblLabel[] = $zasobObj->OPIS;
  43. $tblLabel = implode(" - ", $tblLabel);
  44. }
  45. $tbl->setSyncUrl($syncUrl);
  46. $tbl->showProcesInitFiltr = $this->getLink("procesInitFiltrAjax", [ 'namespace' => $acl->getNamespace() ]);
  47. $tbl->showTableTools = $this->getLink("tableToolsAjax", [ 'namespace' => $acl->getNamespace() ]);
  48. $tbl->useUserTableFilter = $this->getLink("getUserTableFilterAjax");
  49. $tbl->setLabel($tblLabel);
  50. if (method_exists($acl, 'getGuiRowFunctions')) {
  51. foreach ($acl->getGuiRowFunctions() as $funKey => $funParams) {
  52. $tbl->addRowFunction($funKey, $funParams);
  53. }
  54. } else {
  55. $tbl->addRowFunction('edit');
  56. $tbl->addRowFunction('hist');
  57. $tbl->addRowFunction('files');
  58. $tbl->addRowFunction('cp');
  59. $tbl->addRowFunction('msgs');
  60. }
  61. return $tbl;
  62. }
  63. public function defaultAction() {
  64. UI::gora();
  65. UI::menu();
  66. try {
  67. $namespace = V::get('namespace', '', $_GET, 'word');
  68. if (!$namespace) {
  69. $typeName = V::get('typeName', '', $_GET, 'word');
  70. if (!$typeName) throw new Exception("Wrong param typeName");
  71. $namespace = Api_WfsNs::getBaseWfsUri() . '/' . str_replace(':', '/', $typeName);
  72. }
  73. $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
  74. $forceFilterInit = array();
  75. $filterInit = new stdClass();
  76. $filterInit->currSortCol = $acl->getPrimaryKeyField();
  77. $filterInit->currSortFlip = 'desc';
  78. foreach ($_REQUEST as $k => $v) {
  79. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && !empty($v)) {// filter prefix
  80. $filterInit->$k = $v;
  81. }
  82. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && !empty($v)) {// special filter prefix
  83. $filterInit->$k = $v;
  84. }
  85. else if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
  86. $fldName = substr($k, 3);
  87. $forceFilterInit[$fldName] = $v;
  88. }
  89. }
  90. $backRefFilter = [
  91. 'namespace' => V::get('backRefNS', '', $_GET),
  92. 'primaryKey' => V::get('backRefPK', '', $_GET),
  93. 'fieldName' => V::get('backRefField', '', $_GET),
  94. ];
  95. $childRefFilter = [
  96. 'namespace' => V::get('childRefNS', '', $_GET),
  97. 'primaryKey' => V::get('childRefPK', '', $_GET),
  98. ];
  99. $tbl = $this->getTableAjaxWidget($acl, $backRefFilter, $childRefFilter);
  100. $tbl->setFilterInit($filterInit);
  101. if (!empty($forceFilterInit)) $tbl->setForceFilterInit($forceFilterInit);
  102. if (V::get('DBG_INST', '', $_GET)) { // TODO: TEST namespace
  103. $siblings = ACL::getNamespaceSiblings($namespace);
  104. DBG::nicePrint($siblings, '$siblings');
  105. $filtrInstance = V::get('f_instance', [], $_POST, 'array');
  106. DBG::nicePrint($filtrInstance, '$filtrInstance');
  107. $sibling = 'default_db/CRM_PROCES/PROCES_INIT'; DBG::nicePrint(array_merge(['type'=>"radio", 'name'=>"f_instance[{$sibling}]", 'value'=>'YES'], ('YES' === V::get($sibling, '', $filtrInstance)) ? ['checked' => "checked"] : []), "merge {$sibling} YES");
  108. $sibling = 'default_db/CRM_PROCES/PROCES_INIT'; DBG::nicePrint(array_merge(['type'=>"radio", 'name'=>"f_instance[{$sibling}]", 'value'=>'NO'], ('NO' === V::get($sibling, '', $filtrInstance)) ? ['checked' => "checked"] : []), "merge {$sibling} NO");
  109. $_ = array(UI, 'h');
  110. echo $_('form', ['method' => "POST", 'style' => "width:600px; border:1px solid #ddd; border-radius:2px"], [
  111. $_('div', ['style' => "background-color:#ddd"], "Test Filtr instancji"),
  112. $_('div', ['style' => "padding:8px"], array_map(function ($sibling) use ($filtrInstance, $_) {
  113. return $_('div', [], [
  114. $_('label', ['style' => "margin:0 8px"], [
  115. $_('input', array_merge(['type'=>"radio", 'name'=>"f_instance[{$sibling}]", 'value'=>'YES'], ('YES' === V::get($sibling, '', $filtrInstance)) ? ['checked' => "checked"] : [])),
  116. " TAK "
  117. ]),
  118. $_('label', ['style' => "margin:0 8px"], [
  119. $_('input', array_merge(['type'=>"radio", 'name'=>"f_instance[{$sibling}]", 'value'=>'NO'], ('NO' === V::get($sibling, '', $filtrInstance)) ? ['checked' => "checked"] : [])),
  120. " NIE "
  121. ]),
  122. $_('label', ['style' => "margin:0 8px"], [
  123. $_('input', ['type'=>"radio", 'name'=>"f_instance[{$sibling}]", 'value'=>'x']),
  124. " pomiń "
  125. ]),
  126. // $_('button', ['onClick'=>"this.form.f_instance['{$sibling}'].value = ''; return false"], "odznacz"),
  127. $_('button', ['onClick'=>"console.log(this.form.elements['f_instance[{$sibling}]']); this.form.elements['f_instance[{$sibling}]'].value = 'x'; return false"], "odznacz"),
  128. " - {$sibling}"
  129. ]);
  130. }, $siblings)),
  131. $_('div', [], [
  132. $_('input', ['type'=>"hidden", 'name'=>'_route', 'value'=>"ViewObject"]),
  133. $_('input', ['type'=>"hidden", 'name'=>'namespace', 'value'=>$namespace]),
  134. $_('input', ['type'=>"submit", 'value'=>"Filtruj - TEST"]),
  135. ]),
  136. ]);
  137. DBG::nicePrint($_POST, '$_POST');
  138. {
  139. $args = $_POST;
  140. $fIsInstance = [];
  141. $fIsNotInstance = [];
  142. if (!empty($args['f_instance'])) {
  143. foreach ($args['f_instance'] as $inst => $selected) {
  144. if ('YES' === $selected) {
  145. $fIsInstance[] = $inst;
  146. } else if ('NO' === $selected) {
  147. $fIsNotInstance[] = $inst;
  148. }
  149. }
  150. }
  151. }
  152. $queryFeatures = $acl->buildQuery([
  153. // TODO: 'propertyName' => "*,@instance",
  154. 'f_is_instance' => $fIsInstance,
  155. 'f_is_not_instance' => $fIsNotInstance,
  156. '@instances' => '1',
  157. 'limit' => 10
  158. ]);
  159. // $total = $queryFeatures->getTotal();
  160. $items = $queryFeatures->getItems();
  161. $rootNamespace = $acl->getRootNamespace();
  162. DBG::nicePrint($rootNamespace, '$rootNamespace');
  163. $jsRenderFunName = 'render_dropdown_instances_' . substr(md5(time()), 0, 6);
  164. DBG::nicePrint($jsRenderFunName, '$jsRenderFunName');
  165. UI::table([
  166. 'rows' => array_map(function($row) use ($namespace, $siblings, $rootNamespace, $jsRenderFunName) {
  167. return [
  168. 'ID' => $row['ID'],
  169. 'DESC' => $row['DESC'],
  170. 'TYPE' => $row['TYPE'],
  171. 'Typ' => UI::h('div', ['class'=>"p5UI__dropdown-wrap"], [
  172. UI::h('button', [
  173. // 'onClick' => "p5UI__dropdown(event, this, 'left bottom')",
  174. 'onClick' => "p5UI__dropdown(event, this, 'left bottom', {$jsRenderFunName}({$row['ID']}))",
  175. 'class' => "btn btn-xs btn-default p5UI__dropdown-btn"
  176. ], [
  177. UI::h('i', ['class' => "glyphicon glyphicon-tags", 'title' => "Ustaw typ danych (instancje)"]),
  178. ]),
  179. UI::h('div', ['class' => "p5UI__dropdown-content"]
  180. , array_merge(
  181. [
  182. UI::h('input', ['type' => "text", 'placeholder' => "Search..", 'class' => "p5UI__dropdown-input", 'onkeyup' => "p5_ViewObject_instances_filterInput(this)"], null),
  183. ]
  184. , array_map(function ($sibling) use ($row, $namespace, $rootNamespace) {
  185. return UI::h('div', ['label'=>$sibling, 'style'=>"padding:4px 0"], [
  186. UI::h('button', array_merge(['class' => "btn btn-xs btn-default",
  187. 'style' => "margin:0 4px 0 0",
  188. 'title' => "Ustaw instancje '{$sibling}'",
  189. 'onClick' => "return p5_ViewObject_instance_set(this, '{$row['ID']}', '{$sibling}', 'yes')"],
  190. (in_array($sibling, explode(',', $row['@instances']))) ? ['disabled' => "disabled"] : []
  191. ), "+"),
  192. UI::h('button', ['class' => "btn btn-xs btn-default",
  193. 'style' => "margin:0 4px 0 0",
  194. 'title' => "Usuń instancje '{$sibling}'",
  195. 'onClick' => "return p5_ViewObject_instance_set(this, '{$row['ID']}', '{$sibling}', 'no')"], "-"),
  196. UI::h('span', [], substr($sibling, strlen($rootNamespace) + 1)),
  197. ]);
  198. }, $siblings)
  199. )
  200. )
  201. ]),
  202. 'instancesList' => implode(', ', ACL::getFeatureNamespaces($namespace, $row['ID'])),
  203. ];
  204. }, $items)
  205. ]);
  206. echo UI::h('style', ['type' => "text/css"], "
  207. .p5UI__dropdown-content { min-width:400px; border:1px solid #ccc; background-color: #fff; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2) }
  208. .p5UI__dropdown-content .p5UI__dropdown-item { display:block; color:#000; padding:4px; text-decoration:none }
  209. .p5UI__dropdown-content .p5UI__dropdown-item:hover { background-color:#ebebeb }
  210. ");
  211. echo UI::h('script', ['src'=>"static/vendor.js", 'type'=>"text/javascript"]);
  212. $jsArgs = [
  213. 'SET_INSTANCE_URL' => $this->getLink('setInstanceAjax'),
  214. 'NAMESPACE' => $namespace,
  215. 'DBG' => DBG::isActive() ? 'true' : 'false',
  216. ];
  217. UI::inlineJS(__FILE__ . '.instancesDropdown.js', [
  218. 'JS_GLOBAL_FUNCTION_NAME' => $jsRenderFunName,
  219. 'NAMESPACE' => $namespace,
  220. 'SET_INSTANCE_URL' => $this->getLink('setInstanceAjax'),
  221. 'DBG' => DBG::isActive() ? 1 : 0,
  222. 'INITIAL_DROPDOWN_DATA' => [
  223. // 'allowed_instances' => $siblings,
  224. 'allowed_instances' => array_map(function ($sibling) use ($rootNamespace) {
  225. return [
  226. 'namespace' => $sibling,
  227. 'label' => substr($sibling, strlen($rootNamespace) + 1)
  228. ];
  229. }, $siblings),
  230. 'items' => array_map(function($row) use ($namespace, $siblings, $rootNamespace, $jsRenderFunName) {
  231. return [
  232. 'pk' => $row['ID'], // TODO: $primaryKeyField
  233. 'instances' => explode(',', $row['@instances']),
  234. ];
  235. }, $items)
  236. ],
  237. ]);
  238. echo UI::h('script', [], "
  239. var SET_INSTANCE_URL = '{$jsArgs['SET_INSTANCE_URL']}'
  240. var NAMESPACE = '{$jsArgs['NAMESPACE']}'
  241. function p5_ViewObject_instance_set(n, pk, sibling, toConnect) {
  242. console.log('p5_ViewObject_instance_set pk('+pk+'), sibling('+sibling+'), toConnect('+toConnect+'), n', n);
  243. window.fetch(SET_INSTANCE_URL, {
  244. method: 'POST',
  245. headers: { 'Content-Type': 'application/json' },
  246. credentials: 'same-origin',
  247. body: JSON.stringify({
  248. namespace: NAMESPACE,
  249. primaryKey: pk,
  250. instance: sibling,
  251. toConnect: toConnect,
  252. })
  253. }).then(function (response) {
  254. return response.json()
  255. }).then(function (response) {
  256. p5UI__notifyAjaxCallback(response)
  257. console.log(response) // TODO: render list
  258. })
  259. }
  260. ");
  261. echo UI::h('script', [], "
  262. function p5_ViewObject_instances_filterInput(n) {
  263. var input, filter, ul, li, a, i, div;
  264. input = n // .id-myInput
  265. filter = input.value.toUpperCase()
  266. div = n.parentNode // .id-myDropdown
  267. a = div.getElementsByTagName('div')
  268. for (i = 0; i < a.length; i++) {
  269. if (a[i].getAttribute('label') && a[i].getAttribute('label').toUpperCase().indexOf(filter) > -1) {
  270. a[i].style.display = 'block'
  271. } else {
  272. a[i].style.display = 'none'
  273. }
  274. }
  275. }
  276. ");
  277. echo '<hr style="margin-top:300px">';
  278. exit;
  279. }
  280. echo $tbl->render();
  281. if (DBG::isActive() && V::get('DBG_ACL', '', $_GET)) {// test load perms
  282. Lib::loadClass('DebugExecutionTime');
  283. $dbgExecTime = new DebugExecutionTime();
  284. $dbgExecTime->activate();
  285. $dbgExecTime->log('start');
  286. UI::startContainer(['style'=>'border:1px solid red']);
  287. UI::tag('p', null, "TEST - load perms from db");
  288. $idTable = $acl->getID();
  289. UI::tag('p', null, "DBG idTable({$idTable})");
  290. if ($idTable > 0) {
  291. $dbgExecTime->log('before sql');
  292. $aclTableRows = DB::getPDO()->fetchAll("select * from `CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW` where ID_TABLE = {$idTable}");
  293. $dbgExecTime->log('after sql', ['sql']);
  294. UI::table(['caption' => "from CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW", 'rows' => $aclTableRows]);
  295. $csvIdProces = array();
  296. foreach ($aclTableRows as $row) {
  297. if (!in_array($row['ID_PROCES'], $csvIdProces)) $csvIdProces[] = $row['ID_PROCES'];
  298. }
  299. }
  300. $tableName = $acl->getName();
  301. $databaseName = DB::getPDO()->getDatabaseName();
  302. UI::table([
  303. 'caption' => "Cell to process",
  304. 'rows' => array_map(
  305. function ($row) use ($aclTableRows, $idTable) {
  306. $row['proces'] = array();
  307. $row['id_zasob'] = 0;
  308. $row['PERM_R'] = 0;
  309. $row['PERM_W'] = 0;
  310. $row['PERM_X'] = 0;
  311. $row['PERM_C'] = 0;
  312. $row['PERM_S'] = 0;
  313. $row['PERM_O'] = 0;
  314. $row['PERM_V'] = 0;
  315. $row['PERM_E'] = 0;
  316. foreach ($aclTableRows as $aclInfo) {
  317. if (strtolower($aclInfo['CELL_NAME']) == strtolower($row['COLUMN_NAME'])) {
  318. $row['proces'][] = $aclInfo['ID_PROCES'];
  319. $row['id_zasob'] = $aclInfo['ID_CELL'];
  320. $row['PERM_R'] += $aclInfo['PERM_R'];
  321. $row['PERM_W'] += $aclInfo['PERM_W'];
  322. $row['PERM_X'] += $aclInfo['PERM_X'];
  323. $row['PERM_C'] += $aclInfo['PERM_C'];
  324. $row['PERM_S'] += $aclInfo['PERM_S'];
  325. $row['PERM_O'] += $aclInfo['PERM_O'];
  326. $row['PERM_V'] += $aclInfo['PERM_V'];
  327. $row['PERM_E'] += $aclInfo['PERM_E'];
  328. }
  329. }
  330. $row['proces'] = (empty($row['proces']))
  331. ? "<i style=\"color:red\">Brak</i>"
  332. : implode(", ", $row['proces']);
  333. if (!$row['id_zasob']) $row['id_zasob'] = DB::getPDO()->fetchValue("select ID from CRM_LISTA_ZASOBOW where `DESC` = '{$row['COLUMN_NAME']}' and PARENT_ID = {$idTable} limit 1");
  334. return $row;
  335. }, DB::getPDO()->fetchAll("
  336. select t.TABLE_NAME, t.COLUMN_NAME, t.DATA_TYPE, t.COLUMN_TYPE
  337. from `information_schema`.`COLUMNS` t
  338. where t.TABLE_SCHEMA = '{$databaseName}'
  339. and t.TABLE_NAME like '{$tableName}'
  340. ")
  341. )
  342. ]);
  343. if (!empty($csvIdProces)) {
  344. $csvIdProces = implode(",", $csvIdProces);
  345. UI::tag('p', null, "DBG csvIdProces({$csvIdProces})");
  346. $userLogin = User::getLogin();
  347. $dbgExecTime->log('before sql');
  348. $rows = DB::getPDO()->fetchAll("select ID_PROCES from `CRM_PROCES_idx_USER_to_PROCES_VIEW` where ADM_ACCOUNT = '{$userLogin}' and ID_PROCES in({$csvIdProces}) group by ID_PROCES");
  349. $dbgExecTime->log('after sql', ['sql']);
  350. UI::table(['caption' => "from CRM_PROCES_idx_USER_to_PROCES_VIEW", 'rows' => $rows]);
  351. $userIdProces = array(); foreach ($rows as $row) $userIdProces[] = $row['ID_PROCES'];
  352. $userTablePerms = array();
  353. foreach ($aclTableRows as $row) {
  354. if (!in_array($row['ID_PROCES'], $userIdProces)) continue;
  355. if (array_key_exists($row['CELL_NAME'], $userTablePerms)) {
  356. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_R' ] += $row['PERM_R'];
  357. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_W' ] += $row['PERM_W'];
  358. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_X' ] += $row['PERM_X'];
  359. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_C' ] += $row['PERM_C'];
  360. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_S' ] += $row['PERM_S'];
  361. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_O' ] += $row['PERM_O'];
  362. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_V' ] += $row['PERM_V'];
  363. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_E' ] += $row['PERM_E'];
  364. } else {
  365. $userTablePerms[ $row['CELL_NAME'] ] = $row;
  366. unset($userTablePerms[ $row['CELL_NAME'] ][ 'TABLE_DESCRIPTION' ]);
  367. unset($userTablePerms[ $row['CELL_NAME'] ][ 'ID_PROCES' ]);
  368. unset($userTablePerms[ $row['CELL_NAME'] ][ 'FORM_TREAT' ]);
  369. }
  370. }
  371. UI::table(['caption' => "\$userTablePerms", 'rows' => $userTablePerms]);
  372. } else UI::alert('warning', "brak \$csvIdProces");
  373. $dbgExecTime->printDebug();
  374. UI::endContainer();
  375. }
  376. } catch (Exception $e) {
  377. UI::startContainer();
  378. UI::alert('danger', "<strong>Wystąpiły błędy!</strong> " . $e->getMessage());
  379. UI::endContainer();
  380. DBG::log($e);
  381. }
  382. UI::dol();
  383. }
  384. public function setInstanceAjaxAction() {
  385. Response::sendTryCatchJson(array($this, 'setInstanceAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  386. }
  387. public function setInstanceAjax($args) {
  388. // namespace => default_db/CRM_PROCES/PROCES_INIT
  389. // primaryKey => 6
  390. // instance => default_db/CRM_PROCES/PROCES_TREE
  391. // toConnect => yes
  392. if (empty($args['namespace'])) throw new Exception("Missing namespace");
  393. if (empty($args['primaryKey'])) throw new Exception("Missing primaryKey");
  394. if (empty($args['instance'])) throw new Exception("Missing instance");
  395. if (empty($args['toConnect'])) throw new Exception("Missing toConnect");
  396. if (!in_array($args['toConnect'], ['yes', 'no'])) throw new Exception("Wrong param toConnect");
  397. $idInstance = ACL::getInstanceId($args['instance']);
  398. throw new Exception("TODO: check instance config"); // if 'view' then set instance is not allowed
  399. // $instanceTable = ACL::getInstanceTable($args['namespace']);
  400. // switch ($args['toConnect']) {
  401. // case 'yes': {
  402. // // TODO: _HIST info - waiting
  403. // $ret = DB::getPDO()->execSql("
  404. // insert into `{$instanceTable}` (`pk`, `idInstance`)
  405. // values ( :pk , :idInstance )
  406. // ", [
  407. // 'pk' => $args['primaryKey'],
  408. // 'idInstance' => $idInstance,
  409. // ]);
  410. // // TODO: _HIST info - mark as done
  411. // } break;
  412. // case 'no': {
  413. // // TODO: _HIST info - waiting
  414. // $ret = DB::getPDO()->execSql("
  415. // delete from `{$instanceTable}`
  416. // where `pk` = :pk
  417. // and `idInstance` = :idInstance
  418. // ", [
  419. // 'pk' => $args['primaryKey'],
  420. // 'idInstance' => $idInstance,
  421. // ]);
  422. // // TODO: _HIST info - mark as done
  423. // } break;
  424. // }
  425. // return [
  426. // 'type' => 'success',
  427. // 'msg' => "Wprowadzono zmiany ({$ret})",
  428. // // TODO: 'data' => all instances for pk
  429. // ];
  430. }
  431. public function rmUserTableFilterAjaxAction() {
  432. Response::sendTryCatchJson(array($this, 'rmUserTableFilterAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  433. }
  434. public function rmUserTableFilterAjax($args) {
  435. $namespace = V::get('namespace', '', $args);
  436. $filtrName = V::get('filtrName', '', $args);
  437. if (!$namespace) throw new Exception("Missing namespace");
  438. if (!$filtrName) throw new Exception("Missing filtrName");
  439. $userFltrConfKey = "tableColFilters__" . User::getLogin();
  440. $currentFilters = DB::getPDO()->fetchValue(" select CONF_VAL from CRM_CONFIG where CONF_KEY = '{$userFltrConfKey}' ");
  441. if (!$currentFilters) return [
  442. 'type' => 'warning',
  443. 'msg' => "Brak filtrów w bazie",
  444. ];
  445. $currentFilters = json_decode($currentFilters, 'assoc');
  446. unset($currentFilters[$namespace][$filtrName]);
  447. $affeced = DB::getPDO()->update('CRM_CONFIG', 'CONF_KEY', $userFltrConfKey, [
  448. 'CONF_VAL' => json_encode($currentFilters)
  449. ]);
  450. return [
  451. 'type' => 'success',
  452. 'msg' => 'Zapisano nowy filtr',
  453. 'data' => $currentFilters[$namespace]
  454. ];
  455. }
  456. public function addUserTableFilterAjaxAction() {
  457. Response::sendTryCatchJson(array($this, 'addUserTableFilterAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  458. }
  459. public function addUserTableFilterAjax($args) {
  460. $namespace = V::get('namespace', '', $args);
  461. $filtrName = V::get('filtrName', '', $args);
  462. $visibleCols = V::get('visibleCols', '', $args);
  463. if (!$namespace) throw new Exception("Missing namespace");
  464. if (!$filtrName) throw new Exception("Missing filtrName");
  465. if (!$visibleCols) throw new Exception("Missing visibleCols");
  466. $userFltrConfKey = "tableColFilters__" . User::getLogin();
  467. $currentFilters = DB::getPDO()->fetchValue(" select CONF_VAL from CRM_CONFIG where CONF_KEY = '{$userFltrConfKey}' ");
  468. $currentFilters = ($currentFilters) ? json_decode($currentFilters, 'assoc') : [];
  469. $currentFilters[$namespace][$filtrName] = $visibleCols;
  470. $sqlFltr = json_encode($currentFilters);
  471. DB::getPDO()->execSql("
  472. insert into CRM_CONFIG (CONF_KEY, CONF_VAL)
  473. values ('$userFltrConfKey', '{$sqlFltr}')
  474. on duplicate key update CONF_VAL = '{$sqlFltr}'
  475. ");
  476. return [
  477. 'type' => 'success',
  478. 'msg' => 'Zapisano nowy filtr',
  479. 'data' => $currentFilters[$namespace]
  480. ];
  481. }
  482. public function getUserTableFilterAjaxAction() {
  483. Response::sendTryCatchJson(array($this, 'getUserTableFilterAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  484. }
  485. public function getUserTableFilterAjax($args) {
  486. $namespace = V::get('namespace', '', $args);
  487. if (!$namespace) throw new Exception("Missing namespace");
  488. $userFltrConfKey = "tableColFilters__" . User::getLogin();
  489. $currentFilters = DB::getPDO()->fetchValue(" select CONF_VAL from CRM_CONFIG where CONF_KEY = '{$userFltrConfKey}' ");
  490. $currentFilters = ($currentFilters) ? json_decode($currentFilters, 'assoc') : [];
  491. return [
  492. 'type' => 'success',
  493. 'msg' => 'Odczytano filtry użytkownika',
  494. 'data' => (!empty($currentFilters[$namespace])) ? $currentFilters[$namespace] : []
  495. ];
  496. }
  497. public function revertFromHistAjaxAction() {
  498. Response::sendTryCatchJson(array($this, 'revertFromHistAjax'));
  499. }
  500. public function revertFromHistAjax() {
  501. $typeName = V::get('typeName', '', $_REQUEST, 'word');
  502. if (!$typeName) throw new Exception("Wrong param typeName");
  503. // TODO: use namespace from url
  504. // $namespace = V::get('namespace', '', $_GET, 'word');
  505. // if (!$namespace) {
  506. // $typeName = V::get('typeName', '', $_GET, 'word');
  507. // if (!$typeName) throw new Exception("Wrong param typeName");
  508. // $namespace = Api_WfsNs::getBaseWfsUri() . '/' . str_replace(':', '/', $typeName);
  509. // }
  510. // $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
  511. $id = V::get('ID', '', $_REQUEST, 'word');
  512. if (!$id) throw new Exception("Wrong param ID");
  513. $idHist = V::get('idHist', '', $_REQUEST, 'word');
  514. if (!$idHist) throw new Exception("Wrong param idHist");
  515. $fieldName = V::get('fieldName', '', $_REQUEST, 'word');
  516. if (!$fieldName) throw new Exception("Wrong param fieldName");
  517. $acl = Core_AclHelper::getAclByTypeName($typeName);
  518. $item = $acl->getItem($id);
  519. if (!$item) throw new HttpException("Item not found", 404);
  520. if (!$acl->canWriteObjectField($fieldName, $record)) throw new Exception("Missing perm Write for field {$fieldName}");
  521. $histItem = $acl->getHistItem($id, $idHist);
  522. if (!$histItem) throw new HttpException("Hist Item not found", 404);
  523. $histValue = V::get($fieldName, 'N/S;', $histItem);
  524. if ('N/S;' == $histValue) throw new Exception("Missing field value in hist[{$idHist}] for field({$fieldName}) from item[{$id}]");
  525. if ($acl->isGeomField($fieldName)) {
  526. $wktType = strtoupper($acl->getGeomFieldType($fieldName));
  527. if (!$wktType) throw new Exception("Wrong geometry type for field {$fieldName}");
  528. if ($wktType != strtoupper(substr($histValue, 0, strlen($wktType)))) throw new Exception("Wrong geometry type for field {$fieldName} in hist value");
  529. $coords = trim(substr($histValue, strlen($wktType)), '()');
  530. $wktValue = $acl->convertGmlCoordsToWkt($wktType, $coords, ['cs'=>' ', 'ts'=>',']);
  531. if (!$wktValue) throw new Exception("BUG in hist record");
  532. $sqlObj = array();
  533. $sqlObj['ID'] = $id;
  534. $sqlObj[$fieldName] = "GeomFromText('{$wktValue}')";
  535. $affected = DB::getDB()->UPDATE_OBJ($acl->getName(), (object)$sqlObj);
  536. if (0 == $affected) throw new AlertInfoException("Nie wprowadzono żadnych zmian");
  537. else if ($affected < 0) throw new Exception("Wystąpiły błędy podczas aktualizacji rekordu [{$id}]");
  538. $jsonResponse = array();
  539. $jsonResponse['type'] = 'success';
  540. $jsonResponse['msg'] = "Zaktualizowano dane na podstawie wcześniejszej wartości dla rekordu [{$id}]";
  541. $jsonResponse['actions'] = array();
  542. $jsonResponse['actions'][] = ['jsFunction'=>'TableAjax__HIST_Route', 'args'=>[$id]];
  543. return $jsonResponse;
  544. } else {
  545. throw new HttpException("Not implemented - update from hist only for the geom field", 501);
  546. }
  547. throw new Exception("BUG: update field '{$fieldName}' in item[{$id}] from hist[{$idHist}]", 501);
  548. }
  549. public function removeTheGeomAjaxAction() {
  550. Response::sendTryCatchJson(array($this, 'removeTheGeomAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  551. }
  552. public function removeTheGeomAjax($args) {
  553. $namespace = V::get('namespace', '', $args, 'word');
  554. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  555. $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
  556. $primaryKeyField = $acl->getPrimaryKeyField();
  557. $primaryKey = V::get($primaryKeyField, 0, $args, 'int');
  558. $geomFieldName = 'the_geom';
  559. $response = new stdClass();
  560. if ($primaryKey <= 0) throw new HttpException("Bad Request - Wrong param ID", 400);
  561. $record = $acl->getItem($primaryKey);
  562. if (!$record) throw new HttpException("Nie odnaleziono rekordu nr {$primaryKey}", 404);
  563. if (!$acl->canWriteObjectField($geomFieldName, $record)) throw new HttpException("Brak dostępu do zapisu dla pola {$geomFieldName}", 403);
  564. if (empty($record->{$geomFieldName})) {
  565. $response->type = 'info';
  566. $response->msg = "Rekord nie jest powiązany z żadnym obiektem na mapie";
  567. $response->record = $record;
  568. return $response;
  569. }
  570. $itemPatch = array();
  571. $itemPatch[$geomFieldName] = "NULL";
  572. $itemPatch[$primaryKeyField] = $primaryKey;
  573. $response = new stdClass();
  574. try {
  575. $affected = $acl->updateItem($itemPatch);
  576. if ($affected > 0) {
  577. $response->type = 'success';
  578. $response->msg = "Usunięto obiekt z mapy dla rekordu {$primaryKey}";// Rekord zapisany pomyślnie
  579. } else if ($affected == 0) {
  580. $response->type = 'info';
  581. $response->msg = "Nie wprowadzono żadnych zmian";
  582. }
  583. $response->record = $acl->getItem($primaryKey);
  584. }
  585. catch (Exception $e) {
  586. $response->type = 'error';
  587. $response->msg = $e->getMessage();
  588. }
  589. return $response;
  590. }
  591. public function getCsvTheGeomAjaxAction() {
  592. try {
  593. self::getCsvTheGeomAjax();
  594. } catch (Exception $e) {
  595. SE_Layout::gora();
  596. SE_Layout::menu();
  597. SE_Layout::alert('danger', $e->getMessage());
  598. ?>
  599. <div style="text-align: center;">
  600. <a href="<?=$_SERVER['HTTP_REFERER']?>" class="btn btn-primary" style="width: 80px;">Powrót</a>
  601. </div>
  602. <?php
  603. SE_Layout::dol();
  604. }
  605. }
  606. public function getCsvTheGeomAjax($minDistance = 10, $nearDistance = 1) {
  607. Lib::loadClass('EpsgConversion');
  608. Lib::loadClass('Geometry');
  609. $namespace = V::get('namespace', '', $_GET, 'word');
  610. $acl = Core_AclHelper::getAclByNamespace($namespace);
  611. $table = $acl->getRootTableName();
  612. $id = V::get('id', 0, $_GET, 'int');
  613. $query_points = "select st_astext(`the_geom`) as `the_geom` from `{$table}` where `ID` = {$id}";
  614. $result_points = DB::getPDO()->fetchValue($query_points);
  615. $points = Geometry::objectFromText($result_points, 'Wgs84ToPuwg2000')->points();
  616. $lines = Geometry::pointsToLines($points);
  617. // Dodanie początkowego punktu pierwszej linii do tabeli wszystkcih punktów
  618. $_points = [['point' => $points[0], 'type' => ['p']]];
  619. // Szukanie kolzji dla każdej linii prostej
  620. foreach ($lines as $line) {
  621. $polygon_asText = Geometry::lineToRectangle($line, $nearDistance)->asText('Puwg2000ToWgs84');
  622. $query_nears = "select st_astext(`the_geom`) as `the_geom` from `rurociagi_obce_wsg84` where st_intersects(st_geomfromtext('{$polygon_asText}'), `the_geom`)";
  623. $results_nears = DB::getPDO()->fetchAll($query_nears);
  624. $nears = [];
  625. foreach ($results_nears as $result_nears) {
  626. $nears = array_merge($nears, Geometry::pointsToLines(Geometry::objectFromText($result_nears['the_geom'], 'Wgs84ToPuwg2000')->points()));
  627. }
  628. $nears = array_filter($nears, function ($near) use ($line, $nearDistance) {
  629. return Geometry::distance($line, $near) <= $nearDistance;
  630. });
  631. // Szukanie odcinków kolizyjnych
  632. $crossPoints = [];
  633. $_nearsOnLine = [];
  634. foreach ($nears as $near) {
  635. if ($_crossPoints = Geometry::crossPoint($line, $near)) {
  636. switch (count($_crossPoints)) {
  637. case 1:
  638. // Znaleziono kolizję przecinającą linię
  639. $crossPoints[] = ['point' => $_crossPoints[0], 'type' => ['x']];
  640. break;
  641. case 2:
  642. // Znaleziono kolizję idealnie nałożoną na linię
  643. $_nearsOnLine[] = Geometry::line($_crossPoints[0], $_crossPoints[1]);
  644. break;
  645. default:
  646. throw new Exception(__CLASS__ . "::" . __FUNCTION__ . ' - unknown error');
  647. }
  648. }
  649. // Analiza pobliskich kolizji
  650. $a = Geometry::closedPointOnLine($near->a, $line);
  651. $b = Geometry::closedPointOnLine($near->b, $line);
  652. if (Geometry::distance($a, $line->a) < Geometry::distance($b, $line->a)) $nearOnLine = Geometry::line($a, $b);
  653. else $nearOnLine = Geometry::line($b, $a);
  654. // Weryfikacja czy pobliska kolizja nie jest jednocześnie kolizją przecinajacą i czy nie jest za krótka (<1m) - wtedy ją usuwamy
  655. $add = true;
  656. if ($nearOnLine->length() < 1) {
  657. foreach ($crossPoints as $crossPoint) {
  658. if (Geometry::distance($crossPoint['point'], $nearOnLine) == 0) {
  659. $add = false;
  660. break;
  661. }
  662. }
  663. }
  664. if ($add) $_nearsOnLine[] = $nearOnLine;
  665. }
  666. // Przesortowanie wszystkich kolizji linowych
  667. usort($_nearsOnLine, function ($A, $B) use ($line) {
  668. if (Geometry::samePoint($A->a, $B->a)) return 0;
  669. if (Geometry::distance($A, $line->a) < Geometry::distance($B, $line->a)) return -1;
  670. return 1;
  671. });
  672. // Scalenie wszystkich kolizji jeżeli odstęp między nimi jest krótszy niz 1m
  673. $lastNearOnLine = null;
  674. $nearsOnLine = [];
  675. foreach ($_nearsOnLine as $nearOnLine) {
  676. if ($lastNearOnLine) {
  677. if (Geometry::distance($nearOnLine, $lastNearOnLine) < 1) {
  678. $nearOnLine->a = $lastNearOnLine->a;
  679. if (Geometry::distance($nearOnLine->b, $line->a) < Geometry::distance($lastNearOnLine->b, $line->a)) $nearOnLine->b = $lastNearOnLine->b;
  680. } else $nearsOnLine[] = $lastNearOnLine;
  681. }
  682. $lastNearOnLine = $nearOnLine;
  683. }
  684. if ($lastNearOnLine) $nearsOnLine[] = $lastNearOnLine;
  685. // Nałożenie kolizji liniowych na punkty kolizyjne
  686. foreach ($nearsOnLine as $nearOnLine) {
  687. $crossPoints[] = ['point' => $nearOnLine->a, 'type' => ['iistart']];
  688. $crossPoints[] = ['point' => $nearOnLine->b, 'type' => ['iistop']];
  689. }
  690. // Podzielenie linii prostej na krótsze odcinki, jezeli jest zbyt długa (>$minDistance)
  691. if (($distance = $line->length()) > $minDistance) {
  692. $parts = ceil($distance / $minDistance);
  693. $deltaX = ($line->b->x - $line->a->x) / $parts;
  694. $deltaY = ($line->b->y - $line->a->y) / $parts;
  695. for ($j = 1; $j < $parts; $j++) {
  696. $_point = Geometry::point($line->a->x + $j * $deltaX, $line->a->y + $j * $deltaY);
  697. $collision = false;
  698. foreach ($nearsOnLine as $nearOnLine) {
  699. if (Geometry::distance($nearOnLine, $_point) == 0) {
  700. $collision = true;
  701. break;
  702. }
  703. }
  704. $type = ['m'];
  705. if ($collision) $type[] = 'ii';
  706. $crossPoints[] = ['point' => Geometry::point($line->a->x + $j * $deltaX, $line->a->y + $j * $deltaY), 'type' => $type];
  707. }
  708. }
  709. // Przesortowanie wszystkich punktów na linii
  710. usort($crossPoints, function ($a, $b) use ($line) {
  711. if (Geometry::samePoint($a['point'], $b['point'])) return 0;
  712. if (Geometry::distance($a['point'], $line->a) < Geometry::distance($b['point'], $line->a)) return -1;
  713. return 1;
  714. });
  715. // Dodanie wszystkich punktów kolizyjnych i pośrednich do tabeli wszystkich punktów
  716. foreach ($crossPoints as $crossPoint) $_points[] = ['point' => $crossPoint['point'], 'type' => $crossPoint['type']];
  717. // Dodanie końcowego punktu linii do tabeli wszystkich punktów
  718. $_points[] = ['point' => $line->b, 'type' => ['p']];
  719. }
  720. // Scalenie pobliskich kolizji występujących na różnych liniach
  721. $starts = array_keys(array_filter($_points, function($point) { return in_array('iistart', $point['type']); }));
  722. $stops = array_keys(array_filter($_points, function($point) { return in_array('iistop', $point['type']); }));
  723. $points = array_keys(array_filter($_points, function($point) { return in_array('p', $point['type']); }));
  724. foreach ($stops as $i) {
  725. if (in_array($i+1, $points) && in_array($i+2, $starts)) {
  726. if (Geometry::distance($_points[$i]['point'], $_points[$i+1]['point']) + Geometry::distance($_points[$i+1]['point'], $_points[$i+2]['point']) < 1) {
  727. unset($_points[$i]);
  728. unset($_points[$i + 2]);
  729. $_points[$i + 1]['type'][] = 'ii';
  730. }
  731. }
  732. }
  733. // Połączenie kilku takich samych punktów w jeden punkt (np. punkt początku linii oraz punkt początku kolizji - gdy wypadają w tym samym miejscu)
  734. $points = [];
  735. $lastPoint = null;
  736. $desc = [];
  737. foreach ($_points as $point) {
  738. if ($lastPoint) {
  739. if (Geometry::samePoint($point['point'], $lastPoint['point'])) $point['type'] = array_merge($lastPoint['type'], $point['type']);
  740. else $points[] = $lastPoint;
  741. }
  742. $lastPoint = $point;
  743. }
  744. if ($lastPoint) $points[] = $lastPoint;
  745. // Funkcja generująca czytelny opis rodzaju punktu
  746. $typeToDesc = function($type) {
  747. if (in_array('iistart', $type) && in_array('iistop', $type)) {
  748. $type = array_diff($type, ['iistart', 'iistop']);
  749. $type[] = 'ii';
  750. }
  751. usort($type, function($a, $b) {
  752. if ($a == 'p' || $a == 'm') return -1;
  753. if ($b == 'p' || $b == 'm') return 1;
  754. return 0;
  755. });
  756. return implode('|', array_map(function($_type) {
  757. $types = [
  758. 'p' => 'Punkt',
  759. 'm' => 'Posredni',
  760. 'x' => 'Kolizja (X)',
  761. 'ii' => 'Kolizja (II)',
  762. 'iistart' => 'Kolizja (II) start',
  763. 'iistop' => 'Kolizja (II) stop'
  764. ];
  765. if (isset($types[$_type])) return $types[$_type];
  766. throw new Exception("Nieznany typ punktu - {$_type} (" . __CLASS__ . '::' . __FUNCTION__ . ')');
  767. }, $type));
  768. };
  769. // Generowanie pliku CSV
  770. $csv = implode("\n", array_map(function ($point, $i) use ($typeToDesc) {
  771. try {
  772. $z = EpsgConversion::GetZByPuwg2000($point['point']->x, $point['point']->y);
  773. } catch (Exception $e) {
  774. $z = 0;
  775. }
  776. return $i . "," . round($point['point']->y, 3) . "," . round($point['point']->x, 3) . "," . round($z, 3) . "," . $typeToDesc($point['type']);
  777. }, $points, range(1, count($points))));
  778. // echo "<pre>{$csv}</pre>";
  779. Response::sendCsv($csv, "{$table}.{$id}");
  780. }
  781. public function moreFunctionsCellAjaxAction() {
  782. Response::sendTryCatchJson(array($this, 'moreFunctionsCell'), $args = $_GET);
  783. }
  784. public function moreFunctionsCell($args) {// ajax task 'MORE_FUNCTIONS_CELL'
  785. $id = V::get('ID', 0, $args, 'int');
  786. if ($id <= 0) throw new HttpException("404", 404);
  787. $namespace = V::get('namespace', '', $args, 'word');
  788. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  789. $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $args)));
  790. $response = new stdClass();
  791. $response->type = 'success';
  792. $response->msg = 'Funkcje';
  793. $response->rowFunctions = Core_AclHelper::getMoreFunctionsCell($acl, array('primary_key' => $id));
  794. return $response;
  795. }
  796. public function createFormAction() {// TODO: move to createFormJsonAction
  797. try {
  798. $args = $_REQUEST;
  799. $namespace = V::get('namespace', '', $args, 'word');
  800. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  801. $acl = Core_AclHelper::getAclByNamespace($namespace);
  802. $tbl = $this->getTableAjaxWidget($acl);
  803. $tbl->sendAjaxCreate();
  804. } catch (Exception $e) {
  805. DBG::log($e);
  806. throw $e;
  807. }
  808. }
  809. public function createFormJsonAction() {
  810. Response::sendTryCatchJson(array($this, 'createFormJson'), $args = $_REQUEST);
  811. }
  812. public function createFormJson($args) { // namespace, _hash, _primaryKey
  813. $namespace = V::get('namespace', '', $args, 'word');
  814. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  815. $acl = Core_AclHelper::getAclByNamespace($namespace);
  816. $tbl = $this->getTableAjaxWidget($acl);
  817. if (!Core_AclHelper::hasCreatePerms($acl)) {
  818. return [
  819. 'type' => "success",
  820. 'msg' => "Dodaj nowy rekord",
  821. 'body' => [
  822. 'reactNode' => [ 'div', [ 'class' => "alert alert-danger" ], "Brak uprawnień do utworzenia nowego rekordu." ]
  823. ],
  824. ];
  825. // throw new Exception("Brak uprawnień do utworzenia nowego rekordu.");
  826. }
  827. $fieldsList = array();
  828. foreach ($acl->getFieldListByIdZasob() as $kID => $fieldName) {
  829. if ($fieldName == 'ID') continue;
  830. $field['name'] = $fieldName;
  831. $field['opis'] = $acl->getFieldOpis($fieldName);
  832. $field['label'] = $acl->getFieldLabel($fieldName);
  833. if (empty($field['label'])) $field['label'] = str_replace('_', ' ', $fieldName);
  834. $fieldsList[$kID] = $field;
  835. }
  836. $cols = array();
  837. $forceFilterInit = array();
  838. $defaultAclGroup = User::getDefaultAclGroup();
  839. if ($defaultAclGroup) {
  840. $forceFilterInit['A_ADM_COMPANY'] = $defaultAclGroup;
  841. $forceFilterInit['A_CLASSIFIED'] = $defaultAclGroup;
  842. }
  843. foreach ($_GET as $k => $v) { // TODO: read from $args ?
  844. if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
  845. $fldName = substr($k, 3);
  846. $forceFilterInit[$fldName] = $v;
  847. }
  848. }
  849. DBG::log($forceFilterInit, 'array', "\$forceFilterInit");
  850. foreach ($fieldsList as $kID => $field) {
  851. $defaultValue = '';
  852. if (!empty($forceFilterInit[$field['name']])) {
  853. $defaultValue = $forceFilterInit[$field['name']];
  854. }
  855. $cols[$kID] = V::get("f{$kID}", $defaultValue, $_POST);
  856. }
  857. DBG::log($cols, 'array', "\$cols - field values");
  858. $tsValues = array();
  859. $featureFunctions = [
  860. // 'edit' => [ 'href' => '#EDIT/{0}', 'ico' => 'glyphicon glyphicon-pencil', 'title' => "Edytuj rekord"],
  861. 'hist' => [ 'href' => '#HIST/{0}', 'ico' => 'glyphicon glyphicon-book', 'title' => "Historia" ],
  862. 'files' => [ 'href' => '#FILES/{0}', 'ico' => 'glyphicon glyphicon-folder-open', 'title' => "Pliki" ],
  863. // 'cp' => [ 'href' => '#', 'ico' => 'glyphicon glyphicon-plus-sign', 'title' => "Kopiuj rekord", 'onclick' => 'return tableAjaxCopy({0});' ],
  864. 'msgs' => [ 'href' => "index.php?_route=TableMsgs&_task=tableRow&idTable=".$acl->getID()."&idRow={0}", 'ico' => 'glyphicon glyphicon-envelope', 'title' => "Wiadomości" ],
  865. ];
  866. $jsFields = [];
  867. $tabindex = 0;
  868. foreach ($fieldsList as $kID => $vCol) {
  869. $fieldName = $vCol['name'];
  870. $fieldLabel = str_replace('<br>', ' ', $vCol['label']);
  871. DBG::log(['$fieldName'=>$fieldName, 'canCreate'=>$acl->canCreateField($fieldName)], 'array', "form field");
  872. if ($acl->canCreateField($fieldName)) {
  873. DBG::log("editFormJson::field({$fieldName})");
  874. $fieldParams = [ 'appendBack' => true, 'tabindex' => (++$tabindex), 'maxGrid' => 8 ];
  875. if (!empty($tsValues[$kID])) $fieldParams['typespecialValue'] = $tsValues[$kID];
  876. $jsFields[] = [ 'div', [ 'class' => "form-group" ], [
  877. [ 'label', [ 'class' => "control-label", 'for' => "f{$kID}" ], [
  878. [ 'span', [ 'style' => ['padding-right'=>'4px'] ], $fieldLabel ],
  879. [ 'i', [ 'class' => "glyphicon glyphicon-info-sign frm-help", 'data-toggle' => "popover", 'data-trigger' => "hover", 'title' => "", 'data-content' => htmlspecialchars($vCol['opis']), 'data-original-title' => "[{$kID}] {$fieldName}" ] ],
  880. ] ],
  881. [ 'div', [ 'class' => "" ], [
  882. UI::hGetFormItem($acl, $fieldName, 'C', $kID, "f{$kID}", $cols[$kID], $fieldParams),
  883. ] ]
  884. ] ];
  885. // } else {
  886. // $jsFields[] = [ 'div', [ 'class' => "form-group" ], [
  887. // "TODO: SKIP field ({$fieldName}) - ! canWriteObjectField && ! canReadObjectField"
  888. // ]];
  889. }
  890. }
  891. $jsFields[] = [ 'div', [ 'class' => "form-group" ], [
  892. [ 'div', [ 'class' => "" ], [
  893. ['button', [ 'type' => "submit", 'class' => "btn btn-primary", 'tabindex' => ++$tabindex ], "Zapisz" ]
  894. ] ]
  895. ] ];
  896. $tblLabel = $acl->getNamespace();
  897. if ('default_db' == $acl->getSourceName()) {
  898. $tblLabel = array();
  899. $zasobObj = ProcesHelper::getZasobTableInfo($acl->getID());
  900. if (!$zasobObj) throw new Exception("Zasob TABELA ID=" . $acl->getID() . " nie istnieje");
  901. if (!empty($zasobObj->DESC_PL)) $tblLabel []= $zasobObj->DESC_PL;
  902. if (!empty($zasobObj->OPIS)) $tblLabel []= $zasobObj->OPIS;
  903. $tblLabel = implode(" - ", $tblLabel);
  904. }
  905. $syncUrl = Request::getPathUri() . 'index.php?_route=ViewTableAjax&namespace=' . $acl->getNamespace();
  906. $jsGui = [
  907. 'reactNode' => [ 'div', [ 'class' => "container AjaxFrmHorizontalEdit", 'style' => [ "max-width" => "940px" ] ], [
  908. [ 'h4', [ 'style' => [ "padding-bottom" => "3px", "border-bottom" => "1px solid #ddd" ] ], [
  909. "Dodaj nowy rekord",
  910. ] ],
  911. [ 'P5UI__FeatureCreateForm', [
  912. 'class' => "", 'action' => "", 'method' => "post",
  913. 'id' => "CREATE_FRM_{$this->_htmlID}", // TODO: rm - use React nodes // TODO: $this->_htmlID not exists!
  914. 'ajaxSaveUrl' => "{$syncUrl}&_task=createSaveAjax", // TODO:? &_hash={$this->_htmlID}
  915. 'ajaxSaveLegacyUrl' => "{$syncUrl}&_task=createSaveLegacy", // TODO: Legacy RM
  916. 'namespace' => $acl->getNamespace(),
  917. 'tableLabelHtml' => $tblLabel,
  918. '_htmlID' => $acl->getName(),
  919. ], [
  920. [ 'fieldset', [ 'style' => [ "padding-bottom" => "100px" ] ], $jsFields ] // fieldset
  921. ] ] // form
  922. ] ] // .container
  923. ];
  924. return [
  925. 'type' => "success",
  926. 'msg' => "Dodaj nowy rekord",
  927. 'body' => $jsGui, // TODO: action for GUI: array to render by function h, js to trigger
  928. ];
  929. }
  930. public function createSaveAjaxAction() {
  931. Response::sendTryCatchJson(array($this, 'createSaveAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  932. }
  933. public function createSaveAjax($args) {
  934. throw new Exception("TODO: ...");
  935. }
  936. public function createSaveLegacyAction() { // TODO: Legacy RM
  937. $args = [
  938. 'namespace' => V::get('namespace', '', $_GET),
  939. 'body' => Request::getRequestJson(),
  940. ];
  941. DBG::log($args, 'array', 'createSaveLegacyAction');
  942. Response::sendTryCatchJson(array($this, 'createSaveLegacy'), $args);
  943. }
  944. public function createSaveLegacy($args) { // TODO: Legacy RM
  945. $namespace = V::get('namespace', '', $args, 'word');
  946. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  947. $body = V::get('body', null, $args);
  948. if (!$body) throw new HttpException("Bad Request - missing body", 400);
  949. $acl = Core_AclHelper::getAclByNamespace($namespace);
  950. $tbl = $this->getTableAjaxWidget($acl);
  951. DBG::log($args, 'array', "ajaxCreateSave");
  952. $createdId = null;
  953. try {
  954. $item = $acl->convertObjectFromUserInput($body, $type = 'array_by_id', $prefix = 'f');
  955. $createdId = $acl->addItem($item);
  956. if ($createdId) {
  957. return [
  958. 'type' => 'success',
  959. 'msg' => "Utworzono pomyślnie rekord nr {$createdId}",
  960. 'id' => $createdId,
  961. 'record' => $acl->buildQuery([])->getItem($createdId),
  962. ];
  963. }
  964. else {
  965. return [
  966. 'type' => 'error',
  967. 'msg' => "Nie udało się utworzyć nowego rekordu!",
  968. ];
  969. }
  970. }
  971. catch (Exception $e) {
  972. return [
  973. 'type' => 'error',
  974. 'msg' => $e->getMessage(),
  975. ];
  976. }
  977. }
  978. public function editFormAction() { // TODO: not used - moved to editFormJsonAction
  979. try {
  980. $args = $_REQUEST;
  981. $id = V::get('_primaryKey', 0, $args, 'int');
  982. if ($id <= 0) throw new HttpException("Bad Request - missing primaryKey", 400);
  983. $namespace = V::get('namespace', '', $args, 'word');
  984. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  985. $acl = Core_AclHelper::getAclByNamespace($namespace);
  986. $tbl = $this->getTableAjaxWidget($acl);
  987. $tbl->sendAjaxEdit($id, $args);
  988. } catch (Exception $e) {
  989. DBG::log($e);
  990. throw $e;
  991. }
  992. }
  993. public function editFormJsonAction() {
  994. Response::sendTryCatchJson(array($this, 'editFormJson'), $args = $_REQUEST);
  995. }
  996. public function editFormJson($args) { // namespace, _hash, _primaryKey
  997. $id = V::get('_primaryKey', 0, $args, 'int');
  998. if ($id <= 0) throw new HttpException("Bad Request - missing primaryKey", 400);
  999. $namespace = V::get('namespace', '', $args, 'word');
  1000. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  1001. $acl = Core_AclHelper::getAclByNamespace($namespace);
  1002. $tbl = $this->getTableAjaxWidget($acl);
  1003. $record = $acl->buildQuery([])->getItem($id);
  1004. if (!$acl->canWriteRecord($record) && !$acl->hasPermSuperWrite()) {
  1005. return [
  1006. 'type' => "success",
  1007. 'msg' => "Edycja rekordu nr {$id}",
  1008. 'body' => [
  1009. 'reactNode' => [ 'div', [ 'class' => "alert alert-danger" ], "Brak dostępu do rekordu" ]
  1010. ],
  1011. ];
  1012. // throw new Exception("Brak dostępu do rekordu");
  1013. }
  1014. $fieldsList = array();
  1015. foreach ($acl->getFieldListByIdZasob() as $kID => $fieldName) {
  1016. if ($fieldName == 'ID') continue;
  1017. $field['name'] = $fieldName;
  1018. $field['opis'] = $acl->getFieldOpis($fieldName);
  1019. $field['label'] = $acl->getFieldLabel($fieldName);
  1020. if (empty($field['label'])) $field['label'] = str_replace('_', ' ', $fieldName);
  1021. $fieldsList[$kID] = $field;
  1022. }
  1023. $cols = array();
  1024. foreach ($fieldsList as $kID => $field) {
  1025. $cols[$kID] = '';
  1026. if ($acl->canReadObjectField($field['name'], $record)) {
  1027. $cols[$kID] = V::get($field['name'], '', $record);
  1028. } else {
  1029. $cols[$kID] = '*****';
  1030. }
  1031. $cols[$kID] = V::get("f{$kID}", $cols[$kID], $_POST);
  1032. }
  1033. $tsValues = array();
  1034. if (!empty($fieldsList)) {
  1035. foreach ($fieldsList as $vColID => $vCol) {
  1036. $typeSpecial = Typespecial::getInstance($vColID, $vCol['name']);
  1037. if ($typeSpecial) {
  1038. $colValue = V::get($vCol['name'], '', $record);
  1039. $specialValues = $typeSpecial->getEditSelectedValuesByIds($acl->getID(), $record['ID'], $vCol['name'], $colValue);
  1040. if (!empty($specialValues)) {
  1041. $tsValues[$vColID] = implode('<br>', $specialValues);
  1042. }
  1043. }
  1044. }
  1045. }
  1046. DBG::log($tsValues, 'array', "editFormJson::tsValues");
  1047. foreach ($tsValues as $idx => $value) {
  1048. if ('<' === substr($value, 0, 1)) {
  1049. // $tsValues[$idx] = UI::convertHtmlToArray($value); // TODO: ...
  1050. $tsValues[$idx] = [ 'P5UI__RawHtml', [ 'rawHtml' => $tsValues[$idx] ] ];
  1051. }
  1052. }
  1053. DBG::log($tsValues, 'array', "editFormJson::tsValues parsed");
  1054. $featureFunctions = [
  1055. // 'edit' => [ 'href' => '#EDIT/{0}', 'ico' => 'glyphicon glyphicon-pencil', 'title' => "Edytuj rekord"],
  1056. 'hist' => [ 'href' => '#HIST/{0}', 'ico' => 'glyphicon glyphicon-book', 'title' => "Historia" ],
  1057. 'files' => [ 'href' => '#FILES/{0}', 'ico' => 'glyphicon glyphicon-folder-open', 'title' => "Pliki" ],
  1058. // 'cp' => [ 'href' => '#', 'ico' => 'glyphicon glyphicon-plus-sign', 'title' => "Kopiuj rekord", 'onclick' => 'return tableAjaxCopy({0});' ],
  1059. 'msgs' => [ 'href' => "index.php?_route=TableMsgs&_task=tableRow&idTable=".$acl->getID()."&idRow={0}", 'ico' => 'glyphicon glyphicon-envelope', 'title' => "Wiadomości" ],
  1060. ];
  1061. $rowFunctionsOut = [ 'P5UI__FeatureRowFunctions', [
  1062. 'id' => $record[ $acl->getPrimaryKeyField() ],
  1063. 'functions' => $featureFunctions,
  1064. 'showLabels' => true,
  1065. 'viewMoreDropdown' => [
  1066. 'primaryKey' => $record['ID'],
  1067. 'uri' => $this->getLink('moreFunctionsCellAjax', [ 'namespace' => $acl->getNamespace(), 'ID' => $record['ID'] ]),
  1068. ],
  1069. ] ]; // TODO: $this->_showRowFunctions($record['ID'], array('edit', 'cp'), true);
  1070. $jsFields = [];
  1071. $tabindex = 0;
  1072. foreach ($fieldsList as $kID => $vCol) {
  1073. $fieldName = $vCol['name'];
  1074. $fieldLabel = str_replace('<br>', ' ', $vCol['label']);
  1075. DBG::log(['$fieldName'=>$fieldName, '$record'=>$record, 'canWrite'=>$acl->canWriteObjectField($fieldName, $record), 'canRead'=>$acl->canReadObjectField($fieldName, $record)], 'array', "form field");
  1076. if ($acl->canWriteObjectField($fieldName, $record)) {
  1077. DBG::log("editFormJson::field({$fieldName})");
  1078. $fieldParams = [ 'appendBack' => true, 'tabindex' => (++$tabindex), 'maxGrid' => 8 ];
  1079. if (!empty($tsValues[$kID])) $fieldParams['typespecialValue'] = $tsValues[$kID];
  1080. $jsFields[] = [ 'div', [ 'class' => "form-group" ], [
  1081. [ 'label', [ 'class' => "control-label", 'for' => "f{$kID}" ], [
  1082. [ 'span', [ 'style' => ['padding-right'=>'4px'] ], $fieldLabel ],
  1083. [ 'i', [ 'class' => "glyphicon glyphicon-info-sign frm-help", 'data-toggle' => "popover", 'data-trigger' => "hover", 'title' => "", 'data-content' => htmlspecialchars($vCol['opis']), 'data-original-title' => "[{$kID}] {$fieldName}" ] ],
  1084. ] ],
  1085. [ 'div', [ 'class' => "" ], [
  1086. UI::hGetFormItem($acl, $fieldName, 'W', $kID, "f{$kID}", $cols[$kID], $fieldParams, $record),
  1087. ] ]
  1088. ] ];
  1089. } else if ($acl->canReadObjectField($fieldName, $record)) {
  1090. $jsFields[] = [ 'div', [ 'class' => "form-group" ], [
  1091. [ 'label', [ 'class' => "control-label", 'for' => "f{$kID}" ], [
  1092. [ 'span', [ 'style' => ['padding-right'=>'4px'] ], $fieldLabel ],
  1093. [ 'i', [ 'class' => "glyphicon glyphicon-info-sign frm-help", 'data-toggle' => "popover", 'data-trigger' => "hover", 'title' => "", 'data-content' => htmlspecialchars($vCol['opis']), 'data-original-title' => "[{$kID}] {$fieldName}" ] ],
  1094. ] ],
  1095. [ 'div', [ 'class' => "" ], [
  1096. ['p', [ 'style' => [ 'margin-top' => '5px' ] ], [
  1097. (!empty($tsValues[$kID]))
  1098. ? $tsValues[$kID]
  1099. : V::get($fieldName, '', $record)
  1100. ] ],
  1101. ] ]
  1102. ] ];
  1103. // } else {
  1104. // $jsFields[] = [ 'div', [ 'class' => "form-group" ], [
  1105. // "TODO: SKIP field ({$fieldName}) - ! canWriteObjectField && ! canReadObjectField"
  1106. // ]];
  1107. }
  1108. }
  1109. $jsFields[] = [ 'div', [ 'class' => "form-group" ], [
  1110. [ 'div', [ 'class' => "" ], [
  1111. ['button', [ 'type' => "submit", 'class' => "btn btn-primary", 'tabindex' => ++$tabindex ], "Zapisz" ]
  1112. ] ]
  1113. ] ];
  1114. $tblLabel = $acl->getNamespace();
  1115. if ('default_db' == $acl->getSourceName()) {
  1116. $tblLabel = array();
  1117. $zasobObj = ProcesHelper::getZasobTableInfo($acl->getID());
  1118. if (!$zasobObj) throw new Exception("Zasob TABELA ID=" . $acl->getID() . " nie istnieje");
  1119. if (!empty($zasobObj->DESC_PL)) $tblLabel []= $zasobObj->DESC_PL;
  1120. if (!empty($zasobObj->OPIS)) $tblLabel []= $zasobObj->OPIS;
  1121. $tblLabel = implode(" - ", $tblLabel);
  1122. }
  1123. $syncUrl = Request::getPathUri() . 'index.php?_route=ViewTableAjax&namespace=' . $acl->getNamespace();
  1124. $jsGui = [
  1125. 'reactNode' => [ 'div', [ 'class' => "container AjaxFrmHorizontalEdit", 'style' => [ "max-width" => "940px" ] ], [
  1126. [ 'h4', [ 'style' => [ "padding-bottom" => "3px", "border-bottom" => "1px solid #ddd" ] ], [
  1127. "Edycja rekordu Nr {$record['ID']}",
  1128. [ 'small', [ 'class' => "pull-right valign-btns-bottom" ], [ $rowFunctionsOut ] ],
  1129. ] ],
  1130. [ 'P5UI__FeatureEditForm', [
  1131. 'class' => "", 'action' => "", 'method' => "post",
  1132. 'id' => "EDIT_FRM_{$this->_htmlID}", // TODO: rm - use React nodes // TODO: $this->_htmlID not exists!
  1133. 'ajaxSaveUrl' => "{$syncUrl}&_task=editSaveAjax", // TODO:? &_hash={$this->_htmlID}
  1134. 'namespace' => $acl->getNamespace(),
  1135. 'idRecord' => $record['ID'],
  1136. 'tableLabelHtml' => $tblLabel,
  1137. ], [
  1138. [ 'fieldset', [ 'style' => [ "padding-bottom" => "100px" ] ], $jsFields ] // fieldset
  1139. ] ] // form
  1140. ] ] // .container
  1141. ];
  1142. return [
  1143. 'type' => "success",
  1144. 'msg' => "Edycja rekordu nr {$id}",
  1145. 'body' => $jsGui, // TODO: action for GUI: array to render by function h, js to trigger
  1146. ];
  1147. }
  1148. public function editSaveAjaxAction() {
  1149. Response::sendTryCatchJson(array($this, 'editSaveAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  1150. }
  1151. public function editSaveAjax($args) {
  1152. $namespace = V::get('namespace', '', $args, 'word');
  1153. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  1154. $acl = Core_AclHelper::getAclByNamespace($namespace);
  1155. $primaryKeyField = $acl->getPrimaryKeyField();
  1156. $primaryKey = V::get('primaryKey', 0, $args, 'int');
  1157. if (empty($primaryKey)) throw new HttpException("Bad Request - missing primaryKey!", 400);
  1158. $item = $acl->getItem($primaryKey);
  1159. if (!$item) throw new HttpException("Item not exists!", 404);
  1160. $itemFromUser = $acl->convertObjectFromUserInput($args['form'], $type = 'array_by_id', $prefix = 'f');
  1161. $response = new stdClass();
  1162. $response->primaryKey = $primaryKey;
  1163. try {
  1164. $itemFromUser[$primaryKeyField] = $primaryKey;
  1165. $affected = $acl->updateItem($itemFromUser);
  1166. if ($affected > 0) {
  1167. $response->type = 'success';
  1168. $response->msg = "Rekord zapisany pomyślnie";//"Record saved successfully";
  1169. } else if ($affected == 0) {
  1170. $response->type = 'info';
  1171. $response->msg = "Nie wprowadzono żadnych zmian";
  1172. }
  1173. $response->record = $acl->getItem($primaryKey);
  1174. $rowFunList = Core_AclHelper::getMoreFunctionsCell($acl, array('primary_key'=>$primaryKey, 'record'=>$response->record));
  1175. if (!empty($rowFunList)) $response->rowFunctions = $rowFunList;
  1176. }
  1177. catch (Exception $e) {
  1178. $response->type = 'error';
  1179. $response->msg = "Wystąpiły błędy!";
  1180. $response->msg .= $e->getMessage();
  1181. }
  1182. return $response;
  1183. }
  1184. public function typeSpecialCellAction() {
  1185. Response::sendTryCatchJson(array($this, 'typeSpecialCell'), $args = $_REQUEST);
  1186. }
  1187. public function typeSpecialCell($args) {
  1188. $namespace = V::get('namespace', '', $args, 'word');
  1189. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  1190. $acl = Core_AclHelper::getAclByNamespace($namespace);
  1191. $id = V::get('ID', 0, $args, 'int');
  1192. $fieldName = V::get('col', '', $args);
  1193. if ($id <= 0 || empty($fieldName)) throw new HttpException("Bad Request - missing id or col", 400);
  1194. $col = $fieldName;// TODO: RM $col
  1195. $jsonData = new stdClass();
  1196. $idField = $acl->getFieldIdByName($fieldName);
  1197. if (!$idField) throw new Exception("Wrong field");
  1198. $item = $acl->getItem($id);
  1199. if (!$acl->canReadObjectField($fieldName, $item)) throw new Exception("Brak dostępu");
  1200. $typeSpecial = Typespecial::getInstance($idField, $fieldName);
  1201. if ($typeSpecial) {
  1202. $jsonData->data = $typeSpecial->getReturnData($acl->getID(), $id, $fieldName, '');
  1203. $jsonData->namespace = 'default_db/' . V::get('tbl_name', '', $jsonData->data);
  1204. }
  1205. return $jsonData;
  1206. }
  1207. public function typespecialAction() { Response::sendTryCatchJson(array($this, 'typespecial'), $args = $_REQUEST); }
  1208. public function typespecial($args) { // @required idField, @optional: q (query), selected (selected value), idRecord (fetch value for given record)
  1209. $idField = V::get('idField', 0, $args, 'int');
  1210. if (!$idField) throw new HttpException("Bad Request - missing idField", 400);
  1211. $query = V::get('q', '', $_REQUEST);
  1212. DBG::log("\$query({$query})");
  1213. $cellInfo = DB::getPDO()->fetchFirst("
  1214. select *
  1215. from CRM_PROCES_idx_TABLES_INFO_VIEW
  1216. where ID_CELL = :id
  1217. ", [ ':id' => $idField ]);
  1218. DBG::log($cellInfo, 'array', "cell info");
  1219. if (!$cellInfo) throw new HttpException("Bad Request - wrong idField", 400);
  1220. // 'ID_CELL' => '24310',
  1221. // 'CELL_NAME' => 'L_APPOITMENT_USER',
  1222. // 'CELL_LABEL' => 'Osoba odpowiedzialna',
  1223. // 'CELL_DESCRIPTION' => '',
  1224. // 'CELL_SORT_PRIO' => '3',
  1225. // 'ID_TABLE' => '13051',
  1226. // 'TABLE_NAME' => 'TEST_PERMS',
  1227. // 'TABLE_LABEL' => 'Test permy',
  1228. // 'TABLE_DESCRIPTION' => '',
  1229. // 'ID_DATABASE' => '36',
  1230. $namespace = (false !== strpos($cellInfo['TABLE_NAME'], '/')) ? $cellInfo['TABLE_NAME'] : "default_db/{$cellInfo['TABLE_NAME']}";
  1231. if (!$namespace) throw new HttpException("Bad Request - wrong idField, cannot find namespace", 400);
  1232. $acl = Core_AclHelper::getAclByNamespace($namespace);
  1233. $fieldName = $cellInfo['CELL_NAME'];
  1234. $jsonData = array();
  1235. $typeSpecial = Typespecial::getInstance($idField, $fieldName);
  1236. if ($typeSpecial) {
  1237. // if (idRecord or selected) { // TODO
  1238. // $jsonData->data = $typeSpecial->getReturnData($acl->getID(), $id, $fieldName, '');
  1239. // $jsonData->namespace = 'default_db/' . V::get('tbl_name', '', $jsonData->data);
  1240. $rawRows = null;
  1241. $rows = $typeSpecial->getValuesWithExports($query);
  1242. DBG::log($rows, 'array', "\$rows({$query})");
  1243. foreach ($rows as $kID => $vItem) {
  1244. $itemJson = new stdClass();
  1245. $itemJson->id = $vItem->id;
  1246. $itemJson->name = $vItem->param_out;
  1247. if (!empty($vItem->exports)) {
  1248. $itemJson->exports = $vItem->exports;
  1249. }
  1250. if (!empty($vItem->{'$order'})) {
  1251. $itemJson->{'$order'} = $vItem->{'$order'};
  1252. }
  1253. $jsonData[] = $itemJson;
  1254. }
  1255. }
  1256. return $jsonData;
  1257. }
  1258. /**
  1259. * @param $_GET['namespace'] = AclNamespace
  1260. * @param $_GET['format'] = 'csv' | 'html'
  1261. * @param $_GET['flds'] = csv - coma separated field names
  1262. * @param $_GET['sortCol'] = FieldName
  1263. * @param $_GET['sortDir'] = SortDir ('desc' | 'asc')
  1264. * @param $_GET['f_{$fieldName}'] = filter
  1265. * @param $_GET['sf_{$fieldName}'] = force filter
  1266. */
  1267. public function exportAction() {
  1268. $args = $_GET;
  1269. $namespace = V::get('namespace', '', $args, 'word');
  1270. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  1271. $acl = Core_AclHelper::getAclByNamespace($namespace);
  1272. $exportLimit = 10000;
  1273. $params = array();
  1274. $params['limit'] = $exportLimit;
  1275. // $params['limitstart'] = 0;
  1276. $params['order_by'] = V::get('sortCol', '', $args);
  1277. $params['order_dir'] = V::get('sortDir', '', $args);
  1278. $params['cols'] = array($acl->getPrimaryKeyField());
  1279. $toExportFields = explode(',', V::get('flds', '', $_GET));
  1280. if (empty($toExportFields)) throw new Exception("Nie wybrano żandych pól do exportu.");
  1281. $allowedExportFieldList = Core_AclHelper::getExportFieldList($acl);
  1282. foreach ($toExportFields as $fieldName) {
  1283. if ($fieldName == $acl->getPrimaryKeyField()) continue;
  1284. if (!in_array($fieldName, $allowedExportFieldList)) throw new Exception("Brak uprawnień do exportu pola '{$fieldName}'");
  1285. $params['cols'][] = $fieldName;
  1286. }
  1287. $labels = array();
  1288. foreach ($toExportFields as $fieldName) {
  1289. $labels[ $fieldName ] = $acl->getFieldLabel($fieldName);
  1290. }
  1291. foreach ($args as $k => $v) {
  1292. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && strlen($v) > 0) {// filter prefix
  1293. $params[$k] = $v;
  1294. }
  1295. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && strlen($v) > 0) {// special filter prefix
  1296. $params[$k] = $v;
  1297. }
  1298. }
  1299. try {
  1300. $queryFeatures = $acl->buildQuery($params);
  1301. $total = $queryFeatures->getTotal();
  1302. $listItems = $queryFeatures->getItems();
  1303. $primaryKeyField = $acl->getPrimaryKeyField();
  1304. $items = []; foreach ($listItems as $item) $items[ $item[$primaryKeyField] ] = $item;
  1305. } catch (Exception $e) {
  1306. DBG::log($e);
  1307. throw $e;
  1308. }
  1309. $format = V::get('format', 'html', $_GET);
  1310. switch ($format) {
  1311. case 'html': {
  1312. UI::gora();
  1313. echo UI::h('table', ['class'=>'table table-bordered table-hover'], [
  1314. UI::h('thead', [], [
  1315. UI::h('tr', [], array_map(function ($label) {
  1316. return UI::h('th', [], $label);
  1317. }, $labels))
  1318. ]),
  1319. UI::h('tbody', [], array_map(function ($item) use($labels) {
  1320. return UI::h('tr', [], array_map(function ($fieldName) use ($item) {
  1321. return UI::h('td', [], V::get($fieldName, '', $item));
  1322. }, array_keys($labels)));
  1323. }, $items)),
  1324. ]);
  1325. UI::dol();
  1326. exit;
  1327. }
  1328. case 'csv_cp1250':
  1329. case 'csv': {
  1330. $csvFileName = "Tabela-" . $acl->getName() . "-" . date("Y-m-d_H_s");
  1331. header('Content-Type: text/csv; charset=utf-8');
  1332. header("Content-Disposition: attachment; filename={$csvFileName}.csv");
  1333. $csvSeparator = ';';
  1334. $csvHeader = implode($csvSeparator, array_map(function ($label) use ($item) {
  1335. return '"' . addslashes($label) . '"';
  1336. }, array_values($labels)));
  1337. $csvRows = implode("\r\n", array_map(function ($item) use ($labels, $csvSeparator) {
  1338. return implode($csvSeparator, array_map(function ($fieldName) use ($item) {
  1339. return '"' . addslashes(V::get($fieldName, '', $item)) . '"';
  1340. }, array_keys($labels)));
  1341. }, $items));
  1342. switch ($format) {
  1343. case 'csv': echo $csvHeader . "\n" . $csvRows; exit;
  1344. case 'csv_cp1250': echo iconv('utf-8', 'Windows-1250//IGNORE', $csvHeader) . "\r\n" . iconv('utf-8', 'Windows-1250//IGNORE', $csvRows); exit;
  1345. die("Nieobsługiwane kodowanie danych csv.");
  1346. }
  1347. exit;
  1348. }
  1349. }
  1350. die("Nieobsługiwany format danych.");
  1351. }
  1352. public function loadDataAjaxAction() {
  1353. $namespace = V::get('namespace', '', $_REQUEST, 'word');
  1354. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  1355. $acl = Core_AclHelper::getAclByNamespace($namespace);
  1356. $backRefFilter = [
  1357. 'namespace' => V::get('backRefNS', '', $_REQUEST),
  1358. 'primaryKey' => V::get('backRefPK', '', $_REQUEST),
  1359. 'fieldName' => V::get('backRefField', '', $_REQUEST),
  1360. ];
  1361. $childRefFilter = [
  1362. 'namespace' => V::get('childRefNS', '', $_GET),
  1363. 'primaryKey' => V::get('childRefPK', '', $_GET),
  1364. ];
  1365. $tbl = $this->getTableAjaxWidget($acl, $backRefFilter, $childRefFilter);
  1366. Response::sendTryCatchJson(array($tbl, 'ajaxData'), $args = $_GET);
  1367. }
  1368. public function uploadFilesAjaxAction() {
  1369. Response::sendTryCatchJson([$this, 'uploadFilesAjax'], $args = $_POST);
  1370. }
  1371. public function uploadFilesAjax($args) {
  1372. DBG::log($_FILES, 'array', "\$_FILES");
  1373. DBG::log($args, 'array', "\$args");
  1374. $namespace = V::get('namespace', '', $args, 'word');
  1375. if (!$namespace) throw new Exception("Missing namespace");
  1376. $primaryKey = V::get('primaryKey', '', $args, 'int');
  1377. if ($primaryKey <= 0) throw new Exception("Missing primaryKey");
  1378. if (empty($_FILES)) throw new Exception("Missing files");
  1379. $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
  1380. Lib::loadClass('FileUploader');
  1381. Lib::loadClass('FoldersConfig');
  1382. // $dbID = $acl->getDB();
  1383. // $db = DB::getDB($dbID);
  1384. // if (!$db) throw new HttpException("No DB ({$dbID})", 406);
  1385. $record = $acl->buildQuery([])->getItem($primaryKey);
  1386. DBG::log($record, 'array', "\$record");
  1387. if (!$record) throw new HttpException("No item ID({$primaryKey})", 404);
  1388. if (!$acl->canReadRecord($record)) throw new Exception("Brak uprawnień do odczytu");
  1389. if (!$acl->canWriteRecord($record)) throw new Exception("Brak uprawnień do zapisu");
  1390. $rootTableName = $acl->getRootTableName();
  1391. $confTblName = "{$rootTableName}_COLUMN";
  1392. $folderConfAll = FoldersConfig::getRawData();
  1393. if (!FoldersConfig::hasConfig($confTblName)) throw new HttpException("Brak danych konfiguracyjnych ({$rootTableName})", 404);
  1394. $folderConf = FoldersConfig::getAll($confTblName);
  1395. DBG::log($folderConf, 'array', "\$folderConf");
  1396. $uploader = new FileUploader($confTblName, (object)$record);
  1397. if (!$uploader->setConfig($folderConf)) throw new HttpException("Błąd danych konfiguracyjnych ({$rootTableName})", 404);
  1398. $uploader->findFolder();
  1399. DBG::log($uploader, 'array', "\$uploader");
  1400. // $errorMsg = '';
  1401. // if (!empty($args['SCANS_COLUMN_ADD'])) {
  1402. // $uploaded = $uploader->tryMoveFromScanAjax($errorMsg);
  1403. // }
  1404. // else {
  1405. // $uploaded = $uploader->tryUploadAjax($errorMsg);
  1406. // }
  1407. $destPath = $uploader->getDestLocalPath($show_if_not_found = true);
  1408. DBG::log($destPath, 'array', "\$destPath");
  1409. if (!file_exists($destPath)) {
  1410. if (!$uploader->tryCreateDestFolder($destPath)) throw new Exception("Wystąpił błąd podczas tworzenie katalogu dla rekordu '{$primaryKey}'");
  1411. }
  1412. $generateSafeFileName = function($destPath, $fileName) {
  1413. if (!file_exists("{$destPath}/{$fileName}")) return $fileName;
  1414. $infoPath = pathinfo($fileName);
  1415. // pathinfo('/path/t1/t2/fileName.ext') = [
  1416. // [dirname] => /path/t1/t2
  1417. // [basename] => fileName.ext
  1418. // [extension] => ext
  1419. // [filename] => fileName
  1420. // ]
  1421. return $infoPath['filename'] . "--" . date("Y-m-d_H-i-s") . "." . $infoPath['extension'];
  1422. };
  1423. $moveActions = array_map(function ($file) use ($destPath, $generateSafeFileName) {
  1424. $safeName = $generateSafeFileName($destPath, $file['name']);
  1425. return [
  1426. $file['tmp_name'],
  1427. "{$destPath}/{$safeName}",
  1428. $safeName,
  1429. ];
  1430. }, $_FILES);
  1431. DBG::log($moveActions, 'array', "\$moveActions"); // [ [ srcPath, descPath ] ]
  1432. $errorMsgs = [];
  1433. $pkField = $acl->getSqlPrimaryKeyField();
  1434. foreach ($moveActions as $fileMoveAction) {
  1435. if (!move_uploaded_file($fileMoveAction[0], $fileMoveAction[1])) {
  1436. $errorMsgs[] = "Nie udało się wgrać pliku '{$fileMoveAction[2]}'";
  1437. } else {
  1438. try {
  1439. $affected = DB::getPDO($acl->getDB())->update($rootTableName, $pkField, $primaryKey, [
  1440. 'M_DIST_FILES' => "Wrano plik '{$fileMoveAction[2]}'",
  1441. 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
  1442. 'A_RECORD_UPDATE_DATE' => 'NOW()',
  1443. ]);
  1444. if ($affected) {
  1445. DB::getPDO($acl->getDB())->insert("{$rootTableName}_HIST", [
  1446. 'ID_USERS2' => $primaryKey,
  1447. 'M_DIST_FILES' => "Wrano plik '{$fileMoveAction[2]}'",
  1448. 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
  1449. 'A_RECORD_UPDATE_DATE' => 'NOW()',
  1450. ]);
  1451. }
  1452. } catch (Exception $e) {
  1453. DBG::log($e);
  1454. $errorMsgs[] = $e->getMessage();
  1455. }
  1456. }
  1457. }
  1458. if (!empty($errorMsgs)) {
  1459. return [
  1460. 'type' => "error",
  1461. 'msg' => "Wystąpiły błędy podczas wgrywania plików dla '{$primaryKey}'",
  1462. 'errors' => $errorMsgs,
  1463. ];
  1464. }
  1465. return [
  1466. 'type' => "success",
  1467. 'msg' => "Wgrano nowe pliki dla '{$primaryKey}'",
  1468. ];
  1469. }
  1470. public function removeFileAjaxAction() {
  1471. Response::sendTryCatchJson([$this, 'removeFileAjax'], $args = $_REQUEST);
  1472. }
  1473. public function removeFileAjax($args) { // ajaxFileRemove
  1474. $namespace = V::get('namespace', '', $args, 'word');
  1475. if (!$namespace) throw new Exception("Missing namespace");
  1476. $id = V::get('ID', 0, $args, 'int');
  1477. if ($id <= 0) throw new Exception("Missing ID");
  1478. $filename = V::get('filename', '', $args);
  1479. if (empty($filename)) throw new Exception("Nie wybrano pliku do usunięcia");
  1480. $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
  1481. $dbID = $acl->getDB();
  1482. $db = DB::getPDO($dbID);
  1483. if (!$db) throw new HttpException("No DB ({$dbID})", 406);
  1484. $record = $acl->buildQuery([])->getItem($id);
  1485. if (!$record) throw new HttpException("No item ID({$id})", 404);
  1486. if (!$acl->canReadRecord($record)) throw new Exception("Brak uprawnień do odczytu");
  1487. if (!$acl->canWriteRecord($record)) throw new Exception("Brak uprawnień do zapisu");
  1488. Lib::loadClass('FileUploader');
  1489. Lib::loadClass('FoldersConfig');
  1490. $tblName = $acl->getName();
  1491. $confTblName = "{$tblName}_COLUMN";
  1492. $folderConfAll = FoldersConfig::getRawData();
  1493. if (!FoldersConfig::hasConfig($confTblName)) throw new HttpException("Brak danych konfiguracyjnych ({$tblName})", 404);
  1494. $folderConf = FoldersConfig::getAll($confTblName);
  1495. $uploader = new FileUploader($confTblName, (object)$record);
  1496. if (!$uploader->setConfig($folderConf)) throw new HttpException("Błąd danych konfiguracyjnych ({$tblName})", 404);
  1497. $uploader->findFolder();
  1498. $errorMsg = '';
  1499. $removed = $uploader->tryRemoveFromAjax($filename, $errorMsg);
  1500. if (!$removed) throw new Exception($errorMsg);
  1501. // $affected = DB::getPDO($acl->getDB())->update();
  1502. $rootTableName = $acl->getRootTableName();
  1503. $pkField = $acl->getSqlPrimaryKeyField();
  1504. $primaryKey = $id;
  1505. try {
  1506. $affected = DB::getPDO($acl->getDB())->update($rootTableName, $pkField, $primaryKey, [
  1507. 'M_DIST_FILES' => "Usunięto plik '{$filename}'",
  1508. 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
  1509. 'A_RECORD_UPDATE_DATE' => 'NOW()',
  1510. ]);
  1511. if ($affected) {
  1512. DB::getPDO($acl->getDB())->insert("{$rootTableName}_HIST", [
  1513. 'ID_USERS2' => $primaryKey,
  1514. 'M_DIST_FILES' => "Usunięto plik '{$filename}'",
  1515. 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
  1516. 'A_RECORD_UPDATE_DATE' => 'NOW()',
  1517. ]);
  1518. }
  1519. } catch (Exception $e) {
  1520. DBG::log($e);
  1521. }
  1522. return [
  1523. 'type' => 'success',
  1524. 'msg' => 'Plik został usunięty',
  1525. ];
  1526. }
  1527. public function procesInitFiltrAjaxAction() {
  1528. Response::sendTryCatchJson([$this, 'procesInitFiltrAjax'], $args = $_GET);
  1529. }
  1530. public function procesInitFiltrAjax($args) { // ajaxFileRemove
  1531. $namespace = V::get('namespace', '', $args, 'word');
  1532. if (!$namespace) throw new Exception("Missing namespace");
  1533. $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
  1534. $pInitList = User::getAcl()->getTableProcesInitList($acl->getID());
  1535. DBG::log($pInitList, 'array', "\$pInitList");
  1536. if (!empty($pInitList)) {
  1537. $procesIds = array_keys($pInitList);
  1538. $mapTree = ACL::getProcesInitMapTreeOnlyIds($procesIds);
  1539. DBG::log($mapTree, 'array', "\$mapTree");
  1540. DBG::log($pInitList, 'array', "\$pInitList");
  1541. $pInitListSelected = User::getAcl()->getPermsFiltrProcesId();
  1542. return [
  1543. 'type' => 'success',
  1544. 'msg' => 'ok',
  1545. 'pInitData' => [
  1546. 'pInitList' => $pInitList,
  1547. 'mapTree' => $mapTree,
  1548. 'pInitListSelected' => $pInitListSelected,
  1549. ],
  1550. ];
  1551. }
  1552. return [
  1553. 'type' => 'success'
  1554. ];
  1555. }
  1556. public function tableToolsAjaxAction() {
  1557. Response::sendTryCatchJson([$this, 'tableToolsAjax'], $args = $_GET);
  1558. }
  1559. public function tableToolsAjax($args) { // ajaxFileRemove
  1560. $namespace = V::get('namespace', '', $args, 'word');
  1561. if (!$namespace) throw new Exception("Missing namespace");
  1562. $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
  1563. $listUrlFunctions = Route_UrlAction::getTableFunctions($acl->getID(), $idRecord = 0, $acl->getName(), User::getLogin());
  1564. DBG::log($listUrlFunctions, 'array', "\$listUrlFunctions");
  1565. $listUrlFunctions = array_map(function ($urlFunction) use ($namespace) {
  1566. if ('index.php?' === substr($urlFunction['baseLink'], 0, strlen('index.php?'))) $urlFunction['baseLink'] .= "&_fromNamespace={$namespace}";
  1567. return $urlFunction;
  1568. }, $listUrlFunctions);
  1569. return [
  1570. 'type' => "success",
  1571. 'msg' => 'ok',
  1572. 'body' => [
  1573. 'tableTools' => array_values(array_map(function ($urlFunction) {
  1574. return [
  1575. 'url' => $urlFunction['baseLink'],
  1576. 'label' => $urlFunction['label'],
  1577. // TODO: $urlFunction['link_target'] // "_blank"
  1578. // ? $urlFunction['name']
  1579. ];
  1580. }, array_filter($listUrlFunctions, function ($urlFunction) {
  1581. return empty($urlFunction['cell_id_params']);
  1582. }))),
  1583. ],
  1584. ];
  1585. }
  1586. function executeRowFunctionAction() { UI::layout([ $this, 'executeRowFunction' ]); }
  1587. function executeRowFunction() {
  1588. $namespace = V::get('namespace', '', $_GET);
  1589. $name = V::get('name', '', $_GET);
  1590. $pk = V::get('pk', '', $_GET);
  1591. if (!$namespace) throw new Exception("Missing namespace");
  1592. if (!$name) throw new Exception("Missing name");
  1593. if (!$pk) throw new Exception("Missing pk");
  1594. $acl = ACL::getAclByNamespace($namespace);
  1595. if (!method_exists($acl, 'executeGuiRowFunction')) throw new Exception("Function executeGuiRowFunction not defined for '{$namespace}'");
  1596. $acl->executeGuiRowFunction($name, $pk);
  1597. }
  1598. }