ViewObject.php 37 KB

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