From 9542b15671bba2469e55ecd656f9881601aa6b29 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 4 May 2015 22:14:01 -0700 Subject: [PATCH] MDL-49985 core_enrol: direct user to appropriate URL --- enrol/index.php | 9 ++++++++- mod/forum/post.php | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/enrol/index.php b/enrol/index.php index 7969859c0d1c2..5e3d331611a75 100644 --- a/enrol/index.php +++ b/enrol/index.php @@ -26,6 +26,7 @@ require_once("$CFG->libdir/formslib.php"); $id = required_param('id', PARAM_INT); +$returnurl = optional_param('returnurl', 0, PARAM_LOCALURL); if (!isloggedin()) { $referer = clean_param(get_referer(), PARAM_LOCALURL); @@ -104,8 +105,14 @@ if (!$forms) { if (isguestuser()) { notice(get_string('noguestaccess', 'enrol'), get_login_url()); + } else if ($returnurl) { + notice(get_string('notenrollable', 'enrol'), $returnurl); } else { - notice(get_string('notenrollable', 'enrol'), "$CFG->wwwroot/index.php"); + $url = clean_param(get_referer(false), PARAM_LOCALURL); + if (empty($url)) { + $url = new moodle_url('/index.php'); + } + notice(get_string('notenrollable', 'enrol'), $url); } } diff --git a/mod/forum/post.php b/mod/forum/post.php index cbdb505ecaf8a..b7e1904a71b26 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -117,7 +117,9 @@ if (enrol_selfenrol_available($course->id)) { $SESSION->wantsurl = qualified_me(); $SESSION->enrolcancel = $_SERVER['HTTP_REFERER']; - redirect($CFG->wwwroot.'/enrol/index.php?id='.$course->id, get_string('youneedtoenrol')); + redirect(new moodle_url('/enrol/index.php', array('id' => $course->id, + 'returnurl' => '/mod/forum/view.php?f=' . $forum->id)), + get_string('youneedtoenrol')); } } } @@ -187,7 +189,9 @@ if (!is_enrolled($coursecontext)) { // User is a guest here! $SESSION->wantsurl = qualified_me(); $SESSION->enrolcancel = $_SERVER['HTTP_REFERER']; - redirect($CFG->wwwroot.'/enrol/index.php?id='.$course->id, get_string('youneedtoenrol')); + redirect(new moodle_url('/enrol/index.php', array('id' => $course->id, + 'returnurl' => '/mod/forum/view.php?f=' . $forum->id)), + get_string('youneedtoenrol')); } } print_error('nopostforum', 'forum');