UrlAction.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. /*
  4. ## Url Actions (to replace Typespecial's):
  5. - new Zasob type: 'URL_ACTION'
  6. ## Config in Zasoby tree (TODO: upload from gui xml file or php):
  7. [100] - TYPESPECIALS
  8. [110] - URL_ACTION ProjektyKosztyWstepnychRobot
  9. [111] - PARAM_IN ID_PROJECT
  10. [200] - TABELA IN7_MK_BAZA_DYSTRYBUCJI Projekty
  11. [210] - KOMORKA ID
  12. [220] - (ALIAS to [110]) URL_ACTION action name/label
  13. [221] - (ALIAS to [210]) PARAM_IN ID_PROJECT
  14. class Route_UrlAction_ProjektyKosztyWstepnychRobot extends RouteBase {
  15. public function defaultAction() {
  16. $args = array();
  17. $args['ID_PROJECT'] = V::get('ID_PROJECT', '', $_REQUEST);// [111]
  18. }
  19. }
  20. ## Process - Create:
  21. - 1. define action name in Zasoby tree (URL_ACTION) and expected args (PARAM_IN) - `ActionDefinition`
  22. - 2. create action alias inside TABLE - `ActionInstance`
  23. - 3. set perms for `ActionInstance`
  24. ## Process - Install ActionDefinitio's:
  25. - class UrlActionBase :: installZasobAction
  26. - create required Zasoby in Zasob Tree if not exists
  27. */
  28. class Route_UrlAction extends RouteBase {// TODO: UrlActionBase
  29. public function handleAuth() {
  30. if (!User::logged()) {
  31. throw new HttpException('Unauthorized', 401);
  32. }
  33. }
  34. public function defaultAction() {
  35. SE_Layout::gora();
  36. ?>
  37. <div class="container">
  38. <h1>UrlActions system</h1>
  39. ...
  40. </div>
  41. <?php
  42. SE_Layout::dol();
  43. }
  44. public function getArgsList() {
  45. $args = array();
  46. return $args;
  47. }
  48. public function reinstallAction() {
  49. $jsonData = new stdClass();
  50. $jsonData->type = 'success';
  51. $jsonData->msg = 'Gotowe';
  52. try {
  53. $this->reinstall();
  54. } catch (Exception $e) {
  55. $jsonData->type = 'danger';
  56. $jsonData->msg = $e->getMessage();
  57. }
  58. echo json_encode($jsonData);
  59. }
  60. public function reinstall() {
  61. $sqlList = array();
  62. // alter table enum add URL_ACTION
  63. //$sqlList['RemoveTable'] = "DROP TABLE IF EXISTS `CRM_UI_MSGS`";
  64. $pdo = DB::getPDO();
  65. foreach ($sqlList as $sqlName => $sql) {
  66. $pdo->exec($sql);
  67. }
  68. }
  69. /*
  70. 636 TABELA IN7_MK_BAZA_DYSTRYBUCJI Projekty
  71. 763 KOMORKA ID Nr
  72. 22332 22317 URL_ACTION ProjektyKosztyWstepnychRobot
  73. 22335 763 PARAM_IN ID_PROJECT
  74. 25 TYPESPECIALS TYPESPECIALS Powiązania tabel
  75. 22317 URL_ACTION ProjektyKosztyWstepnychRobot
  76. 22324 PARAM_IN ID_PROJECT
  77. */
  78. public static function fetchTableFunctions($idTbl, $idRecord) {
  79. $sth = DB::getPDO()->prepare("
  80. select z.ID as ID
  81. , z.`DESC_PL` as fun_label
  82. , za.`DESC` as fun_name
  83. , zp.ALIAS_ID as param_in_to_cell_id
  84. , zp.DESC as param_in_name
  85. from CRM_LISTA_ZASOBOW z
  86. join CRM_LISTA_ZASOBOW za on(za.ID = z.ALIAS_ID)
  87. left join CRM_LISTA_ZASOBOW zp on(zp.PARENT_ID = z.ID and zp.`TYPE` = 'PARAM_IN')
  88. left join CRM_LISTA_ZASOBOW zpa on(zpa.ID = zp.ALIAS_ID and zpa.`TYPE` = 'PARAM_IN' and zpa.`DESC` = zp.`DESC`)
  89. where z.PARENT_ID = :id_zasob
  90. and z.`TYPE` = 'URL_ACTION'
  91. ");
  92. $sth->bindValue(':id_zasob', $idTbl, PDO::PARAM_STR);
  93. $sth->execute();
  94. return $sth->fetchAll();
  95. }
  96. public static function fetchTableFunctionsForUser($idTbl, $idRecord, $usrLogin) {
  97. $sth = DB::getPDO()->prepare("
  98. select z.ID as ID
  99. , z.`DESC_PL` as fun_label
  100. , za.`DESC` as fun_name
  101. , zp.ALIAS_ID as param_in_to_cell_id
  102. , zp.DESC as param_in_name
  103. , param.`DESC` as link_param
  104. from CRM_LISTA_ZASOBOW z
  105. join CRM_LISTA_ZASOBOW za on(za.ID = z.ALIAS_ID)
  106. left join CRM_LISTA_ZASOBOW zp on(zp.PARENT_ID = z.ID and zp.`TYPE` = 'PARAM_IN')
  107. left join CRM_LISTA_ZASOBOW zpa on(zpa.ID = zp.ALIAS_ID and zpa.`TYPE` = 'PARAM_IN' and zpa.`DESC` = zp.`DESC`)
  108. join CRM_WSKAZNIK w on(w.ID_ZASOB = z.ID)
  109. -- join CRM_PROCES p on(p.ID = w.ID_PROCES)
  110. join CRM_PROCES_idx_USER_to_PROCES_VIEW upv on(upv.ID_PROCES = w.ID_PROCES)
  111. left join CRM_LISTA_ZASOBOW param on(param.PARENT_ID = z.ID and param.`TYPE` = 'DANE')
  112. where z.PARENT_ID = :id_zasob
  113. and z.`TYPE` = 'URL_ACTION'
  114. and upv.ADM_ACCOUNT = :usr_login
  115. group by z.ID
  116. ");
  117. $sth->bindValue(':id_zasob', $idTbl, PDO::PARAM_STR);
  118. $sth->bindValue(':usr_login', $usrLogin, PDO::PARAM_STR);
  119. $sth->execute();
  120. return $sth->fetchAll();
  121. }
  122. public static function getTableFunctions($idTbl, $idRecord, $tblName = '', $usrLogin = null) {
  123. $rows = array();
  124. if (!empty($usrLogin)) {
  125. $rows = self::fetchTableFunctionsForUser($idTbl, $idRecord, $usrLogin);
  126. } else {
  127. $rows = self::fetchTableFunctions($idTbl, $idRecord);
  128. }
  129. DBG::_('DBG', '>1', 'rows', $rows, __CLASS__, __FUNCTION__, __LINE__);
  130. $functions = array();
  131. foreach ($rows as $row) {
  132. // TODO: Router::getRoute("UrlAction_{$row['fun_name']}")->isRecordAllowed($idTbl, $idRecord, $tblName);
  133. if (!array_key_exists($row['ID'], $functions)) {
  134. $fun = array();
  135. $fun['label'] = $row['fun_label'];
  136. $fun['name'] = $row['fun_name'];
  137. $fun['baseLink'] = "index.php?_route=UrlAction_{$row['fun_name']}";
  138. $fun['ico'] = "glyphicon glyphicon-share";
  139. $fun['cell_id_params'] = array();
  140. $fun['link_target'] = '_blank';// LINK_TARGET_SELF
  141. $functions[ $row['ID'] ] = $fun;
  142. }
  143. $funParams = $functions[ $row['ID'] ]['cell_id_params'];
  144. if ($row['param_in_to_cell_id'] > 0 && !empty($row['param_in_name'])) {
  145. $funParams[ $row['param_in_to_cell_id'] ] = $row['param_in_name'];
  146. $functions[ $row['ID'] ]['cell_id_params'] = $funParams;
  147. }
  148. if ('LINK_TARGET_SELF' == $row['link_param']) {
  149. unset($functions[ $row['ID'] ]['link_target']);
  150. }
  151. }
  152. DBG::_('DBG', '>1', 'functions', $functions, __CLASS__, __FUNCTION__, __LINE__);
  153. return $functions;
  154. }
  155. }