BxBaseStudioPermissionsActions.php 12 KB

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