ViewTableAjax.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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) {
  16. $syncUrl = Request::getPathUri() . 'index.php?_route=ViewTableAjax&namespace=' . $acl->getNamespace();
  17. $tbl = new TableAjax($acl);
  18. $tblLabel = $acl->getNamespace();
  19. if ('default_db' == $acl->getSourceName()) {
  20. $tblLabel = array();
  21. $zasobObj = ProcesHelper::getZasobTableInfo($acl->getID());
  22. if (!$zasobObj) throw new Exception("Zasob TABELA ID=" . $acl->getID() . " nie istnieje");
  23. if (!empty($zasobObj->DESC_PL)) $tblLabel []= $zasobObj->DESC_PL;
  24. if (!empty($zasobObj->OPIS)) $tblLabel []= $zasobObj->OPIS;
  25. $tblLabel = implode(" - ", $tblLabel);
  26. }
  27. $tbl->setSyncUrl($syncUrl);
  28. $tbl->setLabel($tblLabel);
  29. $tbl->addRowFunction('edit');
  30. $tbl->addRowFunction('hist');
  31. $tbl->addRowFunction('files');
  32. $tbl->addRowFunction('cp');
  33. $tbl->addRowFunction('msgs');
  34. return $tbl;
  35. }
  36. public function defaultAction() {
  37. UI::gora();
  38. UI::menu();
  39. try {
  40. $namespace = V::get('namespace', '', $_GET, 'word');
  41. if (!$namespace) {
  42. $typeName = V::get('typeName', '', $_GET, 'word');
  43. if (!$typeName) throw new Exception("Wrong param typeName");
  44. $namespace = Api_WfsNs::getBaseWfsUri() . '/' . str_replace(':', '/', $typeName);
  45. }
  46. $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
  47. $forceFilterInit = array();
  48. $filterInit = new stdClass();
  49. $filterInit->currSortCol = $acl->getPrimaryKeyField();
  50. $filterInit->currSortFlip = 'desc';
  51. foreach ($_GET as $k => $v) {
  52. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && !empty($v)) {// filter prefix
  53. $filterInit->$k = $v;
  54. }
  55. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && !empty($v)) {// special filter prefix
  56. $filterInit->$k = $v;
  57. }
  58. else if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
  59. $fldName = substr($k, 3);
  60. $forceFilterInit[$fldName] = $v;
  61. }
  62. }
  63. $tbl = $this->getTableAjaxWidget($acl);
  64. $tbl->setFilterInit($filterInit);
  65. if (!empty($forceFilterInit)) $tbl->setForceFilterInit($forceFilterInit);
  66. echo $tbl->render();
  67. if (DBG::isActive() && V::get('DBG_ACL', '', $_GET)) {// test load perms
  68. Lib::loadClass('DebugExecutionTime');
  69. $dbgExecTime = new DebugExecutionTime();
  70. $dbgExecTime->activate();
  71. $dbgExecTime->log('start');
  72. UI::startContainer(['style'=>'border:1px solid red']);
  73. UI::tag('p', null, "TEST - load perms from db");
  74. $idTable = $acl->getID();
  75. UI::tag('p', null, "DBG idTable({$idTable})");
  76. if ($idTable > 0) {
  77. $dbgExecTime->log('before sql');
  78. $aclTableRows = DB::getPDO()->fetchAll("select * from `CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW` where ID_TABLE = {$idTable}");
  79. $dbgExecTime->log('after sql', ['sql']);
  80. UI::table(['caption' => "from CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW", 'rows' => $aclTableRows]);
  81. $csvIdProces = array();
  82. foreach ($aclTableRows as $row) {
  83. if (!in_array($row['ID_PROCES'], $csvIdProces)) $csvIdProces[] = $row['ID_PROCES'];
  84. }
  85. }
  86. $tableName = $acl->getName();
  87. $databaseName = DB::getPDO()->getDatabaseName();
  88. UI::table([
  89. 'caption' => "Cell to process",
  90. 'rows' => array_map(
  91. function ($row) use ($aclTableRows, $idTable) {
  92. $row['proces'] = array();
  93. $row['id_zasob'] = 0;
  94. $row['PERM_R'] = 0;
  95. $row['PERM_W'] = 0;
  96. $row['PERM_X'] = 0;
  97. $row['PERM_C'] = 0;
  98. $row['PERM_S'] = 0;
  99. $row['PERM_O'] = 0;
  100. $row['PERM_V'] = 0;
  101. $row['PERM_E'] = 0;
  102. foreach ($aclTableRows as $aclInfo) {
  103. if (strtolower($aclInfo['CELL_NAME']) == strtolower($row['COLUMN_NAME'])) {
  104. $row['proces'][] = $aclInfo['ID_PROCES'];
  105. $row['id_zasob'] = $aclInfo['ID_CELL'];
  106. $row['PERM_R'] += $aclInfo['PERM_R'];
  107. $row['PERM_W'] += $aclInfo['PERM_W'];
  108. $row['PERM_X'] += $aclInfo['PERM_X'];
  109. $row['PERM_C'] += $aclInfo['PERM_C'];
  110. $row['PERM_S'] += $aclInfo['PERM_S'];
  111. $row['PERM_O'] += $aclInfo['PERM_O'];
  112. $row['PERM_V'] += $aclInfo['PERM_V'];
  113. $row['PERM_E'] += $aclInfo['PERM_E'];
  114. }
  115. }
  116. $row['proces'] = (empty($row['proces']))
  117. ? "<i style=\"color:red\">Brak</i>"
  118. : implode(", ", $row['proces']);
  119. 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");
  120. return $row;
  121. }, DB::getPDO()->fetchAll("
  122. select t.TABLE_NAME, t.COLUMN_NAME, t.DATA_TYPE, t.COLUMN_TYPE
  123. from `information_schema`.`COLUMNS` t
  124. where t.TABLE_SCHEMA = '{$databaseName}'
  125. and t.TABLE_NAME like '{$tableName}'
  126. ")
  127. )
  128. ]);
  129. if (!empty($csvIdProces)) {
  130. $csvIdProces = implode(",", $csvIdProces);
  131. UI::tag('p', null, "DBG csvIdProces({$csvIdProces})");
  132. $userLogin = User::getLogin();
  133. $dbgExecTime->log('before sql');
  134. $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");
  135. $dbgExecTime->log('after sql', ['sql']);
  136. UI::table(['caption' => "from CRM_PROCES_idx_USER_to_PROCES_VIEW", 'rows' => $rows]);
  137. $userIdProces = array(); foreach ($rows as $row) $userIdProces[] = $row['ID_PROCES'];
  138. $userTablePerms = array();
  139. foreach ($aclTableRows as $row) {
  140. if (!in_array($row['ID_PROCES'], $userIdProces)) continue;
  141. if (array_key_exists($row['CELL_NAME'], $userTablePerms)) {
  142. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_R' ] += $row['PERM_R'];
  143. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_W' ] += $row['PERM_W'];
  144. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_X' ] += $row['PERM_X'];
  145. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_C' ] += $row['PERM_C'];
  146. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_S' ] += $row['PERM_S'];
  147. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_O' ] += $row['PERM_O'];
  148. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_V' ] += $row['PERM_V'];
  149. $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_E' ] += $row['PERM_E'];
  150. } else {
  151. $userTablePerms[ $row['CELL_NAME'] ] = $row;
  152. unset($userTablePerms[ $row['CELL_NAME'] ][ 'TABLE_DESCRIPTION' ]);
  153. unset($userTablePerms[ $row['CELL_NAME'] ][ 'ID_PROCES' ]);
  154. unset($userTablePerms[ $row['CELL_NAME'] ][ 'FORM_TREAT' ]);
  155. }
  156. }
  157. UI::table(['caption' => "\$userTablePerms", 'rows' => $userTablePerms]);
  158. } else UI::alert('warning', "brak \$csvIdProces");
  159. $dbgExecTime->printDebug();
  160. UI::endContainer();
  161. }
  162. } catch (Exception $e) {
  163. UI::startContainer();
  164. UI::alert('danger', "<strong>Wystąpiły błędy!</strong> " . $e->getMessage());
  165. UI::endContainer();
  166. }
  167. UI::dol();
  168. }
  169. public function revertFromHistAjaxAction() {
  170. Response::sendTryCatchJson(array($this, 'revertFromHistAjax'));
  171. }
  172. public function revertFromHistAjax() {
  173. $typeName = V::get('typeName', '', $_REQUEST, 'word');
  174. if (!$typeName) throw new Exception("Wrong param typeName");
  175. // TODO: use namespace from url
  176. // $namespace = V::get('namespace', '', $_GET, 'word');
  177. // if (!$namespace) {
  178. // $typeName = V::get('typeName', '', $_GET, 'word');
  179. // if (!$typeName) throw new Exception("Wrong param typeName");
  180. // $namespace = Api_WfsNs::getBaseWfsUri() . '/' . str_replace(':', '/', $typeName);
  181. // }
  182. // $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
  183. $id = V::get('ID', '', $_REQUEST, 'word');
  184. if (!$id) throw new Exception("Wrong param ID");
  185. $idHist = V::get('idHist', '', $_REQUEST, 'word');
  186. if (!$idHist) throw new Exception("Wrong param idHist");
  187. $fieldName = V::get('fieldName', '', $_REQUEST, 'word');
  188. if (!$fieldName) throw new Exception("Wrong param fieldName");
  189. $acl = Core_AclHelper::getAclByTypeName($typeName);
  190. $item = $acl->getItem($id);
  191. if (!$item) throw new HttpException("Item not found", 404);
  192. if (!$acl->canWriteObjectField($fieldName, $record)) throw new Exception("Missing perm Write for field {$fieldName}");
  193. $histItem = $acl->getHistItem($id, $idHist);
  194. if (!$histItem) throw new HttpException("Hist Item not found", 404);
  195. $histValue = V::get($fieldName, 'N/S;', $histItem);
  196. if ('N/S;' == $histValue) throw new Exception("Missing field value in hist[{$idHist}] for field({$fieldName}) from item[{$id}]");
  197. if ($acl->isGeomField($fieldName)) {
  198. $wktType = strtoupper($acl->getGeomFieldType($fieldName));
  199. if (!$wktType) throw new Exception("Wrong geometry type for field {$fieldName}");
  200. if ($wktType != strtoupper(substr($histValue, 0, strlen($wktType)))) throw new Exception("Wrong geometry type for field {$fieldName} in hist value");
  201. $coords = trim(substr($histValue, strlen($wktType)), '()');
  202. $wktValue = $acl->convertGmlCoordsToWkt($wktType, $coords, ['cs'=>' ', 'ts'=>',']);
  203. if (!$wktValue) throw new Exception("BUG in hist record");
  204. $sqlObj = array();
  205. $sqlObj['ID'] = $id;
  206. $sqlObj[$fieldName] = "GeomFromText('{$wktValue}')";
  207. $affected = DB::getDB()->UPDATE_OBJ($acl->getName(), (object)$sqlObj);
  208. if (0 == $affected) throw new AlertInfoException("Nie wprowadzono żadnych zmian");
  209. else if ($affected < 0) throw new Exception("Wystąpiły błędy podczas aktualizacji rekordu [{$id}]");
  210. $jsonResponse = array();
  211. $jsonResponse['type'] = 'success';
  212. $jsonResponse['msg'] = "Zaktualizowano dane na podstawie wcześniejszej wartości dla rekordu [{$id}]";
  213. $jsonResponse['actions'] = array();
  214. $jsonResponse['actions'][] = ['jsFunction'=>'TableAjax__HIST_Route', 'args'=>[$id]];
  215. return $jsonResponse;
  216. } else {
  217. throw new HttpException("Not implemented - update from hist only for the geom field", 501);
  218. }
  219. throw new Exception("BUG: update field '{$fieldName}' in item[{$id}] from hist[{$idHist}]", 501);
  220. }
  221. public function removeTheGeomAjaxAction() {
  222. Response::sendTryCatchJson(array($this, 'removeTheGeomAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  223. }
  224. public function removeTheGeomAjax($args) {
  225. $namespace = V::get('namespace', '', $args, 'word');
  226. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  227. $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
  228. $primaryKeyField = $acl->getPrimaryKeyField();
  229. $primaryKey = V::get($primaryKeyField, 0, $args, 'int');
  230. $geomFieldName = 'the_geom';
  231. $response = new stdClass();
  232. if ($primaryKey <= 0) throw new HttpException("Bad Request - Wrong param ID", 400);
  233. $record = $acl->getItem($primaryKey);
  234. if (!$record) throw new HttpException("Nie odnaleziono rekordu nr {$primaryKey}", 404);
  235. if (!$acl->canWriteObjectField($geomFieldName, $record)) throw new HttpException("Brak dostępu do zapisu dla pola {$geomFieldName}", 403);
  236. if (empty($record->{$geomFieldName})) {
  237. $response->type = 'info';
  238. $response->msg = "Rekord nie jest powiązany z żadnym obiektem na mapie";
  239. $response->record = $record;
  240. return $response;
  241. }
  242. $itemPatch = array();
  243. $itemPatch[$geomFieldName] = "NULL";
  244. $itemPatch[$primaryKeyField] = $primaryKey;
  245. $response = new stdClass();
  246. try {
  247. $affected = $acl->updateItem($itemPatch);
  248. if ($affected > 0) {
  249. $response->type = 'success';
  250. $response->msg = "Usunięto obiekt z mapy dla rekordu {$primaryKey}";// Rekord zapisany pomyślnie
  251. } else if ($affected == 0) {
  252. $response->type = 'info';
  253. $response->msg = "Nie wprowadzono żadnych zmian";
  254. }
  255. $response->record = $acl->getItem($primaryKey);
  256. }
  257. catch (Exception $e) {
  258. $response->type = 'error';
  259. $response->msg = $e->getMessage();
  260. }
  261. return $response;
  262. }
  263. public function moreFunctionsCellAjaxAction() {
  264. Response::sendTryCatchJson(array($this, 'moreFunctionsCell'), $args = $_GET);
  265. }
  266. public function moreFunctionsCell($args) {// ajax task 'MORE_FUNCTIONS_CELL'
  267. $id = V::get('ID', 0, $args, 'int');
  268. if ($id <= 0) throw new HttpException("404", 404);
  269. $namespace = V::get('namespace', '', $args, 'word');
  270. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  271. $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $args)));
  272. $response = new stdClass();
  273. $response->type = 'success';
  274. $response->msg = 'Funkcje';
  275. $response->rowFunctions = Core_AclHelper::getMoreFunctionsCell($acl, array('primary_key' => $id));
  276. return $response;
  277. }
  278. public function editFormAction() {// namespace, _hash, _primaryKey
  279. $args = $_REQUEST;
  280. $id = V::get('_primaryKey', 0, $args, 'int');
  281. if ($id <= 0) throw new HttpException("Bad Request - missing primaryKey", 400);
  282. $namespace = V::get('namespace', '', $args, 'word');
  283. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  284. $acl = Core_AclHelper::getAclByNamespace($namespace);
  285. $tbl = $this->getTableAjaxWidget($acl);
  286. $tbl->sendAjaxEdit($id, $args);
  287. }
  288. public function editSaveAjaxAction() {
  289. Response::sendTryCatchJson(array($this, 'editSaveAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  290. }
  291. public function editSaveAjax($args) {
  292. $namespace = V::get('namespace', '', $args, 'word');
  293. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  294. $acl = Core_AclHelper::getAclByNamespace($namespace);
  295. $primaryKeyField = $acl->getPrimaryKeyField();
  296. $primaryKey = V::get('primaryKey', 0, $args, 'int');
  297. if (empty($primaryKey)) throw new HttpException("Bad Request - missing primaryKey!", 400);
  298. $item = $acl->getItem($primaryKey);
  299. if (!$item) throw new HttpException("Item not exists!", 404);
  300. $itemFromUser = $acl->convertObjectFromUserInput($args['form'], $type = 'array_by_id', $prefix = 'f');
  301. $response = new stdClass();
  302. $response->primaryKey = $primaryKey;
  303. try {
  304. $itemFromUser[$primaryKeyField] = $primaryKey;
  305. $affected = $acl->updateItem($itemFromUser);
  306. if ($affected > 0) {
  307. $response->type = 'success';
  308. $response->msg = "Rekord zapisany pomyślnie";//"Record saved successfully";
  309. } else if ($affected == 0) {
  310. $response->type = 'info';
  311. $response->msg = "Nie wprowadzono żadnych zmian";
  312. }
  313. $response->record = $acl->getItem($primaryKey);
  314. $rowFunList = Core_AclHelper::getMoreFunctionsCell($acl, array('primary_key'=>$primaryKey, 'record'=>$response->record));
  315. if (!empty($rowFunList)) $response->rowFunctions = $rowFunList;
  316. }
  317. catch (Exception $e) {
  318. $response->type = 'error';
  319. $response->msg = "Wystąpiły błędy!";
  320. $response->msg .= $e->getMessage();
  321. }
  322. return $response;
  323. }
  324. public function typeSpecialCellAction() {
  325. Response::sendTryCatchJson(array($this, 'typeSpecialCell'), $args = $_REQUEST);
  326. }
  327. public function typeSpecialCell($args) {
  328. $namespace = V::get('namespace', '', $args, 'word');
  329. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  330. $acl = Core_AclHelper::getAclByNamespace($namespace);
  331. $id = V::get('ID', 0, $args, 'int');
  332. $fieldName = V::get('col', '', $args);
  333. if ($id <= 0 || empty($fieldName)) throw new HttpException("Bad Request - missing id or col", 400);
  334. $col = $fieldName;// TODO: RM $col
  335. $jsonData = new stdClass();
  336. $idField = $acl->getFieldIdByName($fieldName);
  337. if (!$idField) throw new Exception("Wrong field");
  338. $item = $acl->getItem($id);
  339. if (!$acl->canReadObjectField($fieldName, $item)) throw new Exception("Brak dostępu");
  340. $typeSpecial = Typespecial::getInstance($idField, $fieldName);
  341. if ($typeSpecial) {
  342. $jsonData->data = $typeSpecial->getReturnData($acl->getID(), $id, $fieldName, '');
  343. $jsonData->namespace = 'default_db/' . V::get('tbl_name', '', $jsonData->data);
  344. }
  345. return $jsonData;
  346. }
  347. /**
  348. * @param $_GET['namespace'] = AclNamespace
  349. * @param $_GET['format'] = 'csv' | 'html'
  350. * @param $_GET['flds'] = csv - coma separated field names
  351. * @param $_GET['sortCol'] = FieldName
  352. * @param $_GET['sortDir'] = SortDir ('desc' | 'asc')
  353. * @param $_GET['f_{$fieldName}'] = filter
  354. * @param $_GET['sf_{$fieldName}'] = force filter
  355. */
  356. public function exportAction() {
  357. $args = $_GET;
  358. $namespace = V::get('namespace', '', $args, 'word');
  359. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  360. $acl = Core_AclHelper::getAclByNamespace($namespace);
  361. $exportLimit = 10000;
  362. $params = array();
  363. $params['limit'] = $exportLimit;
  364. // $params['limitstart'] = 0;
  365. $params['order_by'] = V::get('sortCol', '', $args);
  366. $params['order_dir'] = V::get('sortDir', '', $args);
  367. $params['cols'] = array($acl->getPrimaryKeyField());
  368. $toExportFields = explode(',', V::get('flds', '', $_GET));
  369. if (empty($toExportFields)) throw new Exception("Nie wybrano żandych pól do exportu.");
  370. $allowedExportFieldList = Core_AclHelper::getExportFieldList($acl);
  371. foreach ($toExportFields as $fieldName) {
  372. if ($fieldName == $acl->getPrimaryKeyField()) continue;
  373. if (!in_array($fieldName, $allowedExportFieldList)) throw new Exception("Brak uprawnień do exportu pola '{$fieldName}'");
  374. $params['cols'][] = $fieldName;
  375. }
  376. $labels = array();
  377. foreach ($toExportFields as $fieldName) {
  378. $labels[ $fieldName ] = $acl->getFieldLabel($fieldName);
  379. }
  380. foreach ($args as $k => $v) {
  381. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && strlen($v) > 0) {// filter prefix
  382. $params[$k] = $v;
  383. }
  384. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && strlen($v) > 0) {// special filter prefix
  385. $params[$k] = $v;
  386. }
  387. }
  388. $total = $acl->getTotal($params);
  389. // if ($total > $exportLimit) $params['limit'] = $exportLimit;
  390. $items = $acl->getItems($params);
  391. $format = V::get('format', 'html', $_GET);
  392. if ('html' == $format) {
  393. UI::gora();
  394. UI::startTag('table', ['class'=>'table table-bordered table-hover']);
  395. UI::startTag('thead');
  396. UI::startTag('tr');
  397. foreach ($labels as $fldName => $label) {
  398. UI::tag('th', [], $label);
  399. }
  400. UI::endTag('tr');
  401. UI::endTag('thead');
  402. UI::startTag('tbody');
  403. foreach ($items as $item) :
  404. UI::startTag('tr');
  405. foreach ($labels as $fldName => $label) :
  406. UI::tag('td', [], $item->{$fldName});
  407. endforeach;
  408. UI::endTag('tr');
  409. endforeach;
  410. UI::endTag('tbody');
  411. UI::endTag('table');
  412. UI::dol();
  413. }
  414. else if ('csv' == $format) {
  415. $csvFileName = "Tabela-" . $acl->getName() . "-" . date("Y-m-d_H_s");
  416. header('Content-Type: text/csv; charset=utf-8');
  417. header("Content-Disposition: attachment; filename={$csvFileName}.csv");
  418. $csvSeparator = ';';
  419. $labelsLine = array();
  420. foreach ($labels as $fldName => $label) {
  421. $labelsLine[] = '"' . addslashes($label) . '"';
  422. }
  423. echo implode($csvSeparator, $labelsLine) . "\n";
  424. foreach ($items as $item) {
  425. $itemLine = array();
  426. foreach ($labels as $fldName => $label) {
  427. $itemLine[] = '"' . addslashes($item->{$fldName}) . '"';
  428. }
  429. echo implode($csvSeparator, $itemLine) . "\n";
  430. }
  431. }
  432. else {
  433. die("Nieobsługiwany format danych.");
  434. }
  435. }
  436. public function loadDataAjaxAction() {
  437. $namespace = V::get('namespace', '', $_REQUEST, 'word');
  438. if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
  439. $acl = Core_AclHelper::getAclByNamespace($namespace);
  440. $tbl = $this->getTableAjaxWidget($acl);
  441. Response::sendTryCatchJson(array($tbl, 'ajaxData'), $args = $_GET);
  442. }
  443. }