BxBasePageAccount.php 4.6 KB

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