BxBaseModProfileGridAdministration.php 11 KB

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