1
0

BxBaseStudioPermissionsActions.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <?php defined('BX_DOL') or die('hack attempt');
  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. bx_import('BxDolStudioPermissionsActions');
  11. bx_import('BxTemplStudioFormView');
  12. class BxBaseStudioPermissionsActions extends BxDolStudioPermissionsActions
  13. {
  14. function __construct($aOptions, $oTemplate = false)
  15. {
  16. parent::__construct($aOptions, $oTemplate);
  17. $this->_aOptions['actions_single']['options']['attr']['title'] = _t('_adm_prm_btn_actions_options');
  18. }
  19. public function performActionEnable()
  20. {
  21. $aIds = bx_get('ids');
  22. $bEnable = (int)bx_get('checked');
  23. if(!$aIds || !is_array($aIds)) {
  24. $this->_echoResultJson(array());
  25. exit;
  26. }
  27. $aResultIds = array();
  28. foreach($aIds as $mixedId) {
  29. if(strpos($mixedId, $this->sParamsDivider) !== false)
  30. list($this->iLevel, $iId) = explode($this->sParamsDivider, urldecode($mixedId));
  31. if($this->oDb->switchAction($this->iLevel, $iId, $bEnable))
  32. $aResultIds[] = $iId;
  33. }
  34. $sAction = $bEnable ? 'enable' : 'disable';
  35. echo $this->_echoResultJson(array(
  36. $sAction => $aResultIds,
  37. ));
  38. }
  39. public function performActionOptions()
  40. {
  41. if((int)$this->iLevel == 0)
  42. $this->iLevel = (int)bx_get('IDLevel');
  43. $aIds = bx_get('ids');
  44. if(!$aIds || !is_array($aIds)) {
  45. $iId = (int)bx_get('IDAction');
  46. if(!$iId) {
  47. $this->_echoResultJson(array());
  48. exit;
  49. }
  50. $aIds = array($iId);
  51. }
  52. $sAction = 'options';
  53. $iId = $aIds[0];
  54. if(strpos($iId, $this->sParamsDivider) !== false)
  55. list($this->iLevel, $iId) = explode($this->sParamsDivider, urldecode($iId));
  56. $aOption = array();
  57. $iOption = $this->oDb->getOptions(array('type' => 'by_level_action_ids', 'level_id' => $this->iLevel, 'action_id' => $iId), $aOption);
  58. if($iOption != 1 || empty($aOption)) {
  59. $this->_echoResultJson(array());
  60. exit;
  61. }
  62. $aForm = array(
  63. 'form_attrs' => array(
  64. 'id' => 'adm-prm-action-options',
  65. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  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 = array();
  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. $this->oDb->updateOptions((int)$oForm->getCleanValue('IDLevel'), (int)$oForm->getCleanValue('IDAction'), $aUpdate);
  174. } else {
  175. bx_import('BxTemplStudioFunctions');
  176. $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(
  177. 'form_id' => $aForm['form_attrs']['id'],
  178. 'form' => $oForm->getCode(true),
  179. 'object' => $this->_sObject,
  180. 'action' => $sAction
  181. )));
  182. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  183. }
  184. }
  185. function getJsObject()
  186. {
  187. return 'oBxDolStudioPermissionsActions';
  188. }
  189. function getCode($isDisplayHeader = true)
  190. {
  191. return $this->_oTemplate->parseHtmlByName('prm_actions.html', array(
  192. 'content' => parent::getCode($isDisplayHeader),
  193. 'js_object' => $this->getJsObject(),
  194. 'grid_object' => $this->_sObject,
  195. 'params_divider' => $this->sParamsDivider
  196. ));
  197. }
  198. protected function _addJsCss()
  199. {
  200. parent::_addJsCss();
  201. $this->_oTemplate->addJs(array('jquery.form.min.js', 'permissions_actions.js'));
  202. bx_import('BxTemplStudioFormView');
  203. $oForm = new BxTemplStudioFormView(array());
  204. $oForm->addCssJs();
  205. }
  206. protected function _getCellSwitcher($mixedValue, $sKey, $aField, $aRow)
  207. {
  208. if($this->iLevel == 0)
  209. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  210. $aRow[$this->_aOptions['field_id']] = urlencode($this->iLevel . $this->sParamsDivider . $aRow[$this->_aOptions['field_id']]);
  211. return parent::_getCellSwitcher($mixedValue, $sKey, $aField, $aRow);
  212. }
  213. protected function _getCellDesc($mixedValue, $sKey, $aField, $aRow)
  214. {
  215. $mixedValue = bx_process_output(_t($aRow['Desc']));
  216. $mixedValue = $this->_limitMaxLength($mixedValue, $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  217. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  218. }
  219. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  220. {
  221. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['Module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  222. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  223. }
  224. protected function _getActionOptions ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  225. {
  226. $a['attr']['bx_grid_action_data'] = urlencode($this->iLevel . $this->sParamsDivider . $a['attr']['bx_grid_action_data']);
  227. return parent::_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  228. }
  229. protected function _getFilterControls ()
  230. {
  231. parent::_getFilterControls();
  232. $sContent = "";
  233. bx_import('BxTemplStudioFormView');
  234. $oForm = new BxTemplStudioFormView(array());
  235. $aInputLevels = array(
  236. 'type' => 'select',
  237. 'name' => 'level',
  238. 'attrs' => array(
  239. 'id' => 'bx-grid-level-' . $this->_sObject,
  240. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeLevel()'
  241. ),
  242. 'value' => 'id-' . $this->iLevel,
  243. 'values' => array()
  244. );
  245. $aLevels = $aCounter = array();
  246. $this->oDb->getLevels(array('type' => 'all'), $aLevels, false);
  247. $this->oDb->getActions(array('type' => 'counter_by_levels'), $aCounter, false);
  248. foreach($aLevels as $aLevel)
  249. $aInputLevels['values']['id-' . $aLevel['id']] = _t($aLevel['name']) . " (" . (isset($aCounter[$aLevel['id']]) ? $aCounter[$aLevel['id']] : "0") . ")";
  250. asort($aInputLevels['values']);
  251. $aInputLevels['values'] = array_merge(array('id-0' => _t('_adm_prm_txt_select_level')), $aInputLevels['values']);
  252. $sContent .= $oForm->genRow($aInputLevels);
  253. if($this->iLevel == 0)
  254. return $sContent;
  255. $aInputModules = array(
  256. 'type' => 'select',
  257. 'name' => 'module',
  258. 'attrs' => array(
  259. 'id' => 'bx-grid-module-' . $this->_sObject,
  260. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  261. ),
  262. 'value' => '',
  263. 'values' => $this->getModules(false)
  264. );
  265. $aInputModules['values'] = array_merge(array('' => _t('_adm_prm_txt_all_modules')), $aInputModules['values']);
  266. $aCounter = array();
  267. $this->oDb->getActions(array('type' => 'counter_by_modules'), $aCounter, false);
  268. foreach($aInputModules['values'] as $sKey => $sValue)
  269. if(isset($aCounter[$sKey]))
  270. $aInputModules['values'][$sKey] = $aInputModules['values'][$sKey] . " (" . $aCounter[$sKey] . ")";
  271. $sContent .= $oForm->genRow($aInputModules);
  272. $aInputSearch = array(
  273. 'type' => 'text',
  274. 'name' => 'keyword',
  275. 'attrs' => array(
  276. 'id' => 'bx-grid-search-' . $this->_sObject,
  277. 'onKeyup' => 'javascript:$(this).off(\'keyup\'); ' . $this->getJsObject() . '.onChangeFilter()'
  278. )
  279. );
  280. $sContent .= $oForm->genRow($aInputSearch);
  281. return $sContent;
  282. }
  283. }
  284. /** @} */