MDL-49985 core_enrol: direct user to appropriate URL

This commit is contained in:
Mark Nelson 2015-05-04 22:14:01 -07:00
parent b3cb726431
commit 9542b15671
2 changed files with 14 additions and 3 deletions

View File

@ -26,6 +26,7 @@ require('../config.php');
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 @@ foreach ($forms as $form) {
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);
}
}

View File

@ -117,7 +117,9 @@ if (!empty($forum)) { // User is starting a new discussion in a forum
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 (!empty($forum)) { // User is starting a new discussion in a forum
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');