ViewObject.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  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. Lib::loadClass('P5');
  15. Lib::loadClass('Route_ViewTableAjax');
  16. class Route_ViewObject extends Route_ViewTableAjax {
  17. public function getTableAjaxWidget($acl) {
  18. $syncUrl = Request::getPathUri() . 'index.php?_route=ViewObject&namespace=' . $acl->getNamespace();
  19. $tbl = new TableAjax($acl);
  20. $tbl->showProcesInit(false); // TODO: activate when ready
  21. $tblLabel = $acl->getNamespace();
  22. if ('default_db' == $acl->getSourceName()) {
  23. $tblLabel = array();
  24. DBG::nicePrint($acl->getID(), '$acl->getID()');
  25. $zasobObj = ProcesHelper::getZasobTableInfo($acl->getID());
  26. DBG::nicePrint($zasobObj, '$zasobObj');
  27. $sqlId = $acl->getID();
  28. if (!$sqlId) throw new Exception("Missing zasob id!");
  29. $zasobItem = DB::getPDO()->fetchFirst("
  30. select z.ID, z.`DESC`, z.DESC_PL, z.OPIS
  31. from CRM_LISTA_ZASOBOW z
  32. where z.ID = {$sqlId}
  33. and z.`TYPE` = 'TABELA'
  34. ");
  35. DBG::nicePrint($zasobItem, '$zasobItem');
  36. // if (!$zasobObj) throw new Exception("Zasob TABELA ID=" . $acl->getID() . " nie istnieje");
  37. // if (!empty($zasobObj->DESC_PL)) $tblLabel []= $zasobObj->DESC_PL;
  38. // if (!empty($zasobObj->OPIS)) $tblLabel []= $zasobObj->OPIS;
  39. if (!$zasobItem) throw new Exception("Zasob TABELA ID=" . $acl->getID() . " nie istnieje");
  40. if (!empty($zasobItem['DESC_PL'])) $tblLabel []= $zasobItem['DESC_PL'];
  41. if (!empty($zasobItem['OPIS'])) $tblLabel []= $zasobItem['OPIS'];
  42. $tblLabel = implode(" - ", $tblLabel);
  43. }
  44. $tbl->setSyncUrl($syncUrl);
  45. $tbl->setLabel($tblLabel);
  46. $tbl->addRowFunction('edit');
  47. $tbl->addRowFunction('hist');
  48. $tbl->addRowFunction('files');
  49. $tbl->addRowFunction('cp');
  50. $tbl->addRowFunction('msgs');
  51. return $tbl;
  52. }
  53. public function defaultAction() {
  54. UI::gora();
  55. UI::menu();
  56. try {
  57. $namespace = V::get('namespace', '', $_GET, 'word');
  58. if (!$namespace) {
  59. $typeName = V::get('typeName', '', $_GET, 'word');
  60. if (!$typeName) throw new Exception("Wrong param typeName");
  61. $namespace = Api_WfsNs::getBaseWfsUri() . '/' . str_replace(':', '/', $typeName);
  62. }
  63. $acl = P5::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
  64. $forceFilterInit = array();
  65. $filterInit = new stdClass();
  66. $filterInit->currSortCol = $acl->getPrimaryKeyField();
  67. $filterInit->currSortFlip = 'desc';
  68. foreach ($_GET as $k => $v) {
  69. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && !empty($v)) {// filter prefix
  70. $filterInit->$k = $v;
  71. }
  72. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && !empty($v)) {// special filter prefix
  73. $filterInit->$k = $v;
  74. }
  75. else if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
  76. $fldName = substr($k, 3);
  77. $forceFilterInit[$fldName] = $v;
  78. }
  79. }
  80. $tbl = $this->getTableAjaxWidget($acl);
  81. $tbl->setFilterInit($filterInit);
  82. if (!empty($forceFilterInit)) $tbl->setForceFilterInit($forceFilterInit);
  83. echo $tbl->render();
  84. if (DBG::isActive() && V::get('DBG_ACL', '', $_GET)) {// test load perms
  85. Lib::loadClass('DebugExecutionTime');
  86. $dbgExecTime = new DebugExecutionTime();
  87. $dbgExecTime->activate();
  88. $dbgExecTime->log('start');
  89. UI::startContainer(['style'=>'border:1px solid red']);
  90. UI::tag('p', null, "TEST - load perms from db");
  91. $idTable = $acl->getID();
  92. UI::tag('p', null, "DBG idTable({$idTable})");
  93. if ($idTable > 0) {
  94. $dbgExecTime->log('before sql');
  95. $aclTableRows = DB::getPDO()->fetchAll("select * from `CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW` where ID_TABLE = {$idTable}");
  96. $dbgExecTime->log('after sql', ['sql']);
  97. UI::table(['caption' => "from CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW", 'rows' => $aclTableRows]);
  98. $csvIdProces = array();
  99. foreach ($aclTableRows as $row) {
  100. if (!in_array($row['ID_PROCES'], $csvIdProces)) $csvIdProces[] = $row['ID_PROCES'];
  101. }
  102. }
  103. $tableName = $acl->getName();
  104. $databaseName = DB::getPDO()->getDatabaseName();
  105. UI::table([
  106. 'caption' => "Cell to process",
  107. 'rows' => array_map(
  108. function ($row) use ($aclTableRows, $idTable) {
  109. $row['proces'] = array();
  110. $row['id_zasob'] = 0;
  111. $row['PERM_R'] = 0;
  112. $row['PERM_W'] = 0;
  113. $row['PERM_X'] = 0;
  114. $row['PERM_C'] = 0;
  115. $row['PERM_S'] = 0;
  116. $row['PERM_O'] = 0;
  117. $row['PERM_V'] = 0;
  118. $row['PERM_E'] = 0;
  119. foreach ($aclTableRows as $aclInfo) {
  120. if (strtolower($aclInfo['CELL_NAME']) == strtolower($row['COLUMN_NAME'])) {
  121. $row['proces'][] = $aclInfo['ID_PROCES'];
  122. $row['id_zasob'] = $aclInfo['ID_CELL'];
  123. $row['PERM_R'] += $aclInfo['PERM_R'];
  124. $row['PERM_W'] += $aclInfo['PERM_W'];
  125. $row['PERM_X'] += $aclInfo['PERM_X'];
  126. $row['PERM_C'] += $aclInfo['PERM_C'];
  127. $row['PERM_S'] += $aclInfo['PERM_S'];
  128. $row['PERM_O'] += $aclInfo['PERM_O'];
  129. $row['PERM_V'] += $aclInfo['PERM_V'];
  130. $row['PERM_E'] += $aclInfo['PERM_E'];
  131. }
  132. }
  133. $row['proces'] = (empty($row['proces']))
  134. ? "<i style=\"color:red\">Brak</i>"
  135. : implode(", ", $row['proces']);
  136. 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");
  137. return $row;
  138. }, DB::getPDO()->fetchAll("
  139. select t.TABLE_NAME, t.COLUMN_NAME, t.DATA_TYPE, t.COLUMN_TYPE
  140. from `information_schema`.`COLUMNS` t
  141. where t.TABLE_SCHEMA = '{$databaseName}'
  142. and t.TABLE_NAME like '{$tableName}'
  143. ")
  144. )
  145. ]);
  146. if (!empty($csvIdProces)) {
  147. $csvIdProces = implode(",", $csvIdProces);
  148. UI::tag('p', null, "DBG csvIdProces({$csvIdProces})");
  149. $userLogin = User::getLogin();
  150. $dbgExecTime->log('before sql');
  151. $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");
  152. $dbgExecTime->log('after sql', ['sql']);
  153. UI::table(['caption' => "from CRM_PROCES_idx_USER_to_PROCES_VIEW", 'rows' => $rows]);
  154. $userIdProces = array(); foreach ($rows as $row) $userIdProces[] = $row['ID_PROCES'];
  155. $userTablePerms = array();
  156. foreach ($aclTableRows as $row) {
  157. if (!in_array($row['ID_PROCES'], $userIdProces)) continue;
  158. if (array_key_exists($row['CELL_NAME'], $userTablePerms)) {
  159. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_R' ] += $row['PERM_R'];
  160. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_W' ] += $row['PERM_W'];
  161. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_X' ] += $row['PERM_X'];
  162. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_C' ] += $row['PERM_C'];
  163. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_S' ] += $row['PERM_S'];
  164. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_O' ] += $row['PERM_O'];
  165. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_V' ] += $row['PERM_V'];
  166. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_E' ] += $row['PERM_E'];
  167. } else {
  168. $userTablePerms[ $row['CELL_NAME'] ] = $row;
  169. unset($userTablePerms[ $row['CELL_NAME'] ][ 'TABLE_DESCRIPTION' ]);
  170. unset($userTablePerms[ $row['CELL_NAME'] ][ 'ID_PROCES' ]);
  171. unset($userTablePerms[ $row['CELL_NAME'] ][ 'FORM_TREAT' ]);
  172. }
  173. }
  174. UI::table(['caption' => "\$userTablePerms", 'rows' => $userTablePerms]);
  175. } else UI::alert('warning', "brak \$csvIdProces");
  176. $dbgExecTime->printDebug();
  177. UI::endContainer();
  178. }
  179. } catch (Exception $e) {
  180. UI::startContainer();
  181. UI::alert('danger', "<strong>Wystąpiły błędy!</strong> " . $e->getMessage());
  182. UI::endContainer();
  183. DBG::log($e);
  184. }
  185. UI::dol();
  186. }
  187. public function rmUserTableFilterAjaxAction() {
  188. Response::sendTryCatchJson(array($this, 'rmUserTableFilterAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  189. }
  190. public function rmUserTableFilterAjax($args) {
  191. $namespace = V::get('namespace', '', $args);
  192. $filtrName = V::get('filtrName', '', $args);
  193. if (!$namespace) throw new Exception("Missing namespace");
  194. if (!$filtrName) throw new Exception("Missing filtrName");
  195. $userFltrConfKey = "tableColFilters__" . User::getLogin();
  196. $currentFilters = DB::getPDO()->fetchValue(" select CONF_VAL from CRM_CONFIG where CONF_KEY = '{$userFltrConfKey}' ");
  197. if (!$currentFilters) return [
  198. 'type' => 'warning',
  199. 'msg' => "Brak filtrów w bazie",
  200. ];
  201. $currentFilters = json_decode($currentFilters, 'assoc');
  202. unset($currentFilters[$namespace][$filtrName]);
  203. $affeced = DB::getPDO()->update('CRM_CONFIG', 'CONF_KEY', $userFltrConfKey, [
  204. 'CONF_VAL' => json_encode($currentFilters)
  205. ]);
  206. return [
  207. 'type' => 'success',
  208. 'msg' => 'Zapisano nowy filtr',
  209. 'data' => $currentFilters[$namespace]
  210. ];
  211. }
  212. public function addUserTableFilterAjaxAction() {
  213. Response::sendTryCatchJson(array($this, 'addUserTableFilterAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  214. }
  215. public function addUserTableFilterAjax($args) {
  216. $namespace = V::get('namespace', '', $args);
  217. $filtrName = V::get('filtrName', '', $args);
  218. $visibleCols = V::get('visibleCols', '', $args);
  219. if (!$namespace) throw new Exception("Missing namespace");
  220. if (!$filtrName) throw new Exception("Missing filtrName");
  221. if (!$visibleCols) throw new Exception("Missing visibleCols");
  222. $userFltrConfKey = "tableColFilters__" . User::getLogin();
  223. $currentFilters = DB::getPDO()->fetchValue(" select CONF_VAL from CRM_CONFIG where CONF_KEY = '{$userFltrConfKey}' ");
  224. $currentFilters = ($currentFilters) ? json_decode($currentFilters, 'assoc') : [];
  225. $currentFilters[$namespace][$filtrName] = $visibleCols;
  226. $sqlFltr = json_encode($currentFilters);
  227. DB::getPDO()->execSql("
  228. insert into CRM_CONFIG (CONF_KEY, CONF_VAL)
  229. values ('$userFltrConfKey', '{$sqlFltr}')
  230. on duplicate key update CONF_VAL = '{$sqlFltr}'
  231. ");
  232. return [
  233. 'type' => 'success',
  234. 'msg' => 'Zapisano nowy filtr',
  235. 'data' => $currentFilters[$namespace]
  236. ];
  237. }
  238. public function getUserTableFilterAjaxAction() {
  239. Response::sendTryCatchJson(array($this, 'getUserTableFilterAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  240. }
  241. public function getUserTableFilterAjax($args) {
  242. $namespace = V::get('namespace', '', $args);
  243. if (!$namespace) throw new Exception("Missing namespace");
  244. $userFltrConfKey = "tableColFilters__" . User::getLogin();
  245. $currentFilters = DB::getPDO()->fetchValue(" select CONF_VAL from CRM_CONFIG where CONF_KEY = '{$userFltrConfKey}' ");
  246. $currentFilters = ($currentFilters) ? json_decode($currentFilters, 'assoc') : [];
  247. return [
  248. 'type' => 'success',
  249. 'msg' => 'Odczytano filtry użytkownika',
  250. 'data' => (!empty($currentFilters[$namespace])) ? $currentFilters[$namespace] : []
  251. ];
  252. }
  253. public function revertFromHistAjaxAction() {
  254. Response::sendTryCatchJson(array($this, 'revertFromHistAjax'));
  255. }
  256. public function revertFromHistAjax() {
  257. $typeName = V::get('typeName', '', $_REQUEST, 'word');
  258. if (!$typeName) throw new Exception("Wrong param typeName");
  259. // TODO: use namespace from url
  260. // $namespace = V::get('namespace', '', $_GET, 'word');
  261. // if (!$namespace) {
  262. // $typeName = V::get('typeName', '', $_GET, 'word');
  263. // if (!$typeName) throw new Exception("Wrong param typeName");
  264. // $namespace = Api_WfsNs::getBaseWfsUri() . '/' . str_replace(':', '/', $typeName);
  265. // }
  266. // $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
  267. $id = V::get('ID', '', $_REQUEST, 'word');
  268. if (!$id) throw new Exception("Wrong param ID");
  269. $idHist = V::get('idHist', '', $_REQUEST, 'word');
  270. if (!$idHist) throw new Exception("Wrong param idHist");
  271. $fieldName = V::get('fieldName', '', $_REQUEST, 'word');
  272. if (!$fieldName) throw new Exception("Wrong param fieldName");
  273. $acl = Core_AclHelper::getAclByTypeName($typeName);
  274. $item = $acl->getItem($id);
  275. if (!$item) throw new HttpException("Item not found", 404);
  276. if (!$acl->canWriteObjectField($fieldName, $record)) throw new Exception("Missing perm Write for field {$fieldName}");
  277. $histItem = $acl->getHistItem($id, $idHist);
  278. if (!$histItem) throw new HttpException("Hist Item not found", 404);
  279. $histValue = V::get($fieldName, 'N/S;', $histItem);
  280. if ('N/S;' == $histValue) throw new Exception("Missing field value in hist[{$idHist}] for field({$fieldName}) from item[{$id}]");
  281. if ($acl->isGeomField($fieldName)) {
  282. $wktType = strtoupper($acl->getGeomFieldType($fieldName));
  283. if (!$wktType) throw new Exception("Wrong geometry type for field {$fieldName}");
  284. if ($wktType != strtoupper(substr($histValue, 0, strlen($wktType)))) throw new Exception("Wrong geometry type for field {$fieldName} in hist value");
  285. $coords = trim(substr($histValue, strlen($wktType)), '()');
  286. $wktValue = $acl->convertGmlCoordsToWkt($wktType, $coords, ['cs'=>' ', 'ts'=>',']);
  287. if (!$wktValue) throw new Exception("BUG in hist record");
  288. $sqlObj = array();
  289. $sqlObj['ID'] = $id;
  290. $sqlObj[$fieldName] = "GeomFromText('{$wktValue}')";
  291. $affected = DB::getDB()->UPDATE_OBJ($acl->getName(), (object)$sqlObj);
  292. if (0 == $affected) throw new AlertInfoException("Nie wprowadzono żadnych zmian");
  293. else if ($affected < 0) throw new Exception("Wystąpiły błędy podczas aktualizacji rekordu [{$id}]");
  294. $jsonResponse = array();
  295. $jsonResponse['type'] = 'success';
  296. $jsonResponse['msg'] = "Zaktualizowano dane na podstawie wcześniejszej wartości dla rekordu [{$id}]";
  297. $jsonResponse['actions'] = array();
  298. $jsonResponse['actions'][] = ['jsFunction'=>'TableAjax__HIST_Route', 'args'=>[$id]];
  299. return $jsonResponse;
  300. } else {
  301. throw new HttpException("Not implemented - update from hist only for the geom field", 501);
  302. }
  303. throw new Exception("BUG: update field '{$fieldName}' in item[{$id}] from hist[{$idHist}]", 501);
  304. }
  305. public function removeTheGeomAjaxAction() {
  306. Response::sendTryCatchJson(array($this, 'removeTheGeomAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  307. }
  308. public function removeTheGeomAjax($args) {
  309. $namespace = V::get('namespace', '', $args, 'word');
  310. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  311. $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
  312. $primaryKeyField = $acl->getPrimaryKeyField();
  313. $primaryKey = V::get($primaryKeyField, 0, $args, 'int');
  314. $geomFieldName = 'the_geom';
  315. $response = new stdClass();
  316. if ($primaryKey <= 0) throw new HttpException("Bad Request - Wrong param ID", 400);
  317. $record = $acl->getItem($primaryKey);
  318. if (!$record) throw new HttpException("Nie odnaleziono rekordu nr {$primaryKey}", 404);
  319. if (!$acl->canWriteObjectField($geomFieldName, $record)) throw new HttpException("Brak dostępu do zapisu dla pola {$geomFieldName}", 403);
  320. if (empty($record->{$geomFieldName})) {
  321. $response->type = 'info';
  322. $response->msg = "Rekord nie jest powiązany z żadnym obiektem na mapie";
  323. $response->record = $record;
  324. return $response;
  325. }
  326. $itemPatch = array();
  327. $itemPatch[$geomFieldName] = "NULL";
  328. $itemPatch[$primaryKeyField] = $primaryKey;
  329. $response = new stdClass();
  330. try {
  331. $affected = $acl->updateItem($itemPatch);
  332. if ($affected > 0) {
  333. $response->type = 'success';
  334. $response->msg = "Usunięto obiekt z mapy dla rekordu {$primaryKey}";// Rekord zapisany pomyślnie
  335. } else if ($affected == 0) {
  336. $response->type = 'info';
  337. $response->msg = "Nie wprowadzono żadnych zmian";
  338. }
  339. $response->record = $acl->getItem($primaryKey);
  340. }
  341. catch (Exception $e) {
  342. $response->type = 'error';
  343. $response->msg = $e->getMessage();
  344. }
  345. return $response;
  346. }
  347. public function moreFunctionsCellAjaxAction() {
  348. Response::sendTryCatchJson(array($this, 'moreFunctionsCell'), $args = $_GET);
  349. }
  350. public function moreFunctionsCell($args) {// ajax task 'MORE_FUNCTIONS_CELL'
  351. $id = V::get('ID', 0, $args, 'int');
  352. if ($id <= 0) throw new HttpException("404", 404);
  353. $namespace = V::get('namespace', '', $args, 'word');
  354. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  355. $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $args)));
  356. $response = new stdClass();
  357. $response->type = 'success';
  358. $response->msg = 'Funkcje';
  359. $response->rowFunctions = Core_AclHelper::getMoreFunctionsCell($acl, array('primary_key' => $id));
  360. return $response;
  361. }
  362. public function editFormAction() {// namespace, _hash, _primaryKey
  363. $args = $_REQUEST;
  364. $id = V::get('_primaryKey', 0, $args, 'int');
  365. if ($id <= 0) throw new HttpException("Bad Request - missing primaryKey", 400);
  366. $namespace = V::get('namespace', '', $args, 'word');
  367. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  368. $acl = Core_AclHelper::getAclByNamespace($namespace);
  369. $tbl = $this->getTableAjaxWidget($acl);
  370. $tbl->sendAjaxEdit($id, $args);
  371. }
  372. public function editSaveAjaxAction() {
  373. Response::sendTryCatchJson(array($this, 'editSaveAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  374. }
  375. public function editSaveAjax($args) {
  376. $namespace = V::get('namespace', '', $args, 'word');
  377. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  378. $acl = Core_AclHelper::getAclByNamespace($namespace);
  379. $primaryKeyField = $acl->getPrimaryKeyField();
  380. $primaryKey = V::get('primaryKey', 0, $args, 'int');
  381. if (empty($primaryKey)) throw new HttpException("Bad Request - missing primaryKey!", 400);
  382. $item = $acl->getItem($primaryKey);
  383. if (!$item) throw new HttpException("Item not exists!", 404);
  384. $itemFromUser = $acl->convertObjectFromUserInput($args['form'], $type = 'array_by_id', $prefix = 'f');
  385. $response = new stdClass();
  386. $response->primaryKey = $primaryKey;
  387. try {
  388. $itemFromUser[$primaryKeyField] = $primaryKey;
  389. $affected = $acl->updateItem($itemFromUser);
  390. if ($affected > 0) {
  391. $response->type = 'success';
  392. $response->msg = "Rekord zapisany pomyślnie";//"Record saved successfully";
  393. } else if ($affected == 0) {
  394. $response->type = 'info';
  395. $response->msg = "Nie wprowadzono żadnych zmian";
  396. }
  397. $response->record = $acl->getItem($primaryKey);
  398. $rowFunList = Core_AclHelper::getMoreFunctionsCell($acl, array('primary_key'=>$primaryKey, 'record'=>$response->record));
  399. if (!empty($rowFunList)) $response->rowFunctions = $rowFunList;
  400. }
  401. catch (Exception $e) {
  402. $response->type = 'error';
  403. $response->msg = "Wystąpiły błędy!";
  404. $response->msg .= $e->getMessage();
  405. }
  406. return $response;
  407. }
  408. public function typeSpecialCellAction() {
  409. Response::sendTryCatchJson(array($this, 'typeSpecialCell'), $args = $_REQUEST);
  410. }
  411. public function typeSpecialCell($args) {
  412. $namespace = V::get('namespace', '', $args, 'word');
  413. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  414. $acl = Core_AclHelper::getAclByNamespace($namespace);
  415. $id = V::get('ID', 0, $args, 'int');
  416. $fieldName = V::get('col', '', $args);
  417. if ($id <= 0 || empty($fieldName)) throw new HttpException("Bad Request - missing id or col", 400);
  418. $col = $fieldName;// TODO: RM $col
  419. $jsonData = new stdClass();
  420. $idField = $acl->getFieldIdByName($fieldName);
  421. if (!$idField) throw new Exception("Wrong field");
  422. $item = $acl->getItem($id);
  423. if (!$acl->canReadObjectField($fieldName, $item)) throw new Exception("Brak dostępu");
  424. $typeSpecial = Typespecial::getInstance($idField, $fieldName);
  425. if ($typeSpecial) {
  426. $jsonData->data = $typeSpecial->getReturnData($acl->getID(), $id, $fieldName, '');
  427. $jsonData->namespace = 'default_db/' . V::get('tbl_name', '', $jsonData->data);
  428. }
  429. return $jsonData;
  430. }
  431. /**
  432. * @param $_GET['namespace'] = AclNamespace
  433. * @param $_GET['format'] = 'csv' | 'html'
  434. * @param $_GET['flds'] = csv - coma separated field names
  435. * @param $_GET['sortCol'] = FieldName
  436. * @param $_GET['sortDir'] = SortDir ('desc' | 'asc')
  437. * @param $_GET['f_{$fieldName}'] = filter
  438. * @param $_GET['sf_{$fieldName}'] = force filter
  439. */
  440. public function exportAction() {
  441. $args = $_GET;
  442. $namespace = V::get('namespace', '', $args, 'word');
  443. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  444. $acl = Core_AclHelper::getAclByNamespace($namespace);
  445. $exportLimit = 10000;
  446. $params = array();
  447. $params['limit'] = $exportLimit;
  448. // $params['limitstart'] = 0;
  449. $params['order_by'] = V::get('sortCol', '', $args);
  450. $params['order_dir'] = V::get('sortDir', '', $args);
  451. $params['cols'] = array($acl->getPrimaryKeyField());
  452. $toExportFields = explode(',', V::get('flds', '', $_GET));
  453. if (empty($toExportFields)) throw new Exception("Nie wybrano żandych pól do exportu.");
  454. $allowedExportFieldList = Core_AclHelper::getExportFieldList($acl);
  455. foreach ($toExportFields as $fieldName) {
  456. if ($fieldName == $acl->getPrimaryKeyField()) continue;
  457. if (!in_array($fieldName, $allowedExportFieldList)) throw new Exception("Brak uprawnień do exportu pola '{$fieldName}'");
  458. $params['cols'][] = $fieldName;
  459. }
  460. $labels = array();
  461. foreach ($toExportFields as $fieldName) {
  462. $labels[ $fieldName ] = $acl->getFieldLabel($fieldName);
  463. }
  464. foreach ($args as $k => $v) {
  465. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && strlen($v) > 0) {// filter prefix
  466. $params[$k] = $v;
  467. }
  468. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && strlen($v) > 0) {// special filter prefix
  469. $params[$k] = $v;
  470. }
  471. }
  472. $total = $acl->getTotal($params);
  473. // if ($total > $exportLimit) $params['limit'] = $exportLimit;
  474. $items = $acl->getItems($params);
  475. $format = V::get('format', 'html', $_GET);
  476. if ('html' == $format) {
  477. UI::gora();
  478. UI::startTag('table', ['class'=>'table table-bordered table-hover']);
  479. UI::startTag('thead');
  480. UI::startTag('tr');
  481. foreach ($labels as $fldName => $label) {
  482. UI::tag('th', [], $label);
  483. }
  484. UI::endTag('tr');
  485. UI::endTag('thead');
  486. UI::startTag('tbody');
  487. foreach ($items as $item) :
  488. UI::startTag('tr');
  489. foreach ($labels as $fldName => $label) :
  490. UI::tag('td', [], $item->{$fldName});
  491. endforeach;
  492. UI::endTag('tr');
  493. endforeach;
  494. UI::endTag('tbody');
  495. UI::endTag('table');
  496. UI::dol();
  497. }
  498. else if ('csv' == $format) {
  499. $csvFileName = "Tabela-" . $acl->getName() . "-" . date("Y-m-d_H_s");
  500. header('Content-Type: text/csv; charset=utf-8');
  501. header("Content-Disposition: attachment; filename={$csvFileName}.csv");
  502. $csvSeparator = ';';
  503. $labelsLine = array();
  504. foreach ($labels as $fldName => $label) {
  505. $labelsLine[] = '"' . addslashes($label) . '"';
  506. }
  507. echo implode($csvSeparator, $labelsLine) . "\n";
  508. foreach ($items as $item) {
  509. $itemLine = array();
  510. foreach ($labels as $fldName => $label) {
  511. $itemLine[] = '"' . addslashes($item->{$fldName}) . '"';
  512. }
  513. echo implode($csvSeparator, $itemLine) . "\n";
  514. }
  515. }
  516. else {
  517. die("Nieobsługiwany format danych.");
  518. }
  519. }
  520. public function loadDataAjaxAction() {
  521. // $tbl = $this->getTableAjaxWidget($acl);
  522. Response::sendTryCatchJson(array($this, 'loadDataAjax'), $args = $_GET);
  523. }
  524. public function loadDataAjax($args) {
  525. $namespace = V::get('namespace', '', $args, 'word');
  526. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  527. $acl = P5::getAclByNamespace($namespace);
  528. $uiConf = [
  529. 'pageSize' => 10
  530. ];
  531. $DBG = ('1' == V::get('DBG', '', $args));
  532. $pageSize = V::get('pageSize', $uiConf['pageSize'], $args, 'int');
  533. $page = V::get('page', 0, $args, 'int');
  534. $currSortCol = V::get('currSortCol', '', $args);
  535. $currSortFlip = V::get('currSortFlip', '', $args);
  536. if ($page > 0) {
  537. $page -= 1;
  538. }
  539. $params = array();
  540. $params['limit'] = $pageSize;
  541. $params['limitstart'] = $page * $params['limit'];
  542. $params['order_by'] = ($currSortCol)? $currSortCol : '';
  543. $params['order_dir'] = $currSortFlip;
  544. $filters = new stdClass();
  545. $filters->currSortCol = $currSortCol;
  546. $filters->currSortFlip = $currSortFlip;
  547. foreach ($args as $k => $v) {
  548. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && strlen($v) > 0) {// filter prefix
  549. $params[$k] = $v;
  550. $filters->{$k} = $v;
  551. }
  552. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && strlen($v) > 0) {// special filter prefix
  553. $params[$k] = $v;
  554. $filters->{$k} = $v;
  555. }
  556. }
  557. // TODO: $this->setFilters($filters);
  558. $vCols = $acl->getVirtualFieldListByIdZasob();
  559. if (!empty($vCols)) {
  560. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">vCols (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($vCols);echo'</pre>';}
  561. }
  562. $visibleCols = $acl->getVisibleFieldListByIdZasob();
  563. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">visibleCols (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($visibleCols);echo'</pre>';}
  564. $jsonData = new stdClass();
  565. $jsonData->page = $page + 1;
  566. $jsonData->pageSize = $pageSize;
  567. $jsonData->filters = $filters;
  568. $jsonData->cols = new stdClass();
  569. $jsonData->uniqueCol = $acl->getPrimaryKeyField();
  570. $ind = 0;
  571. foreach ($visibleCols as $fieldID => $col) {
  572. $ind++;
  573. $columnConfig = (object)array('index'=>$ind);
  574. if (in_array($col, array('A_STATUS','A_STATUS_CURRENT','A_SERVICES_STATUS_CURRENT'))) {
  575. $columnConfig->format = '<div class="cell-A_STATUS-{0}">{0}</div>';
  576. }
  577. else if (in_array($col, array('Status'))) {
  578. // Ahmes problems Status colors
  579. $columnConfig->format = '<div class="cell-Status-{0}">{0}</div>';
  580. }
  581. else if ($acl->isGeomField($col)) {
  582. $columnConfig->type = 'geom';
  583. }
  584. if ('' !== ($label = $acl->getFieldLabel($col))) {
  585. $columnConfig->friendly = $label;
  586. }
  587. $colType = $acl->getFieldType($col);
  588. if ($colType) {// @see MarkTableAjaxFilterColType
  589. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">field('.$col.') $colType (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($colType);echo'</pre>';}
  590. if ($colType['type'] == 'date') {
  591. //$columnConfig->type = 'date';// TODO: require datetimepicker
  592. }
  593. if (!empty($colType['simpleType'])) $columnConfig->type = $colType['simpleType'];
  594. } else {// typespecial - no type
  595. $columnConfig->type = 'special';
  596. }
  597. $columnConfig->xsdType = $acl->getXsdFieldType($col);
  598. if ($columnConfig->xsdType) {
  599. $ex = explode(":", $columnConfig->xsdType);
  600. switch ($ex[0]) {
  601. case 'ref':
  602. case 'alias_ref':
  603. if (3 != count($ex)) throw new HttpException("Schema Error for field({$col}) xsdType({$columnConfig->xsdType})", 500);
  604. $columnConfig->type = 'ref';
  605. $columnConfig->xsdRefUri = Api_WfsNs::getNsUri($ex[1]);
  606. $columnConfig->xsdRefType = $ex[2];
  607. $columnConfig->xsdRefNsPrefix = $ex[1];
  608. break;
  609. case 'xsd':
  610. switch ($ex[1]) {
  611. case 'string': $columnConfig->type = 'string'; break;
  612. case 'ind': $columnConfig->type = 'number'; break;// TODO: bug 'ind'?
  613. }
  614. break;
  615. case 'p5':
  616. switch ($ex[1]) {
  617. case 'alias': {
  618. $format = $acl->getXsdFieldParam($col, 'format');
  619. if ($format) $columnConfig->format = $format;
  620. } break;
  621. case 'string': {
  622. $columnConfig->type = 'p5:string';
  623. $columnConfig->formatByValue = $acl->getXsdFieldParam($col, 'formatByValue');
  624. } break;
  625. }
  626. break;
  627. }
  628. }
  629. $typeSpecial = Typespecial::getInstance($fieldID, $col);
  630. if ($typeSpecial) {
  631. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">typeSpecial (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'</pre>';}
  632. $columnConfig->_tsRetId = $typeSpecial->getReturnId();
  633. if ($columnConfig->_tsRetId == 0) {
  634. $tsParamOut = V::get('param_out', null, $typeSpecial);
  635. if ($tsParamOut) {
  636. $tsFormat = V::get('format', null, $tsParamOut);
  637. $tsValues = V::get('values', null, $tsParamOut);
  638. $tsAliases = V::get('alias', null, $tsParamOut);
  639. if (false !== strpos($tsFormat, '<a') && !empty($tsValues) && !empty($tsAliases)) {
  640. $tsAliasMap = array();
  641. /* [values] => Array([ID] => 1467), [alias] => Array([1467] => ID) */
  642. $bugTsColsNotVisible = array();
  643. foreach ($tsValues as $kVarName => $vIdZasob) {
  644. if (array_key_exists($vIdZasob, $tsAliases)) {
  645. $tsAliasMap[$kVarName] = $tsAliases[$vIdZasob];
  646. } else {
  647. $bugTsColsNotVisible[] = "noAliasFor {$vIdZasob}";
  648. }
  649. if (!array_key_exists($vIdZasob, $visibleCols)) {
  650. $bugTsColsNotVisible[] = $vIdZasob;
  651. }
  652. }
  653. if (empty($bugTsColsNotVisible)) {
  654. $tsSimpleLink = new stdClass();
  655. $tsSimpleLink->format = $tsFormat;
  656. $tsSimpleLink->aliasMap = $tsAliasMap;
  657. $columnConfig->_tsSimpleLink = $tsSimpleLink;
  658. $columnConfig->type = 'simpleLink';
  659. } else {
  660. $columnConfig->_tsSimpleLinkBug = $bugTsColsNotVisible;
  661. }
  662. }
  663. }
  664. }
  665. }
  666. if ($columnConfig->xsdType) {// fix fields type p5:typeSpecialSimpleLink (previously defined by Typespecial)
  667. switch ($columnConfig->xsdType) {
  668. case 'p5:typeSpecialSimpleLink': {
  669. $columnConfig->type = 'simpleLink';
  670. $columnConfig->_tsRetId = 0;
  671. $columnConfig->_tsSimpleLink = new stdClass();
  672. $columnConfig->_tsSimpleLink->format = $acl->getXsdFieldParam($col, 'format');
  673. $columnConfig->_tsSimpleLink->aliasMap = $acl->getXsdFieldParam($col, 'aliasMap');
  674. } break;
  675. }
  676. }
  677. // @see ajaxHiddenColsSave
  678. if (UserProfile::isHiddenColumn($acl->getID(), $fieldID)) {
  679. $columnConfig->hidden = true;
  680. }
  681. $columnConfig->description = $acl->getFieldOpis($col);
  682. $jsonData->cols->{$col} = $columnConfig;
  683. }
  684. $jsonData->rows = array();
  685. $jsonData->total = $acl->getTotal($params);
  686. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">get_total (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($jsonData->total);echo'</pre>';}
  687. $items = $acl->getItems($params);
  688. foreach ($items as $idx => $item) $items[$idx] = (array)$item;
  689. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">items (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($items);echo'</pre>';}
  690. // TODO: add virtual data by Typespecial
  691. if (!empty($vCols) && !empty($items)) {
  692. foreach ($vCols as $vColID => $vCol) {
  693. $colType = $acl->getFieldTypeById($vColID);
  694. if ($colType) continue;// pomin Typespecial dla realnych komorek w bazie danych
  695. $typeSpecial = Typespecial::getInstance($vColID, $vCol);
  696. if ($typeSpecial) {
  697. $columnConfig = V::get($vCol, null, $jsonData->cols);
  698. if ($columnConfig && !empty($columnConfig->_tsSimpleLink)) {
  699. // pomin simple link values - mved to js render
  700. } else {
  701. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$vColID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'</pre>';}
  702. $ids = array_keys($items);
  703. $specialValues = $typeSpecial->getValuesByIds($this->_zasobID, $ids);
  704. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$vCol.') specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValues);echo'</pre>';}
  705. if (!empty($specialValues)) foreach ($specialValues as $kItemID => $vValues) {
  706. $tsValue = implode('<br>', $vValues);
  707. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Item['.$kItemID.'].'.$vCol.' specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($items[$kItemID]);echo'</pre>';}
  708. if (!empty($items[$kItemID][$vCol]) && !empty($tsValue)) {
  709. $items[$kItemID][$vCol] .= ": {$tsValue}";
  710. } else {
  711. $items[$kItemID][$vCol] = $tsValue;
  712. }
  713. }
  714. }
  715. }
  716. }
  717. }
  718. {
  719. if(V::get('DBG', '', $_GET)){$jsonData->__DBG__ = [];}
  720. $p5Alias = [];
  721. foreach ((array)$jsonData->cols as $fieldName => $conf) {
  722. if ('p5:alias' == V::get('xsdType', '', $conf)) {
  723. if(V::get('DBG', '', $_GET)){$jsonData->__DBG__[$fieldName] = $conf;}
  724. $aliasType = $acl->getXsdFieldParam($fieldName, 'type');// 'type' => 'sql_table_alias',
  725. if ('sql_table_alias' == $aliasType) {
  726. $p5Alias[$fieldName] = (array)$conf;
  727. $p5Alias[$fieldName]['type'] = 'sql_table_alias';
  728. $p5Alias[$fieldName]['local_join_key'] = $acl->getXsdFieldParam($fieldName, 'local_join_key');// 'local_join_key' => 'ID',
  729. $p5Alias[$fieldName]['remote_table_name'] = $acl->getXsdFieldParam($fieldName, 'remote_table_name');// 'remote_table_name' => 'CRM_LISTA_ZASOBOW_ORDERS_summary_view',
  730. $p5Alias[$fieldName]['remote_join_key'] = $acl->getXsdFieldParam($fieldName, 'remote_join_key');// 'remote_join_key' => 'ID',
  731. $p5Alias[$fieldName]['remote_column_value'] = $acl->getXsdFieldParam($fieldName, 'remote_column_value');// 'remote_column_value' => 'SUM_POS',
  732. } else if ('sql_query_alias' == $aliasType) {
  733. $p5Alias[$fieldName] = (array)$conf;
  734. $p5Alias[$fieldName]['type'] = 'sql_query_alias';
  735. $p5Alias[$fieldName]['local_join_key'] = $acl->getXsdFieldParam($fieldName, 'local_join_key');
  736. $p5Alias[$fieldName]['join_query_format'] = $acl->getXsdFieldParam($fieldName, 'join_query_format');
  737. }
  738. }
  739. }
  740. if(V::get('DBG', '', $_GET)){$jsonData->__DBG__['$p5Alias'] = $p5Alias;}
  741. if(V::get('DBG', '', $_GET)){$jsonData->__DBG__['$aliasValuesRaw'] = [];}
  742. if ($p5Alias) {
  743. $sqlLocalTableName = $acl->getRootTableName();
  744. $primaryKeyField = $acl->getPrimaryKeyField();
  745. foreach ($p5Alias as $fieldName => $conf) {
  746. $aliasValuesRaw = [];
  747. if ('sql_table_alias' == $conf['type']) {
  748. $localKeys = [];
  749. $localKeyName = V::get('local_join_key', '', $conf);
  750. if ($localKeyName) {
  751. if (!array_key_exists($localKeyName, $localKeys)) {
  752. $localKeys[$localKeyName] = [];
  753. foreach ($items as $item) {
  754. $keyLocal = V::get($localKeyName, 0, $item);
  755. if ($keyLocal) $localKeys[$localKeyName][] = DB::getPDO()->quote($keyLocal, PDO::PARAM_STR);
  756. }
  757. }
  758. if(V::get('DBG', '', $_GET)){$jsonData->__DBG__['$localKeys'] = $localKeys;}
  759. if (!empty($localKeys[$localKeyName])) {
  760. $sqlRemoteTable = V::get('remote_table_name', '', $conf);
  761. $sqlRemoteValueFieldName = V::get('remote_column_value', '', $conf);
  762. $sqlRemoteKeyName = V::get('remote_join_key', '', $conf);
  763. $sqlLocalKeyName = $acl->getSqlFieldName($localKeyName);
  764. $aliasValuesRaw = DB::getPDO()->fetchAllByKey("
  765. select r.{$sqlRemoteKeyName} as {$sqlLocalKeyName}, r.{$sqlRemoteValueFieldName} as remote_value
  766. from {$sqlRemoteTable} r
  767. where r.{$sqlRemoteKeyName} in(" . implode(",", $localKeys[$localKeyName]) . ")
  768. ", $sqlLocalKeyName);
  769. if(V::get('DBG', '', $_GET)){$jsonData->__DBG__['$aliasValuesRaw'][$fieldName] = $aliasValuesRaw;}
  770. }
  771. }
  772. } else if ('sql_query_alias' == $conf['type']) {
  773. $localKeys = [];
  774. $localKeyName = V::get('local_join_key', '', $conf);
  775. $sqlFormat = V::get('join_query_format', '', $conf);
  776. if ($localKeyName && $sqlFormat) {
  777. if (!array_key_exists($localKeyName, $localKeys)) {
  778. $localKeys[$localKeyName] = [];
  779. foreach ($items as $item) {
  780. $keyLocal = V::get($localKeyName, 0, $item);
  781. if ($keyLocal) $localKeys[$localKeyName][] = DB::getPDO()->quote($keyLocal, PDO::PARAM_STR);
  782. }
  783. }
  784. }
  785. if (!empty($localKeys[$localKeyName])) {
  786. $sql = str_replace('{sql_in_local_join_key}', implode(",", $localKeys[$localKeyName]), $sqlFormat);
  787. $sqlLocalKeyName = $acl->getSqlFieldName($localKeyName);
  788. $aliasValuesRaw = DB::getPDO()->fetchAllByKey($sql, $sqlLocalKeyName);
  789. }
  790. }
  791. DBG::log($aliasValuesRaw, 'array', '$aliasValuesRaw');
  792. if (!empty($aliasValuesRaw)) {
  793. if(V::get('DBG_P5', '', $_GET)){echo '{ "$aliasValuesRaw": '.json_encode($aliasValuesRaw).', "dbg": [' . "\n";}
  794. array_walk($items, function (&$item) use ($fieldName, $sqlLocalKeyName, $aliasValuesRaw) {
  795. $sqlValue = V::get($sqlLocalKeyName, null, $item);
  796. if(V::get('DBG_P5', '', $_GET)){echo '{ "sqlValue": "'.$sqlValue.'", "remote_value": "'.$aliasValuesRaw[$sqlValue]['remote_value'].'", "item": '.json_encode($item) . '},' . "\n";}
  797. if ($sqlValue !== null && array_key_exists($sqlValue, $aliasValuesRaw)) {
  798. if(V::get('DBG_P5', '', $_GET)){echo '{ "TODO_update_value": "'.$aliasValuesRaw[$sqlValue]['remote_value'].'"},' . "\n";}
  799. $item[$fieldName] = $aliasValuesRaw[$sqlValue]['remote_value'];
  800. if(V::get('DBG_P5', '', $_GET)){echo '{ "TODO_updated_value": "'.$item[$fieldName].'"},' . "\n";}
  801. }
  802. });
  803. if(V::get('DBG_P5', '', $_GET)){echo "\n".'{}]}';die();}
  804. }
  805. }
  806. }
  807. }
  808. foreach ($items as $item) {
  809. // TODO: hide items without 'R'
  810. foreach ($visibleCols as $fieldName) {
  811. // TODO: ID default 'R'
  812. if (!$acl->canReadObjectField($fieldName, $item)) $item[$fieldName] = '*****';
  813. // null => empty string
  814. if (!isset($item[$fieldName]) || (!$item[$fieldName] && $item[$fieldName] !== '0')) {
  815. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">isEmptyString['.$fieldName.'] (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($item[$fieldName]);echo'</pre>';}
  816. $item[$fieldName] = '';
  817. }
  818. }
  819. $jsonData->rows[] = $item;
  820. }
  821. $jsonData->type = 'success';
  822. $jsonData->msg = 'pobrano nowe dane';
  823. return $jsonData;
  824. }
  825. }