| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup BaseGeneral Base classes for modules
- * @ingroup UnaModules
- * @{
- */
- define('BX_DOL_MANAGE_TOOLS_ADMINISTRATION', 'administration');
- define('BX_DOL_MANAGE_TOOLS_COMMON', 'common');
- class BxBaseModGeneralGridAdministration extends BxTemplGrid
- {
- protected $MODULE;
- protected $_oModule;
- protected $_sManageType;
- protected $_sParamsDivider;
- public function __construct ($aOptions, $oTemplate = false)
- {
- $this->_oModule = BxDolModule::getInstance($this->MODULE);
- if(!$oTemplate)
- $oTemplate = $this->_oModule->_oTemplate;
- parent::__construct ($aOptions, $oTemplate);
- $this->_sManageType = BX_DOL_MANAGE_TOOLS_ADMINISTRATION;
- $this->_sParamsDivider = '#-#';
- $this->_sDefaultSortingOrder = 'DESC';
- }
- public function performActionDelete($aParams = array())
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $iAffected = 0;
- $aIds = bx_get('ids');
- if(!$aIds || !is_array($aIds)) {
- echoJson(array());
- exit;
- }
- $aIdsAffected = array ();
- foreach($aIds as $iId) {
- $aContentInfo = $this->_getContentInfo($iId);
- if($this->_oModule->checkAllowedDelete($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
- continue;
- if(!$this->_doDelete($iId, $aParams))
- continue;
- if(!$this->_onDelete($iId, $aParams))
- continue;
- $this->_oModule->checkAllowedDelete($aContentInfo, true);
- $aIdsAffected[] = $iId;
- $iAffected++;
- }
- echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($CNF['T']['grid_action_err_delete'])));
- }
-
- public function performActionClearReports($aParams = array())
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $iAffected = 0;
- $aIds = bx_get('ids');
- if(!$aIds || !is_array($aIds)) {
- echoJson(array());
- exit;
- }
- $aIdsAffected = array ();
- foreach($aIds as $iId) {
- if (isset($CNF['OBJECT_REPORTS'])){
- $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $iId);
- $oReport->actionClearReport();
- $aIdsAffected[] = $iId;
- $iAffected++;
- }
- }
- echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($CNF['T']['grid_action_err_clear_reports'])));
- }
- protected function _getActionAuditContent($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
- {
- if (!getParam('sys_audit_enable') || getParam('sys_audit_acl_levels') == '')
- return;
-
- $iProfileId = bx_get_logged_profile_id();
- if (!BxDolAcl::getInstance()->isMemberLevelInSet(explode(',', getParam('sys_audit_acl_levels')), $iProfileId))
- return;
-
- $CNF = &$this->_oModule->_oConfig->CNF;
- $sUrl = BX_DOL_URL_ROOT . 'page/audit-administration?module=' . $this->_oModule->getName() . '&content_id=' . $aRow[$CNF['FIELD_ID']];
- $a['attr'] = array_merge($a['attr'], array(
- "onclick" => "window.open('" . $sUrl . "','_audit');"
- ));
- return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
- }
- protected function _getActionDelete($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
- {
- if($this->_sManageType == BX_DOL_MANAGE_TOOLS_ADMINISTRATION && $this->_oModule->checkAllowedEditAnyEntry() !== CHECK_ACTION_RESULT_ALLOWED)
- return '';
- return $this->_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
- }
- protected function _getActionSettings($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
- {
- $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
- $sMenuName = $this->_oModule->_oConfig->CNF['OBJECT_MENU_MANAGE_TOOLS'];
- $oMenu = BxDolMenu::getObjectInstance($sMenuName);
- $oMenu->setContentId($aRow['id']);
- $sMenu = $oMenu->getCode();
- if(empty($sMenu))
- return '';
- $a['attr'] = array_merge($a['attr'], array(
- "bx-popup-id" => $sMenuName . "-" . $aRow['id'],
- "onclick" => "$(this).off('click'); " . $sJsObject . ".onClickSettings('" . $sMenuName . "', this);"
- ));
- return $this->_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
- }
- protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues)
- {
- if(empty($sFilterName) || empty($aFilterValues))
- return '';
- $CNF = &$this->_oModule->_oConfig->CNF;
- $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
- foreach($aFilterValues as $sKey => $sValue)
- $aFilterValues[$sKey] = _t($sValue);
- $aInputModules = array(
- 'type' => 'select',
- 'name' => $sFilterName,
- 'attrs' => array(
- 'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
- 'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
- ),
- 'value' => $sFilterValue,
- 'values' => array_merge(array('' => _t($CNF['T']['filter_item_select_one_' . $sFilterName])), $aFilterValues)
- );
- $oForm = new BxTemplFormView(array());
- return $oForm->genRow($aInputModules);
- }
- protected function _getSearchInput()
- {
- $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
- $aInputSearch = array(
- 'type' => 'text',
- 'name' => 'search',
- 'attrs' => array(
- 'id' => 'bx-grid-search-' . $this->_sObject,
- 'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.onChangeFilter(this)',
- 'onBlur' => 'javascript:' . $sJsObject . '.onChangeFilter(this)',
- )
- );
- $oForm = new BxTemplFormView(array());
- return $oForm->genRow($aInputSearch);
- }
- protected function _getContentInfo($iId)
- {
- return $this->_oModule->_oDb->getContentInfoById($iId);
- }
-
- protected function _getProfileObject($iId)
- {
- return BxDolProfile::getInstanceMagic($iId);
- }
- protected function _getManageAccountUrl($sFilter = '')
- {
- $sModuleAccounts = 'bx_accounts';
- if(!BxDolModuleQuery::getInstance()->isEnabledByName($sModuleAccounts))
- return '';
- $sTypeUpc = strtoupper($this->_sManageType);
- $oModuleAccounts = BxDolModule::getInstance($sModuleAccounts);
- if(!$oModuleAccounts || empty($oModuleAccounts->_oConfig->CNF['URL_MANAGE_' . $sTypeUpc]))
- return '';
- $sLink = $oModuleAccounts->_oConfig->CNF['URL_MANAGE_' . $sTypeUpc];
- $sLink = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($sLink);
-
- if(!empty($sFilter))
- $sLink = bx_append_url_params($sLink, array('filter' => $sFilter));
- return $sLink;
- }
- protected function _enable ($mixedId, $isChecked)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $mixedResult = parent::_enable($mixedId, $isChecked);
- if((int)$mixedResult > 0) {
- if(!empty($CNF['FIELD_CHANGED']))
- $this->_oModule->_oDb->updateEntriesBy(array($CNF['FIELD_CHANGED'] => time()), array($this->_aOptions['field_id'] => $mixedId));
- $aContentInfo = $this->_oModule->_oDb->getContentInfoById($mixedId);
- $this->_oModule->alertAfterEdit($aContentInfo);
-
- $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;
- $AuditParams = array(
- 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
- 'context_profile_id' => $iContextId,
- 'content_info_object' => isset($CNF['OBJECT_CONTENT_INFO']) ? $CNF['OBJECT_CONTENT_INFO'] : '',
- 'data' => $aContentInfo
- );
- if ($iContextId > 0)
- $AuditParams['context_profile_title'] = BxDolProfile::getInstance($iContextId)->getDisplayName();
-
- bx_audit(
- $mixedId,
- $this->_oModule->getName(),
- ($isChecked ? '_sys_audit_action_content_enabled': '_sys_audit_action_content_disabled'),
- $AuditParams
- );
- }
- return $mixedResult;
- }
- protected function _doDelete($iId, $aParams = array())
- {
- return $this->_oModule->serviceDeleteEntity($iId) == '';
- }
- protected function _onDelete($iId, $aParams = array())
- {
- return true;
- }
- protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if(isset($CNF['FIELD_STATUS']) && isset($aRow[$CNF['FIELD_STATUS']]) && !in_array($aRow[$CNF['FIELD_STATUS']], array('active', 'hidden'))) {
- $sStatusKey = '_sys_status_' . $aRow[$CNF['FIELD_STATUS']];
- if(!empty($CNF['T']['txt_status_' . $aRow[$CNF['FIELD_STATUS']]]))
- $sStatusKey = $CNF['T']['txt_status_' . $aRow[$CNF['FIELD_STATUS']]];
- return parent::_getCellDefault(_t($sStatusKey), $sKey, $aField, $aRow);
- }
- return parent::_getCellSwitcher ($mixedValue, $sKey, $aField, $aRow);
- }
- protected function _getCellHeaderReports ($sKey, $aField)
- {
- $s = parent::_getCellHeaderDefault($sKey, $aField);
- 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);
- }
-
- protected function _getCellReports($mixedValue, $sKey, $aField, $aRow)
- {
- if ($mixedValue == 0){
- $mixedValue = '';
- }
- else{
- $CNF = &$this->_oModule->_oConfig->CNF;
- $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aRow[$CNF['FIELD_ID']]) : null;
- if ($oReports){
- $mixedValue = $oReports->getCounter().$oReports->getJsScript();
- }
- }
- return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
- }
- }
- /** @} */
|