UrlAction.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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):
  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. $args[] = 'ID_PROJECT';
  47. return $args;
  48. }
  49. public function reinstallAction() {
  50. $jsonData = new stdClass();
  51. $jsonData->type = 'success';
  52. $jsonData->msg = 'Gotowe';
  53. try {
  54. $this->reinstall();
  55. } catch (Exception $e) {
  56. $jsonData->type = 'danger';
  57. $jsonData->msg = $e->getMessage();
  58. }
  59. echo json_encode($jsonData);
  60. }
  61. public function runAction() {
  62. $jsonData = new stdClass();
  63. $jsonData->type = 'success';
  64. $jsonData->msg = 'Gotowe';
  65. try {
  66. $idAction = V::get('_idAction', 0, $_REQUEST, 'int');
  67. if ($idAction > 0) {
  68. $this->runActionById($idAction);
  69. }
  70. } catch (Exception $e) {
  71. $jsonData->type = 'danger';
  72. $jsonData->msg = $e->getMessage();
  73. }
  74. echo json_encode($jsonData);
  75. }
  76. public function reinstall() {
  77. $sqlList = array();
  78. //$sqlList['RemoveTable'] = "DROP TABLE IF EXISTS `CRM_UI_MSGS`";
  79. $pdo = DB::getPDO();
  80. foreach ($sqlList as $sqlName => $sql) {
  81. $pdo->exec($sql);
  82. }
  83. }
  84. public function runActionById($id) {
  85. $msgRow = $this->getActiveMessage($id);
  86. $execNotes = '';
  87. if (!empty($msgRow->app_className)) {
  88. $route = Router::getRoute($msgRow->app_className);
  89. $route->runByMessageFromMsgsSystem($msgRow->msg, $execNotes);
  90. }
  91. $this->forceFinishMessage($id, $execNotes);
  92. }
  93. }