BxBaseModProfileGridAdministration.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModProfileGridAdministration extends BxBaseModGeneralGridAdministration
  12. {
  13. protected $_sFilter1Name;
  14. protected $_sFilter1Value;
  15. protected $_aFilter1Values;
  16. public function __construct ($aOptions, $oTemplate = false)
  17. {
  18. parent::__construct ($aOptions, $oTemplate);
  19. $CNF = &$this->_oModule->_oConfig->CNF;
  20. $this->_aQueryReset = array($this->_aOptions['paginate_get_start'], $this->_aOptions['paginate_get_per_page']);
  21. $this->_sStatusField = !empty($CNF['FIELD_STATUS']) ? $CNF['FIELD_STATUS'] : 'status';
  22. $this->_aStatusValues = array('active', 'pending', 'suspended');
  23. $this->_sFilter1Name = 'filter1';
  24. $this->_aFilter1Values = array(
  25. 'active' => $CNF['T']['filter_item_active'],
  26. 'pending' => $CNF['T']['filter_item_pending'],
  27. 'suspended' => $CNF['T']['filter_item_suspended'],
  28. );
  29. $sFilter1 = bx_get($this->_sFilter1Name);
  30. if(!empty($sFilter1)) {
  31. $this->_sFilter1Value = bx_process_input($sFilter1);
  32. $this->_aQueryAppend[$this->_sFilter1Name] = $this->_sFilter1Value;
  33. }
  34. }
  35. public function performActionSetAclLevel()
  36. {
  37. $oMenu = BxDolMenu::getObjectInstance('sys_set_acl_level');
  38. $aIds = bx_get('ids');
  39. if(!$aIds || !is_array($aIds) || !$oMenu) {
  40. echoJson(array());
  41. return;
  42. }
  43. $aIdsResult = array();
  44. foreach($aIds as $iId) {
  45. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iId);
  46. if($this->_oModule->checkAllowedSetMembership($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
  47. continue;
  48. $aIdsResult[] = $this->_getProfileId($iId);
  49. }
  50. if(empty($aIdsResult)) {
  51. echoJson(array());
  52. return;
  53. }
  54. if(count($aIdsResult) == 1)
  55. $aIdsResult = $aIdsResult[0];
  56. $sContent = $this->_oTemplate->parseHtmlByName('set_acl_popup.html', array(
  57. 'content' => $oMenu->getCode($aIdsResult)
  58. ));
  59. $sContent = BxTemplFunctions::getInstance()->transBox($this->_oModule->_oConfig->getName() . 'set_acl_level_popup', $sContent);
  60. echoJson(array('popup' => $sContent));
  61. }
  62. public function performActionDeleteWithContent()
  63. {
  64. $this->performActionDelete(array('with_content' => true));
  65. }
  66. protected function _getActionSetAclLevel($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  67. {
  68. if($this->_sManageType == BX_DOL_MANAGE_TOOLS_ADMINISTRATION && $this->_oModule->checkAllowedSetMembership($aRow) !== CHECK_ACTION_RESULT_ALLOWED)
  69. return '';
  70. return $this->_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  71. }
  72. protected function _getActionAuditProfile($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  73. {
  74. if (!getParam('sys_audit_enable') || getParam('sys_audit_acl_levels') == '')
  75. return;
  76. $iProfileId = bx_get_logged_profile_id();
  77. if (!BxDolAcl::getInstance()->isMemberLevelInSet(explode(',', getParam('sys_audit_acl_levels')), $iProfileId))
  78. return;
  79. $CNF = &$this->_oModule->_oConfig->CNF;
  80. $oProfile = $this->_getProfileObject($aRow[$CNF['FIELD_ID']]);
  81. $sUrl = BX_DOL_URL_ROOT . 'page/audit-administration?profile=' . $oProfile->id();
  82. $a['attr'] = array_merge($a['attr'], array(
  83. "onclick" => "window.open('" . $sUrl . "','_audit');"
  84. ));
  85. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  86. }
  87. protected function _getActionDeleteWithContent($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  88. {
  89. if($this->_sManageType != BX_DOL_MANAGE_TOOLS_ADMINISTRATION || !$this->_oModule->_isAdministrator())
  90. return '';
  91. return $this->_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  92. }
  93. protected function _switcherChecked2State($isChecked)
  94. {
  95. return $isChecked ? 'active' : 'suspended';
  96. }
  97. protected function _switcherState2Checked($mixedState)
  98. {
  99. return 'active' == $mixedState ? true : false;
  100. }
  101. protected function _enable ($mixedId, $isChecked)
  102. {
  103. $oProfile = $this->_getProfileObject($mixedId);
  104. if($oProfile instanceof BxDolProfileUndefined)
  105. return false;
  106. $iAction = BX_PROFILE_ACTION_MANUAL;
  107. $bSendEmailNotification = $this->_oModule->serviceActAsProfile();
  108. return $isChecked ? $oProfile->activate($iAction, 0, $bSendEmailNotification) : $oProfile->suspend($iAction, 0, $bSendEmailNotification);
  109. }
  110. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  111. {
  112. $iFilterPartsCount = substr_count($sFilter, $this->_sParamsDivider);
  113. switch ($iFilterPartsCount) {
  114. case 1:
  115. list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  116. break;
  117. case 2:
  118. list($this->_sFilter1Value, $this->_sFilter2Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  119. break;
  120. }
  121. if(!empty($this->_sFilter1Value))
  122. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `tp`.`status`=?", $this->_sFilter1Value);
  123. return $this->_getDataSqlInner($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  124. }
  125. protected function _getDataSqlInner($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  126. {
  127. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  128. }
  129. //--- Layout methods ---//
  130. protected function _getFilterControls()
  131. {
  132. parent::_getFilterControls();
  133. return $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
  134. }
  135. protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow)
  136. {
  137. if (isset($aRow['profile_id']))
  138. if (!$this->_oModule->isAllowDeleteOrDisable(bx_get_logged_profile_id(), $aRow['profile_id']))
  139. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  140. return parent::_getCellSwitcher ($mixedValue, $sKey, $aField, $aRow);
  141. }
  142. protected function _getCellFullname($mixedValue, $sKey, $aField, $aRow)
  143. {
  144. $oProfile = $this->_getProfileObject($aRow['id']);
  145. return parent::_getCellDefault($oProfile->getUnit(), $sKey, $aField, $aRow);
  146. }
  147. protected function _getCellLastOnline($mixedValue, $sKey, $aField, $aRow)
  148. {
  149. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  150. }
  151. protected function _getCellAddedTs($mixedValue, $sKey, $aField, $aRow)
  152. {
  153. return $this->_getCellLastOnline($mixedValue, $sKey, $aField, $aRow);
  154. }
  155. protected function _getCellAccount($mixedValue, $sKey, $aField, $aRow)
  156. {
  157. $sManageAccountUrl = $this->_getManageAccountUrl($aRow[$sKey]);
  158. if(!empty($sManageAccountUrl)) {
  159. $mixedValue = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  160. 'href' => $sManageAccountUrl,
  161. 'title' => _t($this->_oModule->_oConfig->CNF['T']['grid_txt_account_manager']),
  162. 'content' => $mixedValue,
  163. 'class' => ''
  164. ));
  165. }
  166. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  167. }
  168. protected function _getProfileObject($iId)
  169. {
  170. return $this->_oModule->getProfileObject($iId);
  171. }
  172. protected function _getProfileId($iId)
  173. {
  174. return $this->_getProfileObject($iId)->id();
  175. }
  176. protected function _doDelete($iId, $aParams = array())
  177. {
  178. $oProfile = $this->_getProfileObject($iId);
  179. if (!$this->_oModule->isAllowDeleteOrDisable(bx_get_logged_profile_id(), $oProfile->id()))
  180. return false;
  181. if($this->_oModule->checkMyself($iId))
  182. return false;
  183. if(isset($aParams['with_content']) && $aParams['with_content'] === true) {
  184. if($oProfile instanceof BxDolProfileUndefined)
  185. return false;
  186. return $oProfile->delete($oProfile->id(), true);
  187. }
  188. return parent::_doDelete($iId, $aParams);
  189. }
  190. }
  191. /** @} */