BxDolAccount.php 21 KB

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