BxBasePageAccount.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Account page.
  11. */
  12. class BxBasePageAccount extends BxTemplPage
  13. {
  14. protected $_aMapStatus2LangKey = array (
  15. BX_PROFILE_STATUS_PENDING => '_sys_txt_account_pending',
  16. BX_PROFILE_STATUS_SUSPENDED => '_sys_txt_account_suspended',
  17. );
  18. public function __construct($aObject, $oTemplate)
  19. {
  20. parent::__construct($aObject, $oTemplate);
  21. $oProfile = BxDolProfile::getInstance();
  22. $aProfileInfo = $oProfile ? $oProfile->getInfo() : false;
  23. $this->addMarkers(array(
  24. 'account_id' => $aProfileInfo ? $aProfileInfo['account_id'] : 0,
  25. 'profile_id' => $aProfileInfo ? $aProfileInfo['id'] : 0,
  26. 'profile_type' => $aProfileInfo ? $aProfileInfo['type'] : 0,
  27. 'profile_content_id' => $aProfileInfo ? $aProfileInfo['content_id'] : 0,
  28. ));
  29. // set settings submenu
  30. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  31. if ($oMenuSubmenu) {
  32. $oMenuSubmenu->setObjectSubmenu('sys_account_settings_submenu', array (
  33. 'title' => _t('_sys_menu_item_title_account_settings'),
  34. 'link' => BX_DOL_URL_ROOT . 'member.php',
  35. 'icon' => '',
  36. ));
  37. }
  38. // display message if profile isn't active
  39. if ($oProfile) {
  40. $sStatus = $oProfile->getStatus();
  41. if (isset($this->_aMapStatus2LangKey[$sStatus])) {
  42. $oInformer = BxDolInformer::getInstance($this->_oTemplate);
  43. if ($oInformer)
  44. $oInformer->add('sys-account-status-not-active', _t($this->_aMapStatus2LangKey[$sStatus]), BX_INFORMER_ALERT);
  45. }
  46. }
  47. // switch profile context
  48. if ($iSwitchToProfileId = (int)bx_get('switch_to_profile')) {
  49. $sInformerMsg = '';
  50. $oProfile = BxDolProfile::getInstance($iSwitchToProfileId);
  51. if($oProfile && BxDolService::call($oProfile->getModule(), 'act_as_profile')) {
  52. $mixedRes = bx_srv('system', 'switch_profile', [$oProfile->id()], 'TemplServiceAccount');
  53. if($mixedRes === true) {
  54. if(bx_get('redirect') !== false) {
  55. $sLocation = '';
  56. switch(bx_process_input(bx_get('redirect'))) {
  57. case 'back':
  58. if(isset($_SERVER['HTTP_REFERER']) && mb_stripos($_SERVER['HTTP_REFERER'], BX_DOL_URL_ROOT) === 0)
  59. $sLocation = $_SERVER['HTTP_REFERER'];
  60. break;
  61. case 'home':
  62. $sLocation = BX_DOL_URL_ROOT;
  63. break;
  64. case 'profile':
  65. $sLocation = $oProfile->getUrl();
  66. break;
  67. case 'custom':
  68. $sLocation = getParam('sys_account_switch_to_profile_redirect_custom');
  69. if(mb_stripos($sLocation, BX_DOL_URL_ROOT) !== 0)
  70. $sLocation = '';
  71. break;
  72. }
  73. if($sLocation != '') {
  74. header('Location: ' . $sLocation);
  75. exit;
  76. }
  77. }
  78. $sInformerMsg = _t('_sys_txt_account_profile_context_changed_success', $oProfile->getDisplayName());
  79. }
  80. else
  81. $sInformerMsg = $mixedRes;
  82. $oInformer = BxDolInformer::getInstance($this->_oTemplate);
  83. if($oInformer)
  84. $oInformer->add('sys-account-profile-context-change-result', $sInformerMsg ? $sInformerMsg : _t('_error occured'), true === $mixedRes ? BX_INFORMER_INFO : BX_INFORMER_ERROR);
  85. }
  86. }
  87. }
  88. protected function _isVisiblePage ($a, $bRedirectToLoginFormForUnauthenticated = false)
  89. {
  90. if (!isLogged()) {
  91. if ($bRedirectToLoginFormForUnauthenticated)
  92. $this->_redirectToLoginForm();
  93. else
  94. return false;
  95. }
  96. return parent::_isVisiblePage ($a, $bRedirectToLoginFormForUnauthenticated);
  97. }
  98. protected function _addJsCss()
  99. {
  100. parent::_addJsCss();
  101. $this->_oTemplate->addCss('account.css');
  102. }
  103. protected function _getPageCacheParams ()
  104. {
  105. $s = parent::_getPageCacheParams ();
  106. return $s . getLoggedId(); // cache is different for every account
  107. }
  108. }
  109. /** @} */