BxBaseModGeneralGridAdministration.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. * @{
  9. */
  10. define('BX_DOL_MANAGE_TOOLS_ADMINISTRATION', 'administration');
  11. define('BX_DOL_MANAGE_TOOLS_COMMON', 'common');
  12. class BxBaseModGeneralGridAdministration extends BxTemplGrid
  13. {
  14. protected $MODULE;
  15. protected $_oModule;
  16. protected $_sManageType;
  17. protected $_sParamsDivider;
  18. protected $_sStatusField;
  19. protected $_aStatusValues;
  20. public function __construct ($aOptions, $oTemplate = false)
  21. {
  22. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  23. if(!$oTemplate)
  24. $oTemplate = $this->_oModule->_oTemplate;
  25. parent::__construct ($aOptions, $oTemplate);
  26. $this->_sManageType = BX_DOL_MANAGE_TOOLS_ADMINISTRATION;
  27. $this->_sParamsDivider = '#-#';
  28. $this->_aStatusValues = array('active');
  29. $this->_sDefaultSortingOrder = 'DESC';
  30. }
  31. public function performActionDelete($aParams = array())
  32. {
  33. $CNF = &$this->_oModule->_oConfig->CNF;
  34. $iAffected = 0;
  35. $aIds = bx_get('ids');
  36. if(!$aIds || !is_array($aIds)) {
  37. echoJson(array());
  38. exit;
  39. }
  40. $aIdsAffected = array ();
  41. foreach($aIds as $iId) {
  42. $aContentInfo = $this->_getContentInfo($iId);
  43. if($this->_oModule->checkAllowedDelete($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
  44. continue;
  45. if(!$this->_doDelete($iId, $aParams))
  46. continue;
  47. if(!$this->_onDelete($iId, $aParams))
  48. continue;
  49. $this->_oModule->checkAllowedDelete($aContentInfo, true);
  50. $aIdsAffected[] = $iId;
  51. $iAffected++;
  52. }
  53. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($CNF['T']['grid_action_err_delete'])));
  54. }
  55. public function performActionClearReports($aParams = array())
  56. {
  57. $CNF = &$this->_oModule->_oConfig->CNF;
  58. $iAffected = 0;
  59. $aIds = bx_get('ids');
  60. if(!$aIds || !is_array($aIds)) {
  61. echoJson(array());
  62. exit;
  63. }
  64. $aIdsAffected = array ();
  65. foreach($aIds as $iId) {
  66. if (isset($CNF['OBJECT_REPORTS'])){
  67. $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $iId);
  68. $oReport->actionClearReport();
  69. $aIdsAffected[] = $iId;
  70. $iAffected++;
  71. }
  72. }
  73. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($CNF['T']['grid_action_err_clear_reports'])));
  74. }
  75. protected function _getActionAuditContent($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  76. {
  77. if (!getParam('sys_audit_enable') || getParam('sys_audit_acl_levels') == '')
  78. return;
  79. $iProfileId = bx_get_logged_profile_id();
  80. if (!BxDolAcl::getInstance()->isMemberLevelInSet(explode(',', getParam('sys_audit_acl_levels')), $iProfileId))
  81. return;
  82. $CNF = &$this->_oModule->_oConfig->CNF;
  83. $sUrl = BX_DOL_URL_ROOT . 'page/audit-administration?module=' . $this->_oModule->getName() . '&content_id=' . $aRow[$CNF['FIELD_ID']];
  84. $a['attr'] = array_merge($a['attr'], array(
  85. "onclick" => "window.open('" . $sUrl . "','_audit');"
  86. ));
  87. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  88. }
  89. protected function _getActionDelete($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  90. {
  91. if($this->_sManageType == BX_DOL_MANAGE_TOOLS_ADMINISTRATION && !$this->_oModule->_isAdministrator())
  92. return '';
  93. return $this->_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  94. }
  95. protected function _getActionSettings($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  96. {
  97. $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
  98. $sMenuName = $this->_oModule->_oConfig->CNF['OBJECT_MENU_MANAGE_TOOLS'];
  99. $oMenu = BxDolMenu::getObjectInstance($sMenuName);
  100. $oMenu->setContentId($aRow['id']);
  101. $sMenu = $oMenu->getCode();
  102. if(empty($sMenu))
  103. return '';
  104. $a['attr'] = array_merge($a['attr'], array(
  105. "bx-popup-id" => $sMenuName . "-" . $aRow['id'],
  106. "onclick" => "$(this).off('click'); " . $sJsObject . ".onClickSettings('" . $sMenuName . "', this);"
  107. ));
  108. return $this->_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  109. }
  110. protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues)
  111. {
  112. if(empty($sFilterName) || empty($aFilterValues))
  113. return '';
  114. $CNF = &$this->_oModule->_oConfig->CNF;
  115. $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
  116. foreach($aFilterValues as $sKey => $sValue)
  117. $aFilterValues[$sKey] = _t($sValue);
  118. $aInputModules = array(
  119. 'type' => 'select',
  120. 'name' => $sFilterName,
  121. 'attrs' => array(
  122. 'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
  123. 'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
  124. ),
  125. 'value' => $sFilterValue,
  126. 'values' => array_merge(array('' => _t($CNF['T']['filter_item_select_one_' . $sFilterName])), $aFilterValues)
  127. );
  128. $oForm = new BxTemplFormView(array());
  129. return $oForm->genRow($aInputModules);
  130. }
  131. protected function _getSearchInput()
  132. {
  133. $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
  134. $aInputSearch = array(
  135. 'type' => 'text',
  136. 'name' => 'search',
  137. 'attrs' => array(
  138. 'id' => 'bx-grid-search-' . $this->_sObject,
  139. 'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.onChangeFilter(this)',
  140. 'onBlur' => 'javascript:' . $sJsObject . '.onChangeFilter(this)',
  141. )
  142. );
  143. $oForm = new BxTemplFormView(array());
  144. return $oForm->genRow($aInputSearch);
  145. }
  146. protected function _getContentInfo($iId)
  147. {
  148. return $this->_oModule->_oDb->getContentInfoById($iId);
  149. }
  150. protected function _getProfileObject($iId)
  151. {
  152. return BxDolProfile::getInstanceMagic($iId);
  153. }
  154. protected function _getManageAccountUrl($sFilter = '')
  155. {
  156. $sModuleAccounts = 'bx_accounts';
  157. if(!BxDolModuleQuery::getInstance()->isEnabledByName($sModuleAccounts))
  158. return '';
  159. $sTypeUpc = strtoupper($this->_sManageType);
  160. $oModuleAccounts = BxDolModule::getInstance($sModuleAccounts);
  161. if(!$oModuleAccounts || empty($oModuleAccounts->_oConfig->CNF['URL_MANAGE_' . $sTypeUpc]))
  162. return '';
  163. $sLink = $oModuleAccounts->_oConfig->CNF['URL_MANAGE_' . $sTypeUpc];
  164. $sLink = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($sLink);
  165. if(!empty($sFilter))
  166. $sLink = bx_append_url_params($sLink, array('filter' => $sFilter));
  167. return $sLink;
  168. }
  169. protected function _enable ($mixedId, $isChecked)
  170. {
  171. $CNF = &$this->_oModule->_oConfig->CNF;
  172. $mixedResult = parent::_enable($mixedId, $isChecked);
  173. if((int)$mixedResult > 0) {
  174. if(!empty($CNF['FIELD_CHANGED']))
  175. $this->_oModule->_oDb->updateEntriesBy(array($CNF['FIELD_CHANGED'] => time()), array($this->_aOptions['field_id'] => $mixedId));
  176. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($mixedId);
  177. $this->_oModule->alertAfterEdit($aContentInfo);
  178. $iContextId = isset($CNF['FIELD_ALLOW_VIEW_TO']) && (!empty($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) ? - $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] : 0;
  179. $AuditParams = array(
  180. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  181. 'context_profile_id' => $iContextId,
  182. 'content_info_object' => isset($CNF['OBJECT_CONTENT_INFO']) ? $CNF['OBJECT_CONTENT_INFO'] : '',
  183. 'data' => $aContentInfo
  184. );
  185. if ($iContextId > 0)
  186. $AuditParams['context_profile_title'] = BxDolProfile::getInstance($iContextId)->getDisplayName();
  187. bx_audit(
  188. $mixedId,
  189. $this->_oModule->getName(),
  190. ($isChecked ? '_sys_audit_action_content_enabled': '_sys_audit_action_content_disabled'),
  191. $AuditParams
  192. );
  193. }
  194. return $mixedResult;
  195. }
  196. protected function _doDelete($iId, $aParams = array())
  197. {
  198. return $this->_oModule->serviceDeleteEntity($iId) == '';
  199. }
  200. protected function _onDelete($iId, $aParams = array())
  201. {
  202. return true;
  203. }
  204. protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow)
  205. {
  206. $CNF = &$this->_oModule->_oConfig->CNF;
  207. if(isset($aRow[$this->_sStatusField]) && !in_array($aRow[$this->_sStatusField], $this->_aStatusValues)) {
  208. $sStatusKey = '_sys_status_' . $aRow[$this->_sStatusField];
  209. if(!empty($CNF['T']['txt_status_' . $aRow[$this->_sStatusField]]))
  210. $sStatusKey = $CNF['T']['txt_status_' . $aRow[$this->_sStatusField]];
  211. return parent::_getCellDefault(_t($sStatusKey), $sKey, $aField, $aRow);
  212. }
  213. return parent::_getCellSwitcher ($mixedValue, $sKey, $aField, $aRow);
  214. }
  215. protected function _getCellHeaderReports ($sKey, $aField)
  216. {
  217. $s = parent::_getCellHeaderDefault($sKey, $aField);
  218. return preg_replace ('/<a(.*?)>(.*?)<\/a>/', '<a$1 title="' . bx_html_attribute(_t('_sys_txt_reports_title')) . '"><i class="sys-icon exclamation-triangle"></i></a>', $s);
  219. }
  220. protected function _getCellReports($mixedValue, $sKey, $aField, $aRow)
  221. {
  222. if ($mixedValue == 0){
  223. $mixedValue = '';
  224. }
  225. else{
  226. $CNF = &$this->_oModule->_oConfig->CNF;
  227. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aRow[$CNF['FIELD_ID']]) : null;
  228. if ($oReports){
  229. $mixedValue = $oReports->getCounter().$oReports->getJsScript();
  230. }
  231. }
  232. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  233. }
  234. }
  235. /** @} */