diff --git a/index.php b/index.php index 9a0e8eb6c1..cfaf86f9ed 100755 --- a/index.php +++ b/index.php @@ -1,16 +1,23 @@ get_installed_plugins(); - $redirectionInstalled = in_array('redirection', $pluginList); - if ($redirectionInstalled) { - $pluginInfo = $plugin->getPluginInfo('redirection'); - if (!empty($pluginInfo) && isset($pluginInfo['obj'])) { - /** @var RedirectionPlugin $redirectionPlugin */ - $redirectionPlugin = $pluginInfo['obj']; - $record = $redirectionPlugin->getUrlFromUser($user_id); - if (!empty($record) && !empty($record['url'])) { - header('Location: '.$record['url']); - exit; - } - } + $allow = api_get_configuration_value('plugin_redirection_enabled'); + if ($allow) { + RedirectionPlugin::redirectUser($user_id); } } @@ -143,7 +131,6 @@ class Redirect if (!empty($page_after_login)) { self::navigate(api_get_path(WEB_PATH).$page_after_login); } - } } diff --git a/plugin/redirection/README.md b/plugin/redirection/README.md index 77478624f7..a61228f703 100644 --- a/plugin/redirection/README.md +++ b/plugin/redirection/README.md @@ -1,7 +1,8 @@ Redirection plugin === -Chamilo plugin for the redirection of specific users after they login. +Chamilo plugin for the redirection of specific users after they login and +redirect from the index.php to the selected URL. Requires the addition of the following in configuration.php: @@ -12,4 +13,4 @@ $_configuration['plugin_redirection_enabled'] = true; This setting is defined in configuration.php rather than in settings_current to reduce the load, as it is used on every login. -@TODO Check the load difference for *just* checking it in settings_current rather than building the plugin object \ No newline at end of file +@TODO Check the load difference for *just* checking it in settings_current rather than building the plugin object diff --git a/plugin/redirection/RedirectionPlugin.php b/plugin/redirection/RedirectionPlugin.php index a4c6c7fafe..e5c8a8bdc4 100644 --- a/plugin/redirection/RedirectionPlugin.php +++ b/plugin/redirection/RedirectionPlugin.php @@ -129,4 +129,28 @@ class RedirectionPlugin extends Plugin $sql = "DROP TABLE IF EXISTS $table"; Database::query($sql); } + + /** + * Redirect user if plugin is installed + * @param int $userId + */ + public static function redirectUser($userId) + { + // Check redirection plugin + $plugin = new AppPlugin(); + $pluginList = $plugin->get_installed_plugins(); + $redirectionInstalled = in_array('redirection', $pluginList); + if ($redirectionInstalled) { + $pluginInfo = $plugin->getPluginInfo('redirection'); + if (!empty($pluginInfo) && isset($pluginInfo['obj'])) { + /** @var RedirectionPlugin $redirectionPlugin */ + $redirectionPlugin = $pluginInfo['obj']; + $record = $redirectionPlugin->getUrlFromUser($userId); + if (!empty($record) && !empty($record['url'])) { + header('Location: '.$record['url']); + exit; + } + } + } + } }