BxAccntModule.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 checkAllowedConfirm(&$aDataEntry, $isPerformAction = false)
  100. {
  101. $bAdmin = isAdmin();
  102. if(!$bAdmin || BxDolAccount::getInstance($aDataEntry['id'])->isConfirmed())
  103. return _t('_sys_txt_access_denied');
  104. return CHECK_ACTION_RESULT_ALLOWED;
  105. }
  106. public function checkAllowedDelete(&$aDataEntry, $isPerformAction = false)
  107. {
  108. if(isAdmin() && (int)$aDataEntry['id'] == getLoggedId())
  109. return _t('_sys_txt_access_denied');
  110. // check ACL
  111. $aCheck = checkActionModule($this->_iProfileId, 'delete account', 'system', $isPerformAction);
  112. if($aCheck[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED)
  113. return $aCheck[CHECK_ACTION_MESSAGE];
  114. return CHECK_ACTION_RESULT_ALLOWED;
  115. }
  116. public function checkAllowedSetOperatorRole(&$aDataEntry, $isPerformAction = false)
  117. {
  118. $bAdmin = isAdmin();
  119. $iAccountId = getLoggedId();
  120. if(!$bAdmin || !BxDolStudioRolesUtils::getInstance()->isActionAllowed(BX_SRA_MANAGE_ROLES, $iAccountId) || (int)$aDataEntry['id'] == $iAccountId)
  121. return _t('_sys_txt_access_denied');
  122. return CHECK_ACTION_RESULT_ALLOWED;
  123. }
  124. public function checkAllowedMakeOperator(&$aDataEntry, $isPerformAction = false)
  125. {
  126. $bAdmin = isAdmin();
  127. $iAccountId = getLoggedId();
  128. if(!$bAdmin || !BxDolStudioRolesUtils::getInstance()->isActionAllowed(BX_SRA_MANAGE_ROLES, $iAccountId) || (int)$aDataEntry['id'] == $iAccountId || (int)$aDataEntry['role'] == 3)
  129. return _t('_sys_txt_access_denied');
  130. return CHECK_ACTION_RESULT_ALLOWED;
  131. }
  132. public function checkAllowedUnmakeOperator(&$aDataEntry, $isPerformAction = false)
  133. {
  134. $bAdmin = isAdmin();
  135. $iAccountId = getLoggedId();
  136. if(!$bAdmin || !BxDolStudioRolesUtils::getInstance()->isActionAllowed(BX_SRA_MANAGE_ROLES, $iAccountId) || (int)$aDataEntry['id'] == $iAccountId || (int)$aDataEntry['role'] != 3)
  137. return _t('_sys_txt_access_denied');
  138. return CHECK_ACTION_RESULT_ALLOWED;
  139. }
  140. public function checkAllowedUnlockAccount(&$aDataEntry, $isPerformAction = false)
  141. {
  142. if((int)$aDataEntry['locked'] != 1)
  143. return _t('_sys_txt_access_denied');
  144. return CHECK_ACTION_RESULT_ALLOWED;
  145. }
  146. public function isAllowDeleteOrDisable($iActorProfileId, $iTargetProfileId)
  147. {
  148. if (BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR), $iActorProfileId) && BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR, MEMBERSHIP_ID_ADMINISTRATOR), $iTargetProfileId))
  149. return false;
  150. return true;
  151. }
  152. }
  153. /** @} */