Skip to content

Commit

Permalink
MDL-49985 core_enrol: direct user to appropriate URL
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed May 5, 2015
1 parent b3cb726 commit 9542b15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 8 additions & 1 deletion enrol/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
8 changes: 6 additions & 2 deletions mod/forum/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
}
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 9542b15

Please sign in to comment.