1
0

BxBaseStudioPermissionsActions.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. class BxBaseStudioPermissionsActions extends BxDolStudioPermissionsActions
  11. {
  12. function __construct($aOptions, $oTemplate = false)
  13. {
  14. parent::__construct($aOptions, $oTemplate);
  15. $this->_aOptions['actions_single']['options']['attr']['title'] = _t('_adm_prm_btn_actions_options');
  16. }
  17. public function performActionEnable($mixedChecked = null)
  18. {
  19. $aIds = bx_get('ids');
  20. $bEnable = (int)bx_get('checked');
  21. if(!$aIds || !is_array($aIds)) {
  22. echoJson(array());
  23. exit;
  24. }
  25. $aResultIds = array();
  26. foreach($aIds as $mixedId) {
  27. if(strpos($mixedId, $this->sParamsDivider) !== false)
  28. list($this->iLevel, $iId) = explode($this->sParamsDivider, urldecode($mixedId));
  29. if($this->oDb->switchAction($this->iLevel, $iId, $bEnable))
  30. $aResultIds[] = $iId;
  31. }
  32. $sAction = $bEnable ? 'enable' : 'disable';
  33. echo echoJson(array(
  34. $sAction => $aResultIds,
  35. ));
  36. }
  37. public function performActionOptions()
  38. {
  39. $sAction = 'options';
  40. if((int)$this->iLevel == 0)
  41. $this->iLevel = (int)bx_get('IDLevel');
  42. $aIds = bx_get('ids');
  43. if(empty($aIds) || !is_array($aIds)) {
  44. $iId = (int)bx_get('IDAction');
  45. if(!$iId)
  46. return echoJson([]);
  47. $aIds = [$iId];
  48. }
  49. $sId = array_shift($aIds);
  50. if(strpos($sId, $this->sParamsDivider) !== false)
  51. list($this->iLevel, $iId) = explode($this->sParamsDivider, urldecode($sId));
  52. else
  53. $iId = $sId;
  54. $aOption = [];
  55. $iOption = $this->oDb->getOptions(array('type' => 'by_level_action_ids', 'level_id' => $this->iLevel, 'action_id' => $iId), $aOption);
  56. if($iOption != 1 || empty($aOption))
  57. return echoJson([]);
  58. bx_import('BxTemplStudioFormView');
  59. $aActionParams = ['o' => $this->_sObject, 'a' => $sAction, 'level' => $this->iLevel];
  60. if(!empty($this->sModule))
  61. $aActionParams['module'] = $this->sModule;
  62. $aForm = array(
  63. 'form_attrs' => array(
  64. 'id' => 'adm-prm-action-options',
  65. 'action' => BX_DOL_URL_ROOT . bx_append_url_params('grid.php', $aActionParams),
  66. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  67. ),
  68. 'params' => array (
  69. 'db' => array(
  70. 'table' => 'sys_acl_matrix',
  71. 'key' => '',
  72. 'uri' => '',
  73. 'uri_title' => '',
  74. 'submit_name' => 'do_submit'
  75. ),
  76. ),
  77. 'inputs' => array (
  78. 'IDLevel' => array(
  79. 'type' => 'hidden',
  80. 'name' => 'IDLevel',
  81. 'value' => $this->iLevel,
  82. 'db' => array (
  83. 'pass' => 'Int',
  84. ),
  85. ),
  86. 'IDAction' => array(
  87. 'type' => 'hidden',
  88. 'name' => 'IDAction',
  89. 'value' => $iId,
  90. 'db' => array (
  91. 'pass' => 'Int',
  92. ),
  93. ),
  94. 'AllowedCount' => array(
  95. 'type' => 'text',
  96. 'name' => 'AllowedCount',
  97. 'caption' => _t('_adm_prm_txt_actions_number'),
  98. 'info' => _t('_adm_prm_dsc_actions_number'),
  99. 'value' => $aOption['allowed_count'],
  100. 'db' => array (
  101. 'pass' => 'Int',
  102. ),
  103. ),
  104. 'AllowedPeriodLen' => array(
  105. 'type' => 'text',
  106. 'name' => 'AllowedPeriodLen',
  107. 'caption' => _t('_adm_prm_txt_actions_reset'),
  108. 'info' => _t('_adm_prm_dsc_actions_reset'),
  109. 'value' => $aOption['allowed_period_len'],
  110. 'db' => array (
  111. 'pass' => 'Int',
  112. ),
  113. ),
  114. 'AllowedPeriodStart' => array(
  115. 'type' => 'datetime',
  116. 'name' => 'AllowedPeriodStart',
  117. 'caption' => _t('_adm_prm_txt_actions_avail_start'),
  118. 'info' => _t('_adm_prm_dsc_actions_avail'),
  119. 'value' => $aOption['allowed_period_start'],
  120. 'attrs' => array(
  121. 'allow_input' => 'true',
  122. ),
  123. 'db' => array (
  124. 'pass' => 'Xss',
  125. ),
  126. ),
  127. 'AllowedPeriodEnd' => array(
  128. 'type' => 'datetime',
  129. 'name' => 'AllowedPeriodEnd',
  130. 'caption' => _t('_adm_prm_txt_actions_avail_end'),
  131. 'info' => _t('_adm_prm_dsc_actions_avail'),
  132. 'value' => $aOption['allowed_period_end'],
  133. 'attrs' => array(
  134. 'allow_input' => 'true',
  135. ),
  136. 'db' => array (
  137. 'pass' => 'Xss',
  138. ),
  139. ),
  140. 'controls' => array(
  141. 'name' => 'controls',
  142. 'type' => 'input_set',
  143. array(
  144. 'type' => 'submit',
  145. 'name' => 'do_submit',
  146. 'value' => _t('_adm_prm_btn_actions_save'),
  147. ),
  148. array (
  149. 'type' => 'reset',
  150. 'name' => 'close',
  151. 'value' => _t('_adm_prm_btn_actions_cancel'),
  152. 'attrs' => array(
  153. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  154. 'class' => 'bx-def-margin-sec-left',
  155. ),
  156. )
  157. )
  158. )
  159. );
  160. if((int)$aOption['action_countable'] != 1)
  161. unset($aForm['inputs']['AllowedCount'], $aForm['inputs']['AllowedPeriodLen']);
  162. $oForm = new BxTemplStudioFormView($aForm);
  163. $oForm->initChecker();
  164. if($oForm->isSubmittedAndValid()) {
  165. $aUpdate = [];
  166. foreach($aForm['inputs'] as $sName => $aInput) {
  167. if(in_array($aInput['type'], array('hidden', 'input_set')))
  168. continue;
  169. $aUpdate[$sName] = $oForm->getCleanValue($sName);
  170. if(empty($aUpdate[$sName]))
  171. $aUpdate[$sName] = null;
  172. }
  173. if($this->oDb->updateOptions((int)$oForm->getCleanValue('IDLevel'), (int)$oForm->getCleanValue('IDAction'), $aUpdate))
  174. $aRes = ['grid' => $this->getCode(false), 'blink' => $sId];
  175. else
  176. $aRes = ['msg' => _t('_adm_prm_err_action_edit')];
  177. echoJson($aRes);
  178. }
  179. else {
  180. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-prm-action-options-popup', _t('_adm_prm_txt_actions_options_popup', _t($aOption['action_title'])), $this->_oTemplate->parseHtmlByName('prm_edit_option.html', [
  181. 'form_id' => $aForm['form_attrs']['id'],
  182. 'form' => $oForm->getCode(true),
  183. 'object' => $this->_sObject,
  184. 'action' => $sAction
  185. ]));
  186. echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false]]]);
  187. }
  188. }
  189. function getJsObject()
  190. {
  191. return 'oBxDolStudioPermissionsActions';
  192. }
  193. function getCode($isDisplayHeader = true)
  194. {
  195. return $this->_oTemplate->parseHtmlByName('prm_actions.html', array(
  196. 'content' => parent::getCode($isDisplayHeader),
  197. 'js_object' => $this->getJsObject(),
  198. 'grid_object' => $this->_sObject,
  199. 'params_divider' => $this->sParamsDivider
  200. ));
  201. }
  202. protected function _addJsCss()
  203. {
  204. parent::_addJsCss();
  205. $this->_oTemplate->addJs(array('jquery.form.min.js', 'permissions_actions.js'));
  206. $oForm = new BxTemplStudioFormView(array());
  207. $oForm->addCssJs();
  208. }
  209. protected function _getCellSwitcher($mixedValue, $sKey, $aField, $aRow)
  210. {
  211. if($this->iLevel == 0)
  212. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  213. $aRow[$this->_aOptions['field_id']] = urlencode($this->iLevel . $this->sParamsDivider . $aRow[$this->_aOptions['field_id']]);
  214. return parent::_getCellSwitcher($mixedValue, $sKey, $aField, $aRow);
  215. }
  216. protected function _getCellDesc($mixedValue, $sKey, $aField, $aRow)
  217. {
  218. $mixedValue = bx_process_output(_t($aRow['Desc']));
  219. $mixedValue = $this->_limitMaxLength($mixedValue, $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  220. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  221. }
  222. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  223. {
  224. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['Module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  225. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  226. }
  227. protected function _getActionOptions ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  228. {
  229. $a['attr']['bx_grid_action_data'] = urlencode($this->iLevel . $this->sParamsDivider . $a['attr']['bx_grid_action_data']);
  230. return parent::_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  231. }
  232. protected function _getFilterControls ()
  233. {
  234. parent::_getFilterControls();
  235. $sContent = "";
  236. $sJsObject = $this->getJsObject();
  237. $oForm = new BxTemplStudioFormView(array());
  238. $aInputLevels = array(
  239. 'type' => 'select',
  240. 'name' => 'level',
  241. 'attrs' => array(
  242. 'id' => 'bx-grid-level-' . $this->_sObject,
  243. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeLevel()'
  244. ),
  245. 'value' => 'id-' . $this->iLevel,
  246. 'values' => array()
  247. );
  248. $aLevels = $aCounter = array();
  249. $this->oDb->getLevels(array('type' => 'all'), $aLevels, false);
  250. $this->oDb->getActions(array('type' => 'counter_by_levels'), $aCounter, false);
  251. foreach($aLevels as $aLevel)
  252. $aInputLevels['values']['id-' . $aLevel['id']] = _t($aLevel['name']) . " (" . (isset($aCounter[$aLevel['id']]) ? $aCounter[$aLevel['id']] : "0") . ")";
  253. asort($aInputLevels['values']);
  254. $aInputLevels['values'] = array_merge(array('id-0' => _t('_adm_prm_txt_select_level')), $aInputLevels['values']);
  255. $sContent .= $oForm->genRow($aInputLevels);
  256. if($this->iLevel == 0)
  257. return $sContent;
  258. $aInputModules = array(
  259. 'type' => 'select',
  260. 'name' => 'module',
  261. 'attrs' => array(
  262. 'id' => 'bx-grid-module-' . $this->_sObject,
  263. 'aria-label' => _t('_adm_grid_lbl_module'),
  264. 'onChange' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.onChangeFilter()',
  265. 'onBlur' => 'javascript:' . $sJsObject . '.onChangeFilter()',
  266. ),
  267. 'value' => '',
  268. 'values' => $this->getModules(false)
  269. );
  270. $aInputModules['values'] = array_merge(array('' => _t('_adm_prm_txt_all_modules')), $aInputModules['values']);
  271. $aCounter = array();
  272. $this->oDb->getActions(array('type' => 'counter_by_modules'), $aCounter, false);
  273. foreach($aInputModules['values'] as $sKey => $sValue)
  274. if(isset($aCounter[$sKey]))
  275. $aInputModules['values'][$sKey] = $aInputModules['values'][$sKey] . " (" . $aCounter[$sKey] . ")";
  276. $sContent .= $oForm->genRow($aInputModules);
  277. $aInputSearch = array(
  278. 'type' => 'text',
  279. 'name' => 'keyword',
  280. 'attrs' => array(
  281. 'id' => 'bx-grid-search-' . $this->_sObject,
  282. 'aria-label' => _t('_adm_grid_lbl_search'),
  283. 'onKeyup' => 'javascript:$(this).off(\'keyup\'); ' . $this->getJsObject() . '.onChangeFilter()'
  284. )
  285. );
  286. $sContent .= $oForm->genRow($aInputSearch);
  287. return $sContent;
  288. }
  289. }
  290. /** @} */