edit.html.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * The create view file of webhook module of ZenTaoPMS.
  4. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  5. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  6. * @author Yidong Wang <yidong@easycorp.ltd>
  7. * @package webhook
  8. * @link https://www.zentao.net
  9. */
  10. namespace zin;
  11. $fields = $config->webhook->form->create;
  12. $defaultWidth = '1/2';
  13. $formItems = array();
  14. $secret = json_decode($webhook->secret);
  15. foreach($fields as $field => $attr)
  16. {
  17. if($field == 'type') continue;
  18. if($field == 'secret' && $webhook->type != 'dinggroup' && $webhook->type != 'feishugroup') continue;
  19. if($field == 'params' && strpos('|bearychat|dinggroup|dinguser|wechatgroup|wechatuser|feishuuser|feishugroup|', "|{$webhook->type}|") !== false) continue;
  20. if(($field == 'agentId' || $field == 'appKey' || $field == 'appSecret') && $webhook->type != 'dinguser') continue;
  21. if(($field == 'wechatCorpId' || $field == 'wechatCorpSecret' || $field == 'wechatAgentId') && $webhook->type != 'wechatuser') continue;
  22. if(($field == 'feishuAppId' || $field == 'feishuAppSecret') && $webhook->type != 'feishuuser') continue;
  23. $width = zget($attr, 'width', $defaultWidth);
  24. $fieldName = $field;
  25. $notice = '';
  26. $required = zget($attr, 'required', false);
  27. $rowID = '';
  28. $rowClass = '';
  29. $title = $field;
  30. $default = zget($webhook, $field, '');
  31. $control = array();
  32. if($field == 'products') $attr['options'] = $products;
  33. if($field == 'executions') $attr['options'] = $executions;
  34. $control['type'] = $attr['control'];
  35. if(!empty($attr['options'])) $control['items'] = $attr['options'];
  36. if(!empty($attr['inline'])) $control['inline'] = $attr['inline'];
  37. if($attr['control'] == 'checkList') $fieldName = $field . '[]';
  38. if(!empty($attr['multiple']))
  39. {
  40. $control['multiple'] = true;
  41. $fieldName = $field . '[]';
  42. }
  43. if($webhook->type == 'dinguser')
  44. {
  45. if($field == 'agentId') $default = $secret->agentId;
  46. if($field == 'appKey') $default = $secret->appKey;
  47. if($field == 'appSecret') $default = $secret->appSecret;
  48. }
  49. if($webhook->type == 'wechatuser')
  50. {
  51. if($field == 'wechatCorpId') $default = $secret->appKey;
  52. if($field == 'wechatCorpSecret') $default = $secret->appSecret;
  53. if($field == 'wechatAgentId') $default = $secret->agentId;
  54. }
  55. if($webhook->type == 'feishuuser')
  56. {
  57. if($field == 'feishuAppId') $default = $secret->appId;
  58. if($field == 'feishuAppSecret') $default = $secret->appSecret;
  59. }
  60. if(isset($lang->webhook->{$field})) $title = $lang->webhook->{$field};
  61. if($field == 'appKey') $title = $lang->webhook->dingAppKey;
  62. if($field == 'appSecret') $title = $lang->webhook->dingAppSecret;
  63. if($field == 'agentId') $title = $lang->webhook->dingAgentId;
  64. if($field == 'products') $title = $lang->webhook->product;
  65. if($field == 'executions') $title = $lang->webhook->execution;
  66. if($field == 'secret') $rowID = 'secretTR';
  67. if($field == 'url') $rowID = 'urlTR';
  68. if($field == 'sendType') $rowID = 'sendTypeTR';
  69. if($field == 'wechatCorpId') $notice = $lang->webhook->note->wechatHelp;
  70. if($field == 'url') $notice = zget($lang->webhook->note->typeList, $webhook->type, '');
  71. if($field == 'agentId') $notice = $lang->webhook->note->dingHelp;
  72. if($field == 'sendType') $notice = $lang->webhook->note->async;
  73. if($field == 'products') $notice = $lang->webhook->note->product;
  74. if($field == 'executions') $notice = $lang->webhook->note->execution;
  75. if($field == 'agentId' || $field == 'appKey' || $field == 'appSecret') $rowClass = 'dinguserTR';
  76. if($field == 'feishuAppId' || $field == 'feishuAppSecret') $rowClass = 'feishuTR';
  77. if($field == 'wechatCorpId' || $field == 'wechatCorpSecret' || $field == 'wechatAgentId') $rowClass = 'wechatTR';
  78. if($field == 'url' && strpos("|dinguser|wechatuser|feishuuser|", "|{$webhook->type}|") !== false) $rowClass = 'hidden';
  79. if($field == 'agentId' || $field == 'appKey' || $field == 'appSecret') $required = true;
  80. if($field == 'feishuAppId' || $field == 'feishuAppSecret') $required = true;
  81. if($field == 'wechatCorpId' || $field == 'wechatCorpSecret' || $field == 'wechatAgentId') $required = true;
  82. $formItems[] = formRow
  83. (
  84. $rowID ? setID($rowID) : null,
  85. $rowClass ? setClass($rowClass) : null,
  86. formGroup
  87. (
  88. set::width($width),
  89. set::name($fieldName),
  90. set::label($title),
  91. set::control($control),
  92. set::value($default),
  93. set::required($required)
  94. ),
  95. $notice ? formGroup
  96. (
  97. $field == 'url' ? setID('urlNote') : null,
  98. html($notice)
  99. ) : null
  100. );
  101. }
  102. jsVar('urlNote', $lang->webhook->note->typeList);
  103. formPanel
  104. (
  105. formGroup
  106. (
  107. setClass('webhookType'),
  108. set::label($lang->webhook->type),
  109. formHidden('type', $webhook->type),
  110. span(setClass('pl-5'), zget($lang->webhook->typeList, $webhook->type))
  111. ),
  112. $formItems
  113. );
  114. render();