1
0

BxBaseModGeneralGridAdministration.php 9.6 KB

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