diff --git a/classes/class.ilUserTakeOverPlugin.php b/classes/class.ilUserTakeOverPlugin.php index 93ed36b..abd52cd 100644 --- a/classes/class.ilUserTakeOverPlugin.php +++ b/classes/class.ilUserTakeOverPlugin.php @@ -20,7 +20,7 @@ class ilUserTakeOverPlugin extends ilUserInterfaceHookPlugin { * @return ilUserTakeOverPlugin */ public static function getInstance() { - if (!isset(self::$instance)) { + if (! isset(self::$instance)) { self::$instance = new self(); } diff --git a/classes/class.ilUserTakeOverUIHookGUI.php b/classes/class.ilUserTakeOverUIHookGUI.php index 0ed433f..4d0bd49 100644 --- a/classes/class.ilUserTakeOverUIHookGUI.php +++ b/classes/class.ilUserTakeOverUIHookGUI.php @@ -2,6 +2,7 @@ /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */ require_once('./Services/UIComponent/classes/class.ilUIHookPluginGUI.php'); require_once './Customizing/global/plugins/Services/UIComponent/UserInterfaceHook/UserTakeOver/classes/class.usrtoGUI.php'; +require_once('./Customizing/global/plugins/Services/UIComponent/UserInterfaceHook/UserTakeOver/classes/class.usrtoHelper.php'); /** * Class ilUserTakeOverUIHookGUI @@ -58,17 +59,14 @@ public function getHTML($a_comp, $a_part, $a_par = array()) { * @var $rbacreview ilRbacReview * @var $ilUser ilObjUser */ - global $ilCtrl; if ($a_comp == 'Services/MainMenu') { if ($_SESSION['usrtoOriginalAccountId']) { $ilToolbar = new ilToolbarGUI(); - if (!self::isLoaded('user_take_back')) { + if (! self::isLoaded('user_take_back')) { if ($ilToolbar instanceof ilToolbarGUI) { $ilUserTakeOverPlugin = ilUserTakeOverPlugin::getInstance(); - $ilCtrl->setParameterByClass('usrtoGUI', 'cmd', usrtoGUI::CMD_PERFORM_USER_TAKE_BACK); - $link = $ilCtrl->getLinkTargetByClass(array( 'ilAdministrationGUI', 'ilRouterGUI', 'usrtoGUI' )); - + $link = 'goto.php?target=usr_takeback'; $html = '' . $ilUserTakeOverPlugin->txt("leave_user_view") . ''; self::setLoaded('user_take_back'); @@ -79,11 +77,11 @@ public function getHTML($a_comp, $a_part, $a_par = array()) { } } - if (!self::isLoaded('user_take_over')) { + if (! self::isLoaded('user_take_over')) { if ($_GET['cmdClass'] == 'ilobjusergui' AND ($_GET['cmd'] == 'view' OR $_GET['cmd'] == 'edit')) { global $rbacreview, $ilUser; // Only Administrators - if (!in_array(2, $rbacreview->assignedGlobalRoles($ilUser->getId()))) { + if (! in_array(2, $rbacreview->assignedGlobalRoles($ilUser->getId()))) { self::setLoaded('user_take_over'); return false; @@ -92,8 +90,7 @@ public function getHTML($a_comp, $a_part, $a_par = array()) { global $ilToolbar; if ($ilToolbar instanceof ilToolbarGUI) { $ilUserTakeOverPlugin = ilUserTakeOverPlugin::getInstance(); - $ilCtrl->setParameterByClass('usrtoGUI', usrtoGUI::USR_ID, $_GET['obj_id']); - $link = $ilCtrl->getLinkTargetByClass(array( 'ilAdministrationGUI', 'ilRouterGUI', 'usrtoGUI' )); + $link = 'goto.php?target=usr_takeover_' . $_GET['obj_id']; // TODO: Refactor in ILIAS 5.0: ilLinkButton::getInstance(); and $ilToolbar->addButtonInstance(); $ilToolbar->addButton($ilUserTakeOverPlugin->txt('take_over_user_view'), $link, '', '', 'take_over_user_view'); self::setLoaded('user_take_over'); @@ -101,6 +98,16 @@ public function getHTML($a_comp, $a_part, $a_par = array()) { } } } + + + public function gotoHook() { + if (preg_match("/usr_takeover_(.*)/uim", $_GET['target'], $matches)) { + usrtoHelper::getInstance()->takeOver($matches[1]); + } + if (preg_match("/usr_takeback/uim", $_GET['target'], $matches)) { + usrtoHelper::getInstance()->switchBack(); + } + } } ?> \ No newline at end of file diff --git a/classes/class.usrtoGUI.php b/classes/class.usrtoGUI.php deleted file mode 100644 index 597e5af..0000000 --- a/classes/class.usrtoGUI.php +++ /dev/null @@ -1,102 +0,0 @@ - - * @version 1.0.0 - * - * @ilCtrl_IsCalledBy usrtoGUI: ilRouterGUI - */ -class usrtoGUI { - - const CMD_STD = self::CMD_PERFORM_USER_TAKE_OVER; - const CMD_PERFORM_USER_TAKE_OVER = 'performUserTakeOver'; - const CMD_PERFORM_USER_TAKE_BACK = 'performUserTakeBack'; - const ACCOUNT_ID = 'AccountId'; - const USRTO_ORIGINAL_ACCOUNT_ID = 'usrtoOriginalAccountId'; - const USR_ID = 'usr_id'; - - - public function __construct() { - global $ilCtrl, $tpl, $lng, $ilTabs, $rbacreview, $ilUser, $ilLog; - /** - * @var $ilCtrl ilCtrl - * @var $tpl ilTemplate - * @var $lng ilLanguage - * @var $ilTabs ilTabsGUI - * @var $rbacreview ilRbacReview - * @var $ilUser ilObjUser - * @var $ilLog ilLog - */ - $this->ilCtrl = $ilCtrl; - $this->tpl = $tpl; - $this->lng = $lng; - $this->tabs = $ilTabs; - $this->rbacreview = $rbacreview; - $this->ilUser = $ilUser; - $this->ilLog = $ilLog; - $this->pl = ilUserTakeOverPlugin::getInstance(); - } - - - public function executeCommand() { - $cmd = $this->ilCtrl->getCmd(self::CMD_STD); - - switch ($cmd) { - case self::CMD_PERFORM_USER_TAKE_OVER: - $this->performUserTakeOver(); - break; - case self::CMD_PERFORM_USER_TAKE_BACK: - $this->performUserTakeBack(); - break; - } - } - - - public function performUserTakeOver() { - // Permission Check: Only Administrators - if (!in_array(2, $this->rbacreview->assignedGlobalRoles($this->ilUser->getId()))) { - ilUtil::sendFailure($this->pl->txt('no_permission'), true); - ilUtil::redirect(''); - - return false; - } - - if ($_GET[self::USR_ID]) { - $_SESSION[self::ACCOUNT_ID] = $_GET[self::USR_ID]; - $_SESSION[self::USRTO_ORIGINAL_ACCOUNT_ID] = $this->ilUser->getId(); - - $ilObjUser = new ilObjUser($_SESSION[self::ACCOUNT_ID]); - - $this->ilLog->write('Plugin usrto: ' . $this->ilUser->getLogin() . ' has taken over the user view of ' . $ilObjUser->getLogin()); - - ilUtil::sendSuccess(sprintf($this->pl->txt('user_taker_over_success'), $ilObjUser->getLogin()), true); - ilUtil::redirect(''); - } else { - ilUtil::sendFailure($this->pl->txt('user_taker_over_failure'), true); - } - } - - - public function performUserTakeBack() { - // No Permission Check. The existing Session usrtoOriginalAccountId is the permission check - if ($_SESSION[self::USRTO_ORIGINAL_ACCOUNT_ID]) { - $_SESSION[self::ACCOUNT_ID] = $_SESSION[self::USRTO_ORIGINAL_ACCOUNT_ID]; - - unset($_SESSION[self::USRTO_ORIGINAL_ACCOUNT_ID]); - - $ilObjUser = new ilObjUser($_SESSION[self::ACCOUNT_ID]); - - $this->ilLog->write('Plugin usrto: ' . $ilObjUser->getLogin() . ' has left the user view of ' . $this->ilUser->getLogin()); - - ilUtil::sendSuccess(sprintf($this->pl->txt('user_taker_back_success'), $ilObjUser->getLogin()), true); - ilUtil::redirect(''); - } else { - ilUtil::sendFailure($this->pl->txt('user_taker_over_failure'), true); - } - } -} - -?> \ No newline at end of file diff --git a/plugin.php b/plugin.php index c528441..378c334 100755 --- a/plugin.php +++ b/plugin.php @@ -1,8 +1,8 @@ \ No newline at end of file