Merge branch 'MDL-50120-master' of git://github.com/FMCorz/moodle

This commit is contained in:
Dan Poltawski 2015-05-07 10:52:25 +01:00
commit fad8ee28f1
3 changed files with 32 additions and 9 deletions

View File

@ -74,7 +74,8 @@ function core_myprofile_navigation(core_user\output\myprofile\tree $tree, $user,
if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
if (($iscurrentuser || is_siteadmin($USER) || !is_siteadmin($user)) && has_capability('moodle/user:update',
$systemcontext)) {
$url = new moodle_url('/user/editadvanced.php', array('id' => $user->id, 'course' => $courseid));
$url = new moodle_url('/user/editadvanced.php', array('id' => $user->id, 'course' => $courseid,
'returnto' => 'profile'));
$node = new core_user\output\myprofile\node('contact', 'editprofile', get_string('editmyprofile'), null, $url);
$tree->add_node($node);
} else if ((has_capability('moodle/user:editprofile', $usercontext) && !is_siteadmin($user))
@ -87,9 +88,10 @@ function core_myprofile_navigation(core_user\output\myprofile\tree $tree, $user,
$url = $userauthplugin->edit_profile_url();
if (empty($url)) {
if (empty($course)) {
$url = new moodle_url('/user/edit.php', array('userid' => $user->id));
$url = new moodle_url('/user/edit.php', array('userid' => $user->id, 'returnto' => 'profile'));
} else {
$url = new moodle_url('/user/edit.php', array('userid' => $user->id, 'course' => $course->id));
$url = new moodle_url('/user/edit.php', array('userid' => $user->id, 'course' => $course->id,
'returnto' => 'profile'));
}
}
$node = new core_user\output\myprofile\node('contact', 'editprofile',

View File

@ -34,6 +34,7 @@ $PAGE->https_required();
$userid = optional_param('id', $USER->id, PARAM_INT); // User id.
$course = optional_param('course', SITEID, PARAM_INT); // Course id (defaults to Site).
$returnto = optional_param('returnto', null, PARAM_ALPHA); // Code determining where to return to after save.
$cancelemailchange = optional_param('cancelemailchange', 0, PARAM_INT); // Course id (defaults to Site).
$PAGE->set_url('/user/edit.php', array('course' => $course, 'id' => $userid));
@ -172,7 +173,7 @@ $filemanageroptions = array('maxbytes' => $CFG->maxbytes,
file_prepare_draft_area($draftitemid, $filemanagercontext->id, 'user', 'newicon', 0, $filemanageroptions);
$user->imagefile = $draftitemid;
// Create form.
$userform = new user_edit_form(null, array(
$userform = new user_edit_form(new moodle_url($PAGE->url, array('returnto' => $returnto)), array(
'editoroptions' => $editoroptions,
'filemanageroptions' => $filemanageroptions,
'user' => $user));
@ -181,6 +182,17 @@ $emailchanged = false;
if ($usernew = $userform->get_data()) {
// Deciding where to send the user back in most cases.
if ($returnto === 'profile') {
if ($course->id != SITEID) {
$returnurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
} else {
$returnurl = new moodle_url('/user/profile.php', array('id' => $user->id));
}
} else {
$returnurl = new moodle_url('/user/preferences.php', array('userid' => $user->id));
}
$emailchangedhtml = '';
if ($CFG->emailchangeconfirmation) {
@ -194,8 +206,7 @@ if ($usernew = $userform->get_data()) {
$a->oldemail = $usernew->email = $user->email;
$emailchangedhtml = $OUTPUT->box(get_string('auth_changingemailaddress', 'auth', $a), 'generalbox', 'notice');
$emailchangedhtml .=
$OUTPUT->continue_button("$CFG->wwwroot/user/preferences.php?userid=$user->id&course=$course->id");
$emailchangedhtml .= $OUTPUT->continue_button($returnurl);
$emailchanged = true;
}
}
@ -285,7 +296,7 @@ if ($usernew = $userform->get_data()) {
}
if (!$emailchanged || !$CFG->emailchangeconfirmation) {
redirect("$CFG->wwwroot/user/preferences.php?userid=$user->id");
redirect($returnurl);
}
}

View File

@ -35,6 +35,7 @@ $PAGE->https_required();
$id = optional_param('id', $USER->id, PARAM_INT); // User id; -1 if creating new user.
$course = optional_param('course', SITEID, PARAM_INT); // Course id (defaults to Site).
$returnto = optional_param('returnto', null, PARAM_ALPHA); // Code determining where to return to after save.
$PAGE->set_url('/user/editadvanced.php', array('course' => $course, 'id' => $id));
@ -153,7 +154,7 @@ $filemanageroptions = array('maxbytes' => $CFG->maxbytes,
file_prepare_draft_area($draftitemid, $filemanagercontext->id, 'user', 'newicon', 0, $filemanageroptions);
$user->imagefile = $draftitemid;
// Create form.
$userform = new user_editadvanced_form(null, array(
$userform = new user_editadvanced_form(new moodle_url($PAGE->url, array('returnto' => $returnto)), array(
'editoroptions' => $editoroptions,
'filemanageroptions' => $filemanageroptions,
'user' => $user));
@ -293,7 +294,16 @@ if ($usernew = $userform->get_data()) {
// Somebody double clicked when editing admin user during install.
redirect("$CFG->wwwroot/$CFG->admin/");
} else {
redirect("$CFG->wwwroot/user/preferences.php?userid=$USER->id&course=$course->id");
if ($returnto === 'profile') {
if ($course->id != SITEID) {
$returnurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
} else {
$returnurl = new moodle_url('/user/profile.php', array('id' => $user->id));
}
} else {
$returnurl = new moodle_url('/user/preferences.php', array('userid' => $user->id));
}
redirect($returnurl);
}
} else {
\core\session\manager::gc(); // Remove stale sessions.