/** * Switch the active organization */ public function changeUiAction() { $request = $this->getRequest(); $orgId = urldecode($request->getParam('org')); $oldOrg = $this->currentUser->getCurrentOrganizationId(); $origUrl = base64_decode($request->getParam('current_uri')); $allowedOrganizations = $this->currentUser->getAllowedOrganizations(); if (isset($allowedOrganizations[$orgId])) { $this->currentUser->setCurrentOrganization($orgId); if ($origUrl) { // Check for organisation id in url, but not when a patient id is stated if (strpos($origUrl, '/' . \MUtil_Model::REQUEST_ID1 . '/') === false) { foreach ($this->currentUser->possibleOrgIds as $key) { $finds[] = '/' . $key . '/' . $oldOrg; $replaces[] = '/' . $key . '/' . $orgId; } $correctUrl = str_replace($finds, $replaces, $origUrl); } else { $correctUrl = $origUrl; } // \MUtil_Echo::track($origUrl, $correctUrl); $this->getResponse()->setRedirect($correctUrl); } else { $this->currentUser->gotoStartPage($this->menu, $request); } return; } throw new \Gems_Exception($this->_('Inaccessible or unknown organization'), 403, null, sprintf($this->_('Access to this page is not allowed for current role: %s.'), $this->currentUser->getRole())); }
/** * Helper function to safely switch org during login * * @param \Gems_User_User $user */ protected function setCurrentOrganizationTo(\Gems_User_User $user) { if ($this->currentUser !== $user) { $this->currentUser->setCurrentOrganization($user->getCurrentOrganization()); } }