BxAccntModule.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 Accounts Accounts
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxAccntModule extends BxBaseModGeneralModule
  12. {
  13. /**
  14. * Constructor
  15. */
  16. function __construct($aModule)
  17. {
  18. parent::__construct($aModule);
  19. $this->_oConfig->init($this->_oDb);
  20. }
  21. public function serviceGetSafeServices()
  22. {
  23. return array ();
  24. }
  25. public function serviceGetOptionsExportTo()
  26. {
  27. return array(
  28. 'csv' => _t('_bx_accnt_txt_export_to_csv'),
  29. 'xml' => _t('_bx_accnt_txt_export_to_xml'),
  30. );
  31. }
  32. public function serviceGetTitle ($iContentId)
  33. {
  34. $oAcc = BxDolAccount::getInstance($iContentId);
  35. return $oAcc ? $oAcc->getEmail() : '';
  36. }
  37. public function serviceGetOptionsExportFields()
  38. {
  39. $aResult = array();
  40. $aFields = $this->_oDb->getAccountFields();
  41. if(empty($aFields['original']) || !is_array($aFields['original']))
  42. return $aResult;
  43. foreach($aFields['original'] as $sField) {
  44. $sLangKey = '_bx_accnt_txt_field_' . $sField;
  45. $sLangString = _t($sLangKey);
  46. if(strcmp($sLangKey, $sLangString) == 0)
  47. continue;
  48. $aResult[] = array('key' => $sField, 'value' => $sLangString);
  49. }
  50. return $aResult;
  51. }
  52. /**
  53. * @page service Service Calls
  54. * @section bx_accounts Accounts
  55. * @subsection bx_accounts-other Other
  56. * @subsubsection bx_accounts-get_menu_addon_manage_tools get_menu_addon_manage_tools
  57. *
  58. * @code bx_srv('bx_accounts', 'get_menu_addon_manage_tools', [...]); @endcode
  59. *
  60. * Get number of 'unconfirmed' accounts for User End -> Dasboard page -> Manage block.
  61. *
  62. * @return integer number of 'unconfirmed' accounts
  63. *
  64. * @see BxAccntModule::serviceGetMenuAddonManageTools
  65. */
  66. /**
  67. * @ref bx_accounts-get_menu_addon_manage_tools "get_menu_addon_manage_tools"
  68. */
  69. public function serviceGetMenuAddonManageTools()
  70. {
  71. $iNumTotal = $this->_oDb->getEntriesNumByParams();
  72. $aConfirmed = array();
  73. $aUnConfirmed = array();
  74. $sCnfnType = getParam('sys_account_confirmation_type');
  75. $aFilter = [
  76. [
  77. 'key' => 'name',
  78. 'value' => 'Robot',
  79. 'operator' => '<>'
  80. ]
  81. ];
  82. switch($sCnfnType) {
  83. case 'email':
  84. $aFilter[] = array('value' => '', 'key' => 'email_confirmed', 'operator' => '=');
  85. $aFilter[] = array('value' => '', 'key' => 'email_confirmed', 'operator' => '<>');
  86. break;
  87. case 'phone':
  88. $aFilter[] = array('value' => '', 'key' => 'phone_confirmed', 'operator' => '=');
  89. $aFilter[] = array('value' => '', 'key' => 'phone_confirmed', 'operator' => '<>');
  90. break;
  91. case 'email_and_phone':
  92. $aFilter[] = array('value' => '', 'key' => 'phone_confirmed` * `email_confirmed', 'operator' => '=');
  93. $aFilter[] = array('value' => '', 'key' => 'phone_confirmed` * `email_confirmed', 'operator' => '<>');
  94. break;
  95. }
  96. $iNum1 = $this->_oDb->getEntriesNumByParams($aFilter);
  97. return array('counter1_value' => $iNum1,'counter3_value' => $iNumTotal, 'counter1_caption' => _t('_bx_accnt_menu_dashboard_manage_tools_addon_counter1_caption'));
  98. }
  99. public function checkAllowedManage($isPerformAction = false)
  100. {
  101. $bAdmin = isAdmin();
  102. if(!$bAdmin && !$this->_isModerator($isPerformAction) && !$this->_isAdministrator($isPerformAction))
  103. return _t('_sys_txt_access_denied');
  104. return CHECK_ACTION_RESULT_ALLOWED;
  105. }
  106. public function checkAllowedConfirm(&$aDataEntry, $isPerformAction = false)
  107. {
  108. $bAdmin = isAdmin();
  109. if(!$bAdmin || BxDolAccount::getInstance($aDataEntry['id'])->isConfirmed())
  110. return _t('_sys_txt_access_denied');
  111. return CHECK_ACTION_RESULT_ALLOWED;
  112. }
  113. public function checkAllowedDelete(&$aDataEntry, $isPerformAction = false)
  114. {
  115. if(isAdmin() && (int)$aDataEntry['id'] == getLoggedId())
  116. return _t('_sys_txt_access_denied');
  117. // check ACL
  118. $aCheck = checkActionModule($this->_iProfileId, 'delete account', 'system', $isPerformAction);
  119. if($aCheck[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED)
  120. return $aCheck[CHECK_ACTION_MESSAGE];
  121. return CHECK_ACTION_RESULT_ALLOWED;
  122. }
  123. public function checkAllowedEditEmail(&$aDataEntry, $isPerformAction = false)
  124. {
  125. $bAdmin = isAdmin();
  126. $iAccountId = getLoggedId();
  127. if((!$bAdmin && !$this->_isAdministrator($isPerformAction)) || (int)$aDataEntry['id'] == $iAccountId)
  128. return _t('_sys_txt_access_denied');
  129. return CHECK_ACTION_RESULT_ALLOWED;
  130. }
  131. public function checkAllowedSetOperatorRole(&$aDataEntry, $isPerformAction = false)
  132. {
  133. $bAdmin = isAdmin();
  134. $iAccountId = getLoggedId();
  135. if(!$bAdmin || !BxDolStudioRolesUtils::getInstance()->isActionAllowed(BX_SRA_MANAGE_ROLES, $iAccountId) || (int)$aDataEntry['id'] == $iAccountId)
  136. return _t('_sys_txt_access_denied');
  137. return CHECK_ACTION_RESULT_ALLOWED;
  138. }
  139. public function checkAllowedMakeOperator(&$aDataEntry, $isPerformAction = false)
  140. {
  141. $bAdmin = isAdmin();
  142. $iAccountId = getLoggedId();
  143. if(!$bAdmin || !BxDolStudioRolesUtils::getInstance()->isActionAllowed(BX_SRA_MANAGE_ROLES, $iAccountId) || (int)$aDataEntry['id'] == $iAccountId || (int)$aDataEntry['role'] == 3)
  144. return _t('_sys_txt_access_denied');
  145. return CHECK_ACTION_RESULT_ALLOWED;
  146. }
  147. public function checkAllowedUnmakeOperator(&$aDataEntry, $isPerformAction = false)
  148. {
  149. $bAdmin = isAdmin();
  150. $iAccountId = getLoggedId();
  151. if(!$bAdmin || !BxDolStudioRolesUtils::getInstance()->isActionAllowed(BX_SRA_MANAGE_ROLES, $iAccountId) || (int)$aDataEntry['id'] == $iAccountId || (int)$aDataEntry['role'] != 3)
  152. return _t('_sys_txt_access_denied');
  153. return CHECK_ACTION_RESULT_ALLOWED;
  154. }
  155. public function checkAllowedUnlockAccount(&$aDataEntry, $isPerformAction = false)
  156. {
  157. $bAdmin = isAdmin();
  158. if(!$bAdmin || (int)$aDataEntry['locked'] != 1)
  159. return _t('_sys_txt_access_denied');
  160. return CHECK_ACTION_RESULT_ALLOWED;
  161. }
  162. public function isAllowDeleteOrDisable($iActorProfileId, $iTargetProfileId)
  163. {
  164. if (BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR), $iActorProfileId) && BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR, MEMBERSHIP_ID_ADMINISTRATOR), $iTargetProfileId))
  165. return false;
  166. return true;
  167. }
  168. }
  169. /** @} */