1
0

BxBaseModProfileGridAdministration.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. protected $_bSetAclWithDuration;
  17. public function __construct ($aOptions, $oTemplate = false)
  18. {
  19. parent::__construct ($aOptions, $oTemplate);
  20. $CNF = &$this->_oModule->_oConfig->CNF;
  21. $this->_aQueryReset = array($this->_aOptions['paginate_get_start'], $this->_aOptions['paginate_get_per_page']);
  22. $this->_sStatusField = !empty($CNF['FIELD_STATUS']) ? $CNF['FIELD_STATUS'] : 'status';
  23. $this->_aStatusValues = array('active', 'pending', 'suspended');
  24. $this->_sFilter1Name = 'filter1';
  25. $this->_aFilter1Values = array(
  26. 'active' => $CNF['T']['filter_item_active'],
  27. 'pending' => $CNF['T']['filter_item_pending'],
  28. 'suspended' => $CNF['T']['filter_item_suspended'],
  29. );
  30. $sFilter1 = bx_get($this->_sFilter1Name);
  31. if(!empty($sFilter1)) {
  32. $this->_sFilter1Value = bx_process_input($sFilter1);
  33. $this->_aQueryAppend[$this->_sFilter1Name] = $this->_sFilter1Value;
  34. }
  35. $this->_bSetAclWithDuration = true;
  36. }
  37. public function performActionSetAclLevel()
  38. {
  39. $oMenu = BxDolMenu::getObjectInstance('sys_set_acl_level');
  40. $aIds = bx_get('ids');
  41. if(!$aIds || !is_array($aIds) || !$oMenu)
  42. return echoJson([]);
  43. $aIdsResult = [];
  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. return echoJson([]);
  52. if(count($aIdsResult) == 1)
  53. $aIdsResult = $aIdsResult[0];
  54. $oMenu->setWithDuration($this->_bSetAclWithDuration);
  55. $oMenu->setHiddenByDefault(!$this->_bSetAclWithDuration);
  56. $sContent = $oMenu->getCode($aIdsResult);
  57. if(!$this->_bSetAclWithDuration)
  58. $sContent = BxTemplFunctions::getInstance()->transBox($this->_oModule->_oConfig->getName() . 'set_acl_level_popup', $this->_oTemplate->parseHtmlByName('set_acl_popup.html', [
  59. 'content' => $sContent
  60. ]));
  61. echoJson(['popup' => $sContent]);
  62. }
  63. public function performActionManageCf()
  64. {
  65. if(!$this->_oModule->_isModerator())
  66. return echoJson([]);
  67. $sModule = $this->_oModule->_oConfig->getName();
  68. $iContentId = $this->_getId();
  69. if($iContentId === false)
  70. return echoJson([]);
  71. $aProfileInfo = BxDolProfileQuery::getInstance()->getProfileByContentAndType($iContentId, $sModule, true);
  72. if(!$aProfileInfo || !is_array($aProfileInfo))
  73. return echoJson([]);
  74. $sAction = 'manage_cf';
  75. $sForm = 'sys_profile';
  76. $sFormDisplay = 'sys_profile_cf_manage';
  77. $oForm = BxDolForm::getObjectInstance($sForm, $sFormDisplay);
  78. if(!$oForm)
  79. return echoJson([]);
  80. $oForm->setAction(BX_DOL_URL_ROOT . 'grid.php', ['o' => $this->_sObject, 'a' => $sAction, 'id' => $iContentId]);
  81. $oForm->initChecker($aProfileInfo);
  82. if($oForm->isSubmittedAndValid()) {
  83. if(!$oForm->update($aProfileInfo['id']))
  84. $aResult = ['msg' => _t('_sys_txt_error_profile_update')];
  85. else
  86. $aResult = ['msg' => _t('_' . $sFormDisplay . '_successfully_submitted')];
  87. return echoJson($aResult);
  88. }
  89. $sPopupTitle = _t('_' . $sFormDisplay . '_popup');
  90. $sPopupContent = $this->_oTemplate->parseHtmlByName('content_filter_manage_popup.html', [
  91. 'form_id' => $oForm->getId(),
  92. 'form' => $oForm->getCode()
  93. ]);
  94. echoJson(['popup' => [
  95. 'html' => BxTemplFunctions::getInstance()->popupBox($sModule . '_manage_cf_popup', $sPopupTitle, $sPopupContent),
  96. 'options' => [
  97. 'closeOnOuterClick' => false,
  98. 'removeOnClose' => true
  99. ]
  100. ]]);
  101. }
  102. public function performActionDeleteWithContent()
  103. {
  104. $this->performActionDelete(array('with_content' => true));
  105. }
  106. protected function _getActionSetAclLevel($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  107. {
  108. if($this->_sManageType == BX_DOL_MANAGE_TOOLS_ADMINISTRATION && $this->_oModule->checkAllowedSetMembership($aRow) !== CHECK_ACTION_RESULT_ALLOWED)
  109. return '';
  110. return $this->_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  111. }
  112. protected function _getActionManageCf($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  113. {
  114. return '';
  115. }
  116. protected function _getActionAuditProfile($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  117. {
  118. if (!getParam('sys_audit_enable') || getParam('sys_audit_acl_levels') == '')
  119. return;
  120. $iProfileId = bx_get_logged_profile_id();
  121. if (!BxDolAcl::getInstance()->isMemberLevelInSet(explode(',', getParam('sys_audit_acl_levels')), $iProfileId))
  122. return;
  123. $CNF = &$this->_oModule->_oConfig->CNF;
  124. $oProfile = $this->_getProfileObject($aRow[$CNF['FIELD_ID']]);
  125. $sUrl = BX_DOL_URL_ROOT . 'page/audit-administration?profile=' . $oProfile->id();
  126. $a['attr'] = array_merge($a['attr'], array(
  127. "onclick" => "window.open('" . $sUrl . "','_audit');"
  128. ));
  129. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  130. }
  131. protected function _getActionDeleteWithContent($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  132. {
  133. if($this->_sManageType != BX_DOL_MANAGE_TOOLS_ADMINISTRATION || !$this->_oModule->_isAdministrator())
  134. return '';
  135. return $this->_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  136. }
  137. protected function _switcherChecked2State($isChecked)
  138. {
  139. return $isChecked ? 'active' : 'suspended';
  140. }
  141. protected function _switcherState2Checked($mixedState)
  142. {
  143. return 'active' == $mixedState ? true : false;
  144. }
  145. protected function _enable ($mixedId, $isChecked)
  146. {
  147. $oProfile = $this->_getProfileObject($mixedId);
  148. if($oProfile instanceof BxDolProfileUndefined)
  149. return false;
  150. $iAction = BX_PROFILE_ACTION_MANUAL;
  151. $bSendEmailNotification = $this->_oModule->serviceActAsProfile();
  152. return $isChecked ? $oProfile->activate($iAction, 0, $bSendEmailNotification) : $oProfile->suspend($iAction, 0, $bSendEmailNotification);
  153. }
  154. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  155. {
  156. $aFilterParts = explode($this->_sParamsDivider, $sFilter);
  157. switch (substr_count($sFilter, $this->_sParamsDivider)) {
  158. case 1:
  159. list($this->_sFilter1Value, $sFilter) = $aFilterParts;
  160. break;
  161. case 2:
  162. list($this->_sFilter1Value, $this->_sFilter2Value, $sFilter) = $aFilterParts;
  163. break;
  164. }
  165. if(!empty($this->_sFilter1Value))
  166. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `tp`.`status`=?", $this->_sFilter1Value);
  167. return $this->_getDataSqlInner($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  168. }
  169. protected function _getDataSqlInner($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  170. {
  171. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  172. }
  173. //--- Layout methods ---//
  174. protected function _getFilterControls()
  175. {
  176. parent::_getFilterControls();
  177. return $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
  178. }
  179. protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow)
  180. {
  181. if (isset($aRow['profile_id']))
  182. if (!$this->_oModule->isAllowDeleteOrDisable(bx_get_logged_profile_id(), $aRow['profile_id']))
  183. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  184. return parent::_getCellSwitcher ($mixedValue, $sKey, $aField, $aRow);
  185. }
  186. protected function _getCellFullname($mixedValue, $sKey, $aField, $aRow)
  187. {
  188. $oProfile = $this->_getProfileObject($aRow['id']);
  189. return parent::_getCellDefault($oProfile->getUnit(), $sKey, $aField, $aRow);
  190. }
  191. protected function _getCellLastOnline($mixedValue, $sKey, $aField, $aRow)
  192. {
  193. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  194. }
  195. protected function _getCellAddedTs($mixedValue, $sKey, $aField, $aRow)
  196. {
  197. return $this->_getCellLastOnline($mixedValue, $sKey, $aField, $aRow);
  198. }
  199. protected function _getCellAccount($mixedValue, $sKey, $aField, $aRow)
  200. {
  201. $sManageAccountUrl = $this->_getManageAccountUrl($aRow[$sKey]);
  202. if(!empty($sManageAccountUrl)) {
  203. $mixedValue = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  204. 'href' => $sManageAccountUrl,
  205. 'title' => _t($this->_oModule->_oConfig->CNF['T']['grid_txt_account_manager']),
  206. 'content' => $mixedValue,
  207. 'class' => ''
  208. ));
  209. }
  210. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  211. }
  212. protected function _getProfileObject($iId)
  213. {
  214. return $this->_oModule->getProfileObject($iId);
  215. }
  216. protected function _getProfileId($iId)
  217. {
  218. return $this->_getProfileObject($iId)->id();
  219. }
  220. protected function _doDelete($iId, $aParams = array())
  221. {
  222. $oProfile = $this->_getProfileObject($iId);
  223. if(!$oProfile || $oProfile instanceof BxDolProfileUndefined)
  224. return false;
  225. if(!$this->_oModule->isAllowDeleteOrDisable(bx_get_logged_profile_id(), $oProfile->id()))
  226. return false;
  227. if($this->_oModule->checkMyself($iId))
  228. return false;
  229. return $oProfile->delete($oProfile->id(), isset($aParams['with_content']) && $aParams['with_content'] === true);
  230. }
  231. protected function _getId()
  232. {
  233. $aIds = bx_get('ids');
  234. if(!empty($aIds) && is_array($aIds))
  235. return (int)reset($aIds);
  236. $iId = bx_get('id');
  237. if($iId !== false)
  238. return (int)$iId;
  239. return false;
  240. }
  241. }
  242. /** @} */