BxDolAccount.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. bx_import('BxDolAcl');
  10. class BxDolAccount extends BxDolFactory implements iBxDolSingleton
  11. {
  12. protected $_iAccountID;
  13. protected $_aInfo;
  14. protected $_oQuery;
  15. /**
  16. * Constructor
  17. */
  18. protected function __construct ($iAccountId)
  19. {
  20. $iAccountId = (int)$iAccountId;
  21. $sClass = get_class($this) . '_' . $iAccountId;
  22. if (isset($GLOBALS['bxDolClasses'][$sClass]))
  23. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  24. parent::__construct();
  25. $this->_iAccountID = $iAccountId; // since constructor is protected $iAccountId is always valid
  26. $this->_oQuery = BxDolAccountQuery::getInstance();
  27. }
  28. /**
  29. * Prevent cloning the instance
  30. */
  31. public function __clone()
  32. {
  33. $sClass = get_class($this) . '_' . $this->_iProfileID;
  34. if (isset($GLOBALS['bxDolClasses'][$sClass]))
  35. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  36. }
  37. /**
  38. * Get singleton instance of the class
  39. */
  40. public static function getInstance($mixedAccountId = false, $bClearCache = false)
  41. {
  42. if (!$mixedAccountId)
  43. $mixedAccountId = getLoggedId();
  44. $iAccountId = self::getID($mixedAccountId);
  45. if (!$iAccountId)
  46. return false;
  47. $sClass = __CLASS__ . '_' . $iAccountId;
  48. if ($bClearCache && isset($GLOBALS['bxDolClasses'][$sClass]))
  49. unset($GLOBALS['bxDolClasses'][$sClass]);
  50. if(!isset($GLOBALS['bxDolClasses'][$sClass]))
  51. $GLOBALS['bxDolClasses'][$sClass] = new BxDolAccount($iAccountId);
  52. return $GLOBALS['bxDolClasses'][$sClass];
  53. }
  54. /**
  55. * Get studio operator account singleton instance on the class
  56. */
  57. public static function getInstanceStudioOperator()
  58. {
  59. $oQuery = BxDolAccountQuery::getInstance();
  60. if (!($iId = $oQuery->getStudioOperatorId()))
  61. return false;
  62. return self::getInstance($iId);
  63. }
  64. /**
  65. * Get account id
  66. */
  67. public function id()
  68. {
  69. $a = $this->getInfo($this->_iAccountID);
  70. return isset($a['id']) ? $a['id'] : false;
  71. }
  72. /**
  73. * Check if account is confirmed, it is checked by email confirmation
  74. */
  75. public function isConfirmed($iAccountId = false)
  76. {
  77. $sConfirmationType = getParam('sys_account_confirmation_type');
  78. if ($sConfirmationType == BX_ACCOUNT_CONFIRMATION_NONE)
  79. return true;
  80. $a = $this->getInfo((int)$iAccountId);
  81. switch ($sConfirmationType) {
  82. case BX_ACCOUNT_CONFIRMATION_EMAIL:
  83. if ($a['email_confirmed'])
  84. return true;
  85. break;
  86. case BX_ACCOUNT_CONFIRMATION_PHONE:
  87. if ($a['phone_confirmed'])
  88. return true;
  89. break;
  90. case BX_ACCOUNT_CONFIRMATION_EMAIL_PHONE:
  91. if ($a['email_confirmed'] && $a['phone_confirmed'])
  92. return true;
  93. break;
  94. }
  95. return false;
  96. }
  97. public function getCurrentConfirmationStatusValue($iAccountId = false)
  98. {
  99. $a = $this->getInfo((int)$iAccountId);
  100. $sTmp = $a['email_confirmed'] . $a['phone_confirmed'];
  101. switch ($sTmp) {
  102. case '01':
  103. return BX_ACCOUNT_CONFIRMATION_PHONE;
  104. case '10':
  105. return BX_ACCOUNT_CONFIRMATION_EMAIL;
  106. case '11':
  107. return BX_ACCOUNT_CONFIRMATION_EMAIL_PHONE;
  108. }
  109. return BX_ACCOUNT_CONFIRMATION_NONE;
  110. }
  111. public function isConfirmedEmail($iAccountId = false)
  112. {
  113. if (!self::isNeedConfirmEmail())
  114. return true;
  115. $a = $this->getInfo((int)$iAccountId);
  116. return $a['email_confirmed'] ? true : false;
  117. }
  118. public function isConfirmedPhone($iAccountId = false)
  119. {
  120. if (!self::isNeedConfirmPhone())
  121. return true;
  122. $a = $this->getInfo((int)$iAccountId);
  123. return $a['phone_confirmed'] ? true : false;
  124. }
  125. static public function isNeedConfirmEmail()
  126. {
  127. if (getParam('sys_account_confirmation_type') == BX_ACCOUNT_CONFIRMATION_EMAIL || getParam('sys_account_confirmation_type') == BX_ACCOUNT_CONFIRMATION_EMAIL_PHONE)
  128. return true;
  129. return false;
  130. }
  131. static public function isNeedConfirmPhone()
  132. {
  133. if (getParam('sys_account_confirmation_type') == BX_ACCOUNT_CONFIRMATION_PHONE || getParam('sys_account_confirmation_type') == BX_ACCOUNT_CONFIRMATION_EMAIL_PHONE)
  134. return true;
  135. return false;
  136. }
  137. public function isLocked($iAccountId = false)
  138. {
  139. $a = $this->getInfo((int)$iAccountId);
  140. return $a['locked'] ? true : false;
  141. }
  142. //
  143. /**
  144. * Set account email to confirmed or unconfirmed
  145. * @param int $isConfirmed - false: mark email as unconfirmed, true: as confirmed
  146. * @param int $iAccountId - optional account id
  147. * @return true on success or false on error
  148. */
  149. public function updateEmailConfirmed($isConfirmed, $isAutoSendConfrmationEmail = true, $iAccountId = false)
  150. {
  151. $iId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  152. if (!$isConfirmed && $isAutoSendConfrmationEmail && self::isNeedConfirmEmail()) // if email_confirmation procedure is enabled - send email confirmation letter
  153. $this->sendConfirmationEmail($iId);
  154. if ($this->_oQuery->updateEmailConfirmed($isConfirmed, $iId)) {
  155. $this->_aInfo = false;
  156. bx_alert('account', $this->isConfirmed() ? 'confirm' : 'unconfirm', $iId);
  157. return true;
  158. }
  159. return false;
  160. }
  161. /**
  162. * Set account phone to confirmed or unconfirmed
  163. * @param int $isConfirmed - false: mark phone as unconfirmed, true: as confirmed
  164. * @param int $iAccountId - optional account id
  165. * @return true on success or false on error
  166. */
  167. public function updatePhoneConfirmed($isConfirmed, $iAccountId = false)
  168. {
  169. $iId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  170. if ($this->_oQuery->updatePhoneConfirmed($isConfirmed, $iId)) {
  171. $this->_aInfo = false;
  172. bx_alert('account', $this->isConfirmed() ? 'confirm' : 'unconfirm', $iId);
  173. return true;
  174. }
  175. return false;
  176. }
  177. /**
  178. * Set account phone
  179. * @param string $sPhone - phone number
  180. * @param int $iAccountId - optional account id
  181. * @return true on success or false on error
  182. */
  183. public function updatePhone($sPhone, $iAccountId = false)
  184. {
  185. $iId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  186. if ($this->_oQuery->updatePhone($sPhone, $iId)) {
  187. bx_alert('account', 'set_phone', $iId);
  188. return true;
  189. }
  190. return false;
  191. }
  192. /**
  193. * Switch context automatically to the first available profile
  194. * @param $iProfileIdFilterOut profile ID to exclude from the list of possible profiles
  195. * @param $iAccountId account ID to use istead of current account
  196. * @return true on success or false on error
  197. */
  198. public function updateProfileContextAuto($iProfileIdFilterOut = false, $iAccountId = false)
  199. {
  200. $oAccount = (!$iAccountId || $iAccountId == $this->_iAccountID ? $this : BxDolAccount::getInstance ($iAccountId));
  201. if (!$oAccount)
  202. return false;
  203. $aAccountInfo = $oAccount->getInfo();
  204. $aProfiles = $oAccount->getProfiles();
  205. $oProfileAccount = BxDolProfile::getInstanceAccountProfile($oAccount->id());
  206. // unset deleted profile and account profile
  207. if ($iProfileIdFilterOut)
  208. unset($aProfiles[$iProfileIdFilterOut]);
  209. unset($aProfiles[$oProfileAccount->id()]);
  210. if ($aProfiles) {
  211. // try to use another profile
  212. reset($aProfiles);
  213. $iProfileId = key($aProfiles);
  214. }
  215. else {
  216. // if no profiles exist, use account profile
  217. $iProfileId = $oProfileAccount->id();
  218. }
  219. return $oAccount->updateProfileContext($iProfileId);
  220. }
  221. public function updateProfileContext($iSwitchToProfileId, $iAccountId = false)
  222. {
  223. $iId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  224. $aInfo = $this->getInfo((int)$iId);
  225. if (!$aInfo)
  226. return false;
  227. $ret = null;
  228. bx_alert('account', 'before_switch_context', $iId, $iSwitchToProfileId, array('profile_id_current' => $aInfo['profile_id'], 'override_result' => &$ret));
  229. if ($ret !== null)
  230. return $ret;
  231. if (!$this->_oQuery->updateCurrentProfile($iId, $iSwitchToProfileId))
  232. return false;
  233. $this->_aInfo = false;
  234. bx_alert('account', 'switch_context', $iId, $iSwitchToProfileId, array('profile_id_old' => $aInfo['profile_id']));
  235. return true;
  236. }
  237. /**
  238. * Send "confirmation" email
  239. */
  240. public function sendConfirmationEmail($iAccountId = false)
  241. {
  242. $sName = $this->getDisplayName($iAccountId);
  243. $sEmail = $this->getEmail($iAccountId);
  244. $oKey = BxDolKey::getInstance();
  245. $sConfirmationCode = $oKey->getNewKey(array('account_id' => $iAccountId));
  246. $sConfirmationLink = bx_append_url_params(BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=confirm-email'), array('code' => urlencode($sConfirmationCode)));
  247. $aPlus = array(
  248. 'name' => $sName,
  249. 'email' => $sEmail,
  250. 'conf_code' => $sConfirmationCode,
  251. 'conf_link' => $sConfirmationLink,
  252. 'conf_form_link' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=confirm-email')
  253. );
  254. $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate('t_Confirmation', $aPlus);
  255. $bRv = $aTemplate && sendMail($sEmail, $aTemplate['Subject'], $aTemplate['Body'], 0, array(), BX_EMAIL_SYSTEM);
  256. if($bRv){
  257. $this->doAudit($iAccountId, '_sys_audit_action_account_resend_confirmation_email');
  258. }
  259. return $bRv;
  260. }
  261. /**
  262. * Get account info
  263. */
  264. public function getInfo($iAccountId = false)
  265. {
  266. if ($iAccountId && $iAccountId != $this->_iAccountID)
  267. return $this->_oQuery->getInfoById((int)$iAccountId ? (int)$iAccountId : $this->_iAccountID);
  268. if ($this->_aInfo)
  269. return $this->_aInfo;
  270. $this->_aInfo = $this->_oQuery->getInfoById($this->_iAccountID);
  271. return $this->_aInfo;
  272. }
  273. /**
  274. * Get account display name
  275. */
  276. public function getDisplayName($iAccountId = false)
  277. {
  278. $aInfo = $this->getInfo($iAccountId);
  279. return bx_process_output(!empty($aInfo['name']) ? $aInfo['name'] : _t('_sys_txt_user_n', $aInfo['id']));
  280. }
  281. /**
  282. * Get account url
  283. */
  284. public function getUrl($iAccountId = false)
  285. {
  286. return 'javascript:void(0);';
  287. }
  288. /**
  289. * Get account url
  290. */
  291. public function getUnit($iAccountId = false, $aParams = array())
  292. {
  293. $sTemplate = 'unit';
  294. $sTemplateSize = false;
  295. $aTemplateVars = array();
  296. if(!empty($aParams['template'])) {
  297. if(is_string($aParams['template']))
  298. $sTemplate = $aParams['template'];
  299. else if(is_array($aParams['template'])) {
  300. if(!empty($aParams['template']['name']))
  301. $sTemplate = $aParams['template']['name'];
  302. if(!empty($aParams['template']['size']))
  303. $sTemplateSize = $aParams['template']['size'];
  304. if(!empty($aParams['template']['vars']))
  305. $aTemplateVars = $aParams['template']['vars'];
  306. }
  307. }
  308. $sTemplate = 'account_' . $sTemplate . '.html';
  309. if(empty($sTemplateSize))
  310. $sTemplateSize = 'thumb';
  311. $sTitle = $this->getDisplayName($iAccountId);
  312. $aTmplVars = array(
  313. 'size' => $sTemplateSize,
  314. 'color' => implode(', ', BxDolTemplate::getColorCode(($iAccountId ? $iAccountId : $this->_iAccountID), 1.0)),
  315. 'letter' => mb_strtoupper(mb_substr($sTitle, 0, 1)),
  316. 'content_url' => $this->getUrl($iAccountId),
  317. 'title' => $sTitle,
  318. 'title_attr' => bx_html_attribute($sTitle),
  319. 'bx_if:show_online' => array(
  320. 'condition' => $this->isOnline($iAccountId),
  321. 'content' => array()
  322. )
  323. );
  324. if(!empty($aTemplateVars) && is_array($aTemplateVars))
  325. $aTmplVars = array_merge ($aTmplVars, $aTemplateVars);
  326. return BxDolTemplate::getInstance()->parseHtmlByName($sTemplate, $aTmplVars);
  327. }
  328. /**
  329. * Get picture url
  330. */
  331. public function getPicture($iAccountId = false)
  332. {
  333. return BxDolTemplate::getInstance()->getImageUrl('account-picture.png');
  334. }
  335. /**
  336. * Get big (2x) avatar url
  337. */
  338. public function getAvatarBig($iAccountId = false)
  339. {
  340. return BxDolTemplate::getInstance()->getImageUrl('account-avatar-big.png');
  341. }
  342. /**
  343. * Get avatar url
  344. */
  345. public function getAvatar($iAccountId = false)
  346. {
  347. return BxDolTemplate::getInstance()->getImageUrl('account-avatar.png');
  348. }
  349. /**
  350. * Get thumb picture url
  351. */
  352. public function getThumb($iAccountId = false)
  353. {
  354. return BxDolTemplate::getInstance()->getImageUrl('account-thumb.png');
  355. }
  356. /**
  357. * Get icon picture url
  358. */
  359. public function getIcon($iAccountId = false)
  360. {
  361. return BxDolTemplate::getInstance()->getImageUrl('account-icon.png');
  362. }
  363. /**
  364. * Get account email
  365. */
  366. public function getEmail($iAccountId = false)
  367. {
  368. $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  369. $aAccountInfo = $this->getInfo($iAccountId);
  370. return $aAccountInfo['email'];
  371. }
  372. /**
  373. * Get language ID
  374. */
  375. public function getLanguageId($iAccountId = false)
  376. {
  377. $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  378. $aAccountInfo = $this->getInfo($iAccountId);
  379. return $aAccountInfo['lang_id'];
  380. }
  381. /**
  382. * Is account online
  383. */
  384. public function isOnline($iAccountId = false)
  385. {
  386. $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  387. return $this->_oQuery->isOnline($iAccountId);
  388. }
  389. /**
  390. * Validate account.
  391. * @param $s - account identifier (id or email)
  392. * @return account id or false if account was not found
  393. */
  394. static public function getID($s)
  395. {
  396. $oQuery = BxDolAccountQuery::getInstance();
  397. bx_import('BxDolForm');
  398. if (BxDolFormCheckerHelper::checkEmail($s)) {
  399. $iId = (int)$oQuery->getIdByEmail($s);
  400. return $iId ? $iId : false;
  401. }
  402. if (preg_match("/^\+[0-9\s]+$/", $s)) {
  403. $iId = (int)$oQuery->getIdByPhone($s);
  404. return $iId ? $iId : false;
  405. }
  406. $iId = $oQuery->getIdById((int)$s);
  407. return $iId ? $iId : false;
  408. }
  409. /**
  410. * Check if profiles limit reached
  411. */
  412. public function isProfilesLimitReached ()
  413. {
  414. $iProfilesLimit = (int)getParam('sys_account_limit_profiles_number');
  415. bx_alert('account', 'get_limit_profiles_number', 0, 0, array('account_id' => $this->_iAccountID, 'number' => &$iProfilesLimit));
  416. if ($iProfilesLimit && ($iProfilesNum = $this->getProfilesNumber()) && $iProfilesNum >= $iProfilesLimit)
  417. return true;
  418. return false;
  419. }
  420. /**
  421. * Get number of profiles associated with the account
  422. */
  423. public function getProfilesNumber ($isFilterNonSwitchableProfiles = true)
  424. {
  425. $a = $this->getProfilesIds($isFilterNonSwitchableProfiles);
  426. return count($a);
  427. }
  428. /**
  429. * Get all profile ids associated with the account
  430. */
  431. public function getProfilesIds ($isFilterNonSwitchableProfiles = true, $isFilterSystemProfiles = true)
  432. {
  433. $a = $this->getProfiles ($isFilterNonSwitchableProfiles, $isFilterSystemProfiles);
  434. return $a ? array_keys($a) : array();
  435. }
  436. /**
  437. * Get all profiles associated with the account
  438. */
  439. public function getProfiles ($isFilterNonSwitchableProfiles = true, $isFilterSystemProfiles = true)
  440. {
  441. $oProfileQuery = BxDolProfileQuery::getInstance();
  442. $aProfiles = $oProfileQuery->getProfilesByAccount($this->_iAccountID);
  443. if ($isFilterNonSwitchableProfiles) {
  444. foreach ($aProfiles as $iProfileId => $aProfile) {
  445. if ('system' == $aProfile['type'])
  446. continue;
  447. if (!BxDolService::call($aProfile['type'], 'act_as_profile'))
  448. unset($aProfiles[$iProfileId]);
  449. }
  450. }
  451. if ($isFilterSystemProfiles) {
  452. foreach ($aProfiles as $iProfileId => $aProfile) {
  453. if ('system' == $aProfile['type'])
  454. unset($aProfiles[$iProfileId]);
  455. }
  456. }
  457. return $aProfiles;
  458. }
  459. /**
  460. * Delete profile.
  461. * @param $bDeleteWithContent - delete associated profiles with all its contents
  462. */
  463. function delete($bDeleteWithContent = false)
  464. {
  465. $aAccountInfo = $this->_oQuery->getInfoById($this->_iAccountID);
  466. if (!$aAccountInfo)
  467. return false;
  468. // create system event before deletion
  469. $isStopDeletion = false;
  470. bx_alert('account', 'before_delete', $this->_iAccountID, 0, array('delete_with_content' => $bDeleteWithContent, 'stop_deletion' => &$isStopDeletion));
  471. if ($isStopDeletion)
  472. return false;
  473. $oAccountQuery = BxDolAccountQuery::getInstance();
  474. $oProfileQuery = BxDolProfileQuery::getInstance();
  475. $aProfiles = $oProfileQuery->getProfilesByAccount($this->_iAccountID);
  476. foreach ($aProfiles as $iProfileId => $aRow) {
  477. $oProfile = BxDolProfile::getInstance($iProfileId);
  478. if (!$oProfile)
  479. continue;
  480. $oProfile->delete(false, $bDeleteWithContent, true);
  481. }
  482. // delete profile
  483. if (!$oAccountQuery->delete($this->_iAccountID))
  484. return false;
  485. // unset class instance to prevent creating the instance again
  486. $sClass = __CLASS__ . '_' . $this->_iAccountID;
  487. unset($GLOBALS['bxDolClasses'][$sClass]);
  488. // create system event
  489. bx_alert('account', 'delete', $this->_iAccountID, 0, array ('delete_with_content' => $bDeleteWithContent));
  490. $this->doAudit($this->_iAccountID, $bDeleteWithContent ? '_sys_audit_action_account_deleted_with_content' : '_sys_audit_action_account_deleted');
  491. return true;
  492. }
  493. /**
  494. * Add permament messages.
  495. */
  496. public function addInformerPermanentMessages ($oInformer)
  497. {
  498. if (!$this->isConfirmedEmail()) {
  499. $sUrl = BxDolPermalinks::getInstance()->permalink('page.php?i=confirm-email') . '&resend=1';
  500. $aAccountInfo = $this->getInfo();
  501. $oInformer->add('sys-account-unconfirmed-email', _t('_sys_txt_account_unconfirmed_email', $sUrl, $aAccountInfo['email']), BX_INFORMER_ALERT);
  502. }
  503. if (!$this->isConfirmedPhone()) {
  504. $sUrl = BxDolPermalinks::getInstance()->permalink('page.php?i=confirm-phone') . '';
  505. $aAccountInfo = $this->getInfo();
  506. $oInformer->add('sys-account-unconfirmed-phone', _t('_sys_txt_account_unconfirmed_phone', $sUrl), BX_INFORMER_ALERT);
  507. }
  508. }
  509. /**
  510. * Get unsubscribe link for the specified mesage type
  511. */
  512. public function getUnsubscribeLink($iEmailType, $iAccountId = false)
  513. {
  514. $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  515. $sUrl = '';
  516. switch ($iEmailType) {
  517. case BX_EMAIL_NOTIFY:
  518. $sUrl = 'page.php?i=unsubscribe-notifications';
  519. break;
  520. case BX_EMAIL_MASS:
  521. $sUrl = 'page.php?i=unsubscribe-news';
  522. break;
  523. default:
  524. return '';
  525. }
  526. return BxDolPermalinks::getInstance()->permalink($sUrl) . '&id=' . $iAccountId . '&code=' . $this->getEmailHash();
  527. }
  528. public function getEmailHash($iAccountId = false)
  529. {
  530. $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  531. $a = $this->getInfo();
  532. return md5($a['email'] . $a['salt'] . BX_DOL_SECRET);
  533. }
  534. public function doAudit($iAccountId, $sAction, $aData = array())
  535. {
  536. $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  537. bx_audit(
  538. $iAccountId,
  539. 'bx_accounts',
  540. $sAction,
  541. array('content_title' => $this->getDisplayName(), 'data' => $aData)
  542. );
  543. }
  544. /**
  545. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  546. */
  547. static public function isAllowedCreate ($iProfileId, $isPerformAction = false)
  548. {
  549. $aCheck = checkActionModule($iProfileId, 'create account', 'system', $isPerformAction);
  550. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  551. return MsgBox($aCheck[CHECK_ACTION_MESSAGE]);
  552. return CHECK_ACTION_RESULT_ALLOWED;
  553. }
  554. /**
  555. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  556. */
  557. static public function isAllowedEdit ($iProfileId, $aContentInfo, $isPerformAction = false)
  558. {
  559. $oProfile = BxDolProfile::getInstance($iProfileId);
  560. if (!$oProfile)
  561. return _t('_sys_txt_access_denied');
  562. $aProfileInfo = $oProfile->getInfo();
  563. if (!$aProfileInfo || getLoggedId() != $aProfileInfo['account_id'])
  564. return _t('_sys_txt_access_denied');
  565. return CHECK_ACTION_RESULT_ALLOWED;
  566. }
  567. /**
  568. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  569. */
  570. static public function isAllowedDelete ($iProfileId, $aContentInfo, $isPerformAction = false)
  571. {
  572. $iAccountId = (int)BxDolProfile::getInstance($iProfileId)->getAccountId();
  573. if(isAdmin($iAccountId) && $iAccountId == (int)$aContentInfo['id'])
  574. return _t('_sys_txt_access_denied');
  575. $aCheck = checkActionModule($iProfileId, 'delete account', 'system', $isPerformAction);
  576. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  577. return $aCheck[CHECK_ACTION_MESSAGE];
  578. return CHECK_ACTION_RESULT_ALLOWED;
  579. }
  580. }
  581. /** @} */