ViewTableAjax.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. class Route_ViewTableAjax extends RouteBase {
  9. public function defaultAction() {
  10. UI::gora();
  11. UI::menu();
  12. try {
  13. $typeName = V::get('typeName', '', $_GET, 'word');
  14. if (!$typeName) throw new Exception("Wrong param typeName");
  15. $tblAcl = $this->getAclFromTypeName($typeName, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
  16. $forceFilterInit = array();
  17. $filterInit = new stdClass();
  18. $filterInit->currSortCol = 'ID';
  19. $filterInit->currSortFlip = 'desc';
  20. foreach ($_GET as $k => $v) {
  21. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && !empty($v)) {// filter prefix
  22. $filterInit->$k = $v;
  23. }
  24. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && !empty($v)) {// special filter prefix
  25. $filterInit->$k = $v;
  26. }
  27. else if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
  28. $fldName = substr($k, 3);
  29. $forceFilterInit[$fldName] = $v;
  30. }
  31. }
  32. $tbl = new TableAjax($tblAcl);
  33. $tblLabel = array();
  34. $zasobObj = ProcesHelper::getZasobTableInfo($tblAcl->getID());
  35. if (!$zasobObj) throw new Exception("Zasob TABELA ID=" . $tblAcl->getID() . " nie istnieje");
  36. if (!empty($zasobObj->DESC_PL)) $tblLabel []= $zasobObj->DESC_PL;
  37. if (!empty($zasobObj->OPIS)) $tblLabel []= $zasobObj->OPIS;
  38. $tblLabel = implode(" - ", $tblLabel);
  39. $tbl->setLabel($tblLabel);
  40. $tbl->setFilterInit($filterInit);
  41. if (!empty($forceFilterInit)) $tbl->setForceFilterInit($forceFilterInit);
  42. $tbl->addRowFunction('edit');
  43. $tbl->addRowFunction('hist');
  44. $tbl->addRowFunction('files');
  45. $tbl->addRowFunction('cp');
  46. $tbl->addRowFunction('msgs');
  47. echo $tbl->render();
  48. } catch (Exception $e) {
  49. UI::startContainer();
  50. UI::alert('danger', "<strong>Wystąpiły błędy!</strong> " . $e->getMessage());
  51. UI::endContainer();
  52. }
  53. UI::dol();
  54. }
  55. /**
  56. * @param string $typeName - 'p5_default_db:TEST_PERMS'
  57. */
  58. public function getAclFromTypeName($typeName, $forceTblAclInit) {
  59. $userAcl = User::getAcl();
  60. $userAcl->fetchGroups();
  61. $typeEx = explode(':', $typeName);
  62. if (2 != count($typeEx)) throw new Exception("Could not get acl for '{$typeName}' - syntax error");
  63. if ('p5_' != substr($typeEx[0], 0, 3)) throw new Exception("Could not get acl for '{$typeName}' - prefix error");
  64. $sourceName = substr($typeEx[0], 3);
  65. $objName = $typeEx[1];
  66. $acl = $userAcl->getObjectAcl($sourceName, $objName);
  67. if (!$acl) throw new Exception("Could not get acl for '{$typeName}'");
  68. $acl->init($forceTblAclInit);
  69. return $acl;
  70. }
  71. }