Commit 93d4824a authored by Richard Mansfield's avatar Richard Mansfield

When changing urlid on the settings page, force a page reload

Bug #1006634, part 1

When a user changes their own url on settings, force a full page
reload so that the profile link in the sideblock works.

Also cleans up existing code to force a reload after a change of theme
or language preference.

Change-Id: Ic9c216d3d295b1cd163fc4bba45a05cc010b7ddb
parent 6fe530c0
...@@ -222,31 +222,33 @@ function accountprefs_submit(Pieform $form, $values) { ...@@ -222,31 +222,33 @@ function accountprefs_submit(Pieform $form, $values) {
if (get_config('cleanurls') && isset($values['urlid']) && $values['urlid'] != $USER->get('urlid')) { if (get_config('cleanurls') && isset($values['urlid']) && $values['urlid'] != $USER->get('urlid')) {
$USER->urlid = $values['urlid']; $USER->urlid = $values['urlid'];
$USER->commit(); $USER->commit();
$reload = true;
} }
db_commit(); db_commit();
$updatelang = isset($values['lang']) && $values['lang'] != $oldlang; $returndata['message'] = get_string('prefssaved', 'account');
$updatetheme = isset($values['theme']) && $values['theme'] != $oldtheme;
if ($updatetheme) { if (isset($values['theme']) && $values['theme'] != $oldtheme) {
$USER->update_theme(); $USER->update_theme();
$message = get_string('prefssaved', 'account'); $reload = true;
} }
if ($updatelang) {
if (isset($values['lang']) && $values['lang'] != $oldlang) {
// The session language pref is used when the user has no user pref, // The session language pref is used when the user has no user pref,
// and when logged out. // and when logged out.
$SESSION->set('lang', $values['lang']); $SESSION->set('lang', $values['lang']);
$message = get_string_from_language($values['lang'], 'prefssaved', 'account'); $returndata['message'] = get_string_from_language($values['lang'], 'prefssaved', 'account');
$reload = true;
} }
if ($updatelang || $updatetheme) {
if (!empty($reload)) {
// Use PIEFORM_CANCEL here to force a page reload and show the new language. // Use PIEFORM_CANCEL here to force a page reload and show the new language.
$returndata['location'] = get_config('wwwroot') . 'account/index.php'; $returndata['location'] = get_config('wwwroot') . 'account/index.php';
$SESSION->add_ok_msg($message); $SESSION->add_ok_msg($returndata['message']);
$form->json_reply(PIEFORM_CANCEL, $returndata); $form->json_reply(PIEFORM_CANCEL, $returndata);
} }
$returndata['message'] = get_string('prefssaved', 'account');
$form->json_reply(PIEFORM_OK, $returndata); $form->json_reply(PIEFORM_OK, $returndata);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment