BxAccntModule.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 serviceGetOptionsExportFields()
  33. {
  34. $aResult = array();
  35. $aFields = $this->_oDb->getAccountFields();
  36. if(empty($aFields['original']) || !is_array($aFields['original']))
  37. return $aResult;
  38. foreach($aFields['original'] as $sField) {
  39. $sLangKey = '_bx_accnt_txt_field_' . $sField;
  40. $sLangString = _t($sLangKey);
  41. if(strcmp($sLangKey, $sLangString) == 0)
  42. continue;
  43. $aResult[] = array('key' => $sField, 'value' => $sLangString);
  44. }
  45. return $aResult;
  46. }
  47. /**
  48. * @page service Service Calls
  49. * @section bx_accounts Accounts
  50. * @subsection bx_accounts-other Other
  51. * @subsubsection bx_accounts-get_menu_addon_manage_tools get_menu_addon_manage_tools
  52. *
  53. * @code bx_srv('bx_accounts', 'get_menu_addon_manage_tools', [...]); @endcode
  54. *
  55. * Get number of 'unconfirmed' accounts for User End -> Dasboard page -> Manage block.
  56. *
  57. * @return integer number of 'unconfirmed' accounts
  58. *
  59. * @see BxAccntModule::serviceGetMenuAddonManageTools
  60. */
  61. /**
  62. * @ref bx_accounts-get_menu_addon_manage_tools "get_menu_addon_manage_tools"
  63. */
  64. public function serviceGetMenuAddonManageTools()
  65. {
  66. $iNumTotal = $this->_oDb->getEntriesNumByParams();
  67. $aConfirmed = array();
  68. $aUnConfirmed = array();
  69. $sCnfnType = getParam('sys_account_confirmation_type');
  70. $aFilter = [
  71. [
  72. 'key' => 'name',
  73. 'value' => 'Robot',
  74. 'operator' => '<>'
  75. ]
  76. ];
  77. switch($sCnfnType) {
  78. case 'email':
  79. $aFilter[] = array('value' => '', 'key' => 'email_confirmed', 'operator' => '=');
  80. $aFilter[] = array('value' => '', 'key' => 'email_confirmed', 'operator' => '<>');
  81. break;
  82. case 'phone':
  83. $aFilter[] = array('value' => '', 'key' => 'phone_confirmed', 'operator' => '=');
  84. $aFilter[] = array('value' => '', 'key' => 'phone_confirmed', 'operator' => '<>');
  85. break;
  86. case 'email_and_phone':
  87. $aFilter[] = array('value' => '', 'key' => 'phone_confirmed` * `email_confirmed', 'operator' => '=');
  88. $aFilter[] = array('value' => '', 'key' => 'phone_confirmed` * `email_confirmed', 'operator' => '<>');
  89. break;
  90. }
  91. $iNum1 = $this->_oDb->getEntriesNumByParams($aFilter);
  92. return array('counter1_value' => $iNum1,'counter3_value' => $iNumTotal, 'counter1_caption' => _t('_bx_accnt_menu_dashboard_manage_tools_addon_counter1_caption'));
  93. }
  94. public function checkAllowedConfirm(&$aDataEntry, $isPerformAction = false)
  95. {
  96. $bAdmin = isAdmin();
  97. if(!$bAdmin || BxDolAccount::getInstance($aDataEntry['id'])->isConfirmed())
  98. return _t('_sys_txt_access_denied');
  99. return CHECK_ACTION_RESULT_ALLOWED;
  100. }
  101. public function checkAllowedDelete(&$aDataEntry, $isPerformAction = false)
  102. {
  103. if(isAdmin() && (int)$aDataEntry['id'] == getLoggedId())
  104. return _t('_sys_txt_access_denied');
  105. // check ACL
  106. $aCheck = checkActionModule($this->_iProfileId, 'delete account', 'system', $isPerformAction);
  107. if($aCheck[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED)
  108. return $aCheck[CHECK_ACTION_MESSAGE];
  109. return CHECK_ACTION_RESULT_ALLOWED;
  110. }
  111. public function checkAllowedSetOperatorRole(&$aDataEntry, $isPerformAction = false)
  112. {
  113. $bAdmin = isAdmin();
  114. $iAccountId = getLoggedId();
  115. if(!$bAdmin || !BxDolStudioRolesUtils::getInstance()->isActionAllowed(BX_SRA_MANAGE_ROLES, $iAccountId) || (int)$aDataEntry['id'] == $iAccountId)
  116. return _t('_sys_txt_access_denied');
  117. return CHECK_ACTION_RESULT_ALLOWED;
  118. }
  119. public function checkAllowedMakeOperator(&$aDataEntry, $isPerformAction = false)
  120. {
  121. $bAdmin = isAdmin();
  122. $iAccountId = getLoggedId();
  123. if(!$bAdmin || !BxDolStudioRolesUtils::getInstance()->isActionAllowed(BX_SRA_MANAGE_ROLES, $iAccountId) || (int)$aDataEntry['id'] == $iAccountId || (int)$aDataEntry['role'] == 3)
  124. return _t('_sys_txt_access_denied');
  125. return CHECK_ACTION_RESULT_ALLOWED;
  126. }
  127. public function checkAllowedUnmakeOperator(&$aDataEntry, $isPerformAction = false)
  128. {
  129. $bAdmin = isAdmin();
  130. $iAccountId = getLoggedId();
  131. if(!$bAdmin || !BxDolStudioRolesUtils::getInstance()->isActionAllowed(BX_SRA_MANAGE_ROLES, $iAccountId) || (int)$aDataEntry['id'] == $iAccountId || (int)$aDataEntry['role'] != 3)
  132. return _t('_sys_txt_access_denied');
  133. return CHECK_ACTION_RESULT_ALLOWED;
  134. }
  135. public function checkAllowedUnlockAccount(&$aDataEntry, $isPerformAction = false)
  136. {
  137. if((int)$aDataEntry['locked'] != 1)
  138. return _t('_sys_txt_access_denied');
  139. return CHECK_ACTION_RESULT_ALLOWED;
  140. }
  141. public function isAllowDeleteOrDisable($iActorProfileId, $iTargetProfileId)
  142. {
  143. if (BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR), $iActorProfileId) && BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR, MEMBERSHIP_ID_ADMINISTRATOR), $iTargetProfileId))
  144. return false;
  145. return true;
  146. }
  147. }
  148. /** @} */