MDL-49632 User preferences: Move preferences out of edit profile form.

This is a super confusing place to change your default text editor. Lets
make these things easy to find.

Part of MDL-45774
This commit is contained in:
Damyon Wiese 2015-04-08 13:07:46 +08:00 committed by Adrian Greeve
parent c78dbe03fb
commit 479fa47d0b
17 changed files with 632 additions and 39 deletions

View File

@ -1082,7 +1082,7 @@ $string['updateavailable_version'] = 'Version {$a}';
$string['updateavailableinstall'] = 'Install this update';
$string['updateavailablenot'] = 'Your Moodle code is up-to-date!';
$string['updatenotifications'] = 'Update notifications';
$string['updatenotificationfooter'] = 'Your Moodle site {$a->siteurl} is configured to automatically check for available updates. You are receiving this message as the administrator of the site. You can disable automatic checks for available updates in the Site administration section of the Administration block. You can customize the delivery of this message via your personal Messaging setting in the My profile settings section.';
$string['updatenotificationfooter'] = 'Your Moodle site {$a->siteurl} is configured to automatically check for available updates. You are receiving this message as the administrator of the site. You can disable automatic checks for available updates in the Site administration section of the Administration block. You can customize the delivery of this message via your personal Messaging setting in the My preferences section.';
$string['updatenotificationsubject'] = 'Moodle updates are available ({$a->siteurl})';
$string['updateautocheck'] = 'Automatically check for available updates';
$string['updateautocheck_desc'] = 'If enabled, your site will automatically check for available updates for both Moodle code and all additional plugins. If there is a new update available, a notification will be sent to site admins.';

View File

@ -552,6 +552,7 @@ $string['editordefaultfont'] = 'Default font';
$string['editorenablespelling'] = 'Enable spellchecking';
$string['editorfontlist'] = 'Fontlist';
$string['editorfontsize'] = 'Default font-size';
$string['editorpreferences'] = 'Editor preferences';
$string['editorresettodefaults'] = 'Reset to default values';
$string['editorsettings'] = 'Editor settings';
$string['editorshortcutkeys'] = 'Editor shortcut keys';
@ -818,6 +819,7 @@ $string['formatmarkdown'] = 'Markdown format';
$string['formatplain'] = 'Plain text format';
$string['formattext'] = 'Moodle auto-format';
$string['formattexttype'] = 'Formatting';
$string['forumpreferences'] = 'Forum preferences';
$string['framesetinfo'] = 'This frameset document contains:';
$string['from'] = 'From';
$string['frontpagecategorycombo'] = 'Combo list';

View File

@ -182,7 +182,7 @@ $string['shortnametaken'] = 'Short name is already used for another service ({$a
$string['simpleauthlog'] = 'Simple authentication login';
$string['step'] = 'Step';
$string['supplyinfo'] = 'More details';
$string['testauserwithtestclientdescription'] = 'Simulate external access to the service using the web service test client. Before doing so, login as a user with the moodle/webservice:createtoken capability and obtain the security key (token) via My profile settings. You will use this token in the test client. In the test client, also choose an enabled protocol with the token authentication. <strong>WARNING: The functions that you test WILL BE EXECUTED for this user, so be careful what you choose to test!</strong>';
$string['testauserwithtestclientdescription'] = 'Simulate external access to the service using the web service test client. Before doing so, login as a user with the moodle/webservice:createtoken capability and obtain the security key (token) via My preferences settings. You will use this token in the test client. In the test client, also choose an enabled protocol with the token authentication. <strong>WARNING: The functions that you test WILL BE EXECUTED for this user, so be careful what you choose to test!</strong>';
$string['testclient'] = 'Web service test client';
$string['testclientdescription'] = '* The web service test client <strong>executes</strong> the functions for <strong>REAL</strong>. Do not test functions that you don\'t know. <br/>* All existing web service functions are not yet implemented into the test client. <br/>* In order to check that a user cannot access some functions, you can test some functions that you didn\'t allow.<br/>* To see clearer error messages set the debugging to <strong>{$a->mode}</strong> into {$a->atag}<br/>* Access the {$a->amfatag}.';
$string['testwithtestclient'] = 'Test the service';
@ -197,7 +197,7 @@ $string['updateusersettings'] = 'Update';
$string['uploadfiles'] = 'Can upload files';
$string['uploadfiles_help'] = 'If enabled, any user can upload files with their security keys to their own private files area or a draft file area. Any user file quotas apply.';
$string['userasclients'] = 'Users as clients with token';
$string['userasclientsdescription'] = 'The following steps help you to set up the Moodle web service for users as clients. These steps also help to set up the recommended token (security keys) authentication method. In this use case, the user will generate his token from the security keys page via My profile settings.';
$string['userasclientsdescription'] = 'The following steps help you to set up the Moodle web service for users as clients. These steps also help to set up the recommended token (security keys) authentication method. In this use case, the user will generate his token from the security keys page via My preferences settings.';
$string['usermissingcaps'] = 'Missing capabilities: {$a}';
$string['usernameorid'] = 'Username / User id';
$string['usernameorid_help'] = 'Enter a username or a user id.';

View File

@ -4357,6 +4357,33 @@ class settings_navigation extends navigation_node {
$useraccount->add(get_string("changepassword"), $passwordchangeurl, self::TYPE_SETTING, null, 'changepassword');
}
if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
if ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext) ||
has_capability('moodle/user:editprofile', $usercontext)) {
$url = new moodle_url('/user/language.php', array('id'=>$user->id, 'course'=>$course->id));
$useraccount->add(get_string('preferredlanguage'), $url, self::TYPE_SETTING);
}
}
$pluginmanager = core_plugin_manager::instance();
$enabled = $pluginmanager->get_enabled_plugins('mod');
if (isset($enabled['forum']) && isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
if ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext) ||
has_capability('moodle/user:editprofile', $usercontext)) {
$url = new moodle_url('/user/forum.php', array('id'=>$user->id, 'course'=>$course->id));
$useraccount->add(get_string('forumpreferences'), $url, self::TYPE_SETTING);
}
}
$editors = editors_get_enabled();
if (count($editors) > 1) {
if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
if ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext) ||
has_capability('moodle/user:editprofile', $usercontext)) {
$url = new moodle_url('/user/editor.php', array('id'=>$user->id, 'course'=>$course->id));
$useraccount->add(get_string('editorpreferences'), $url, self::TYPE_SETTING);
}
}
}
// View the roles settings.
if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride','moodle/role:override', 'moodle/role:manage'),
$usercontext)) {

View File

@ -24,6 +24,7 @@
require_once(dirname(__FILE__) . '/../config.php');
require_once($CFG->dirroot . '/message/lib.php');
require_once($CFG->dirroot . '/user/lib.php');
$userid = optional_param('id', 0, PARAM_INT); // User id.
$disableall = optional_param('disableall', 0, PARAM_BOOL); //disable all of this user's notifications
@ -129,6 +130,9 @@ if (($form = data_submitted()) && confirm_sesskey()) {
print_error('cannotupdateusermsgpref');
}
$user->mailformat = $form->mailformat;
user_update_user($user, false, false);
redirect("$CFG->wwwroot/message/edit.php?id=$user->id");
}
@ -161,11 +165,13 @@ foreach ($processors as $processor) {
//load general messaging preferences
$preferences->blocknoncontacts = get_user_preferences( 'message_blocknoncontacts', '', $user->id);
$preferences->beepnewmessage = get_user_preferences( 'message_beepnewmessage', '', $user->id);
$preferences->mailformat = $user->mailformat;
$preferences->mailcharset = get_user_preferences( 'mailcharset', '', $user->id);
/// Display page header
$strmessaging = get_string('messaging', 'message');
$PAGE->set_title($strmessaging);
$PAGE->set_heading(fullname($USER));
$PAGE->set_heading(fullname($user));
// Grab the renderer
$renderer = $PAGE->get_renderer('core', 'message');

View File

@ -25,7 +25,7 @@
$string['allowattachments'] = 'Allow attachments';
$string['allowusermailcharset'] = 'Allow user to select character set';
$string['configallowattachments'] = 'If enabled, emails sent from the site can have attachments, such as badges.';
$string['configallowusermailcharset'] = 'If enabled, users can choose an email charset in their profile settings.';
$string['configallowusermailcharset'] = 'If enabled, users can choose an email charset in their messaging preferences.';
$string['configmailnewline'] = 'Newline characters used in mail messages. CRLF is required according to RFC 822bis, some mail servers do automatic conversion from LF to CRLF, other mail servers do incorrect conversion from CRLF to CRCRLF, yet others reject mails with bare LF (qmail for example). Try changing this setting if you are having problems with undelivered emails or double newlines.';
$string['confignoreplyaddress'] = 'Emails are sometimes sent out on behalf of a user (eg forum posts). The email address you specify here will be used as the "From" address in those cases when the recipients should not be able to reply directly to the user (eg when a user chooses to keep their address private).';
$string['configemailonlyfromnoreplyaddress'] = 'If enabled, all email will be sent using the no-reply address as the "from" address. This can be used to stop anti-spoofing controls in external mail systems blocking emails.';
@ -46,4 +46,4 @@ $string['smtphosts'] = 'SMTP hosts';
$string['smtpmaxbulk'] = 'SMTP session limit';
$string['smtppass'] = 'SMTP password';
$string['smtpsecure'] = 'SMTP security';
$string['smtpuser'] = 'SMTP username';
$string['smtpuser'] = 'SMTP username';

View File

@ -108,20 +108,45 @@ class message_output_email extends message_output {
*/
function config_form($preferences){
global $USER, $OUTPUT, $CFG;
$string = '';
if (empty($CFG->messagingallowemailoverride)) {
return null;
$choices = array();
$choices['0'] = get_string('textformat');
$choices['1'] = get_string('htmlformat');
$current = $preferences->mailformat;
$string .= $OUTPUT->container(html_writer::label(get_string('emailformat'), 'mailformat'));
$string .= $OUTPUT->container(html_writer::select($choices, 'mailformat', $current, false, array('id' => 'mailformat')));
if (!empty($CFG->allowusermailcharset)) {
$choices = array();
$charsets = get_list_of_charsets();
if (!empty($CFG->sitemailcharset)) {
$choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
} else {
$choices['0'] = get_string('site').' (UTF-8)';
}
$choices = array_merge($choices, $charsets);
$current = $preferences->mailcharset;
$string .= $OUTPUT->container(html_writer::label(get_string('emailcharset'), 'mailcharset'));
$string .= $OUTPUT->container(
html_writer::select($choices, 'preference_mailcharset', $current, false, array('id' => 'mailcharset'))
);
}
$inputattributes = array('size'=>'30', 'name'=>'email_email', 'value'=>$preferences->email_email);
$string = get_string('email','message_email') . ': ' . html_writer::empty_tag('input', $inputattributes);
if (!empty($CFG->messagingallowemailoverride)) {
$inputattributes = array('size'=>'30', 'name'=>'email_email', 'value'=>$preferences->email_email, 'id'=>'email_email');
$string .= html_writer::label(get_string('email','message_email'), 'email_email');
$string .= $OUTPUT->container(html_writer::empty_tag('input', $inputattributes));
if (empty($preferences->email_email) && !empty($preferences->userdefaultemail)) {
$string .= get_string('ifemailleftempty', 'message_email', $preferences->userdefaultemail);
}
if (empty($preferences->email_email) && !empty($preferences->userdefaultemail)) {
$string .= $OUTPUT->container(get_string('ifemailleftempty', 'message_email', $preferences->userdefaultemail));
}
if (!empty($preferences->email_email) && !validate_email($preferences->email_email)) {
$string .= $OUTPUT->container(get_string('invalidemail'), 'error');
if (!empty($preferences->email_email) && !validate_email($preferences->email_email)) {
$string .= $OUTPUT->container(get_string('invalidemail'), 'error');
}
$string .= '<br/>';
}
return $string;
@ -137,6 +162,9 @@ class message_output_email extends message_output {
if (isset($form->email_email)) {
$preferences['message_processor_email_email'] = $form->email_email;
}
if (isset($form->preference_mailcharset)) {
$preferences['mailcharset'] = $form->preference_mailcharset;
}
}
/**

View File

@ -284,7 +284,7 @@ if ($usernew = $userform->get_data()) {
}
if (!$emailchanged || !$CFG->emailchangeconfirmation) {
redirect("$CFG->wwwroot/user/preferences.php?id=$user->id&course=$course->id");
redirect("$CFG->wwwroot/user/preferences.php?userid=$user->id");
}
}

View File

@ -99,16 +99,6 @@ class user_edit_form extends moodleform {
$mform = $this->_form;
$userid = $mform->getElementValue('id');
// If language does not exist, use site default lang.
if ($langsel = $mform->getElementValue('lang')) {
$lang = reset($langsel);
// Check lang exists.
if (!get_string_manager()->translation_exists($lang, false)) {
$langel =& $mform->getElement('lang');
$langel->setValue($CFG->lang);
}
}
if ($user = $DB->get_record('user', array('id' => $userid))) {
// Remove description.

View File

@ -146,16 +146,6 @@ class user_editadvanced_form extends moodleform {
$user = false;
}
// If language does not exist, use site default lang.
if ($langsel = $mform->getElementValue('lang')) {
$lang = reset($langsel);
// Check lang exists.
if (!get_string_manager()->translation_exists($lang, false)) {
$langel =& $mform->getElement('lang');
$langel->setValue($CFG->lang);
}
}
// User can not change own auth method.
if ($userid == $USER->id) {
$mform->hardFreeze('auth');

View File

@ -33,6 +33,99 @@ function cancel_email_update($userid) {
unset_user_preference('newemailattemptsleft', $userid);
}
/**
* Performs the common access checks and page setup for all
* user preference pages.
*
* @param int $userid The user id to edit taken from the page params.
* @param int $courseid The optional course id if we came from a course context.
* @return array containing the user and course records.
*/
function useredit_setup_preference_page($userid, $courseid) {
global $PAGE, $SESSION, $DB, $CFG, $OUTPUT, $USER;
// Guest can not edit.
if (isguestuser()) {
print_error('guestnoeditprofile');
}
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('invalidcourseid');
}
if ($course->id != SITEID) {
require_login($course);
} else if (!isloggedin()) {
if (empty($SESSION->wantsurl)) {
$SESSION->wantsurl = $CFG->httpswwwroot.'/user/preferences.php';
}
redirect(get_login_url());
} else {
$PAGE->set_context(context_system::instance());
}
// The user profile we are editing.
if (!$user = $DB->get_record('user', array('id' => $userid))) {
print_error('invaliduserid');
}
// Guest can not be edited.
if (isguestuser($user)) {
print_error('guestnoeditprofile');
}
// Remote users cannot be edited.
if (is_mnet_remote_user($user)) {
if (user_not_fully_set_up($user)) {
$hostwwwroot = $DB->get_field('mnet_host', 'wwwroot', array('id' => $user->mnethostid));
print_error('usernotfullysetup', 'mnet', '', $hostwwwroot);
}
redirect($CFG->wwwroot . "/user/view.php?course={$course->id}");
}
$systemcontext = context_system::instance();
$personalcontext = context_user::instance($user->id);
// Check access control.
if ($user->id == $USER->id) {
// Editing own profile - require_login() MUST NOT be used here, it would result in infinite loop!
if (!has_capability('moodle/user:editownprofile', $systemcontext)) {
print_error('cannotedityourprofile');
}
} else {
// Teachers, parents, etc.
require_capability('moodle/user:editprofile', $personalcontext);
// No editing of guest user account.
if (isguestuser($user->id)) {
print_error('guestnoeditprofileother');
}
// No editing of primary admin!
if (is_siteadmin($user) and !is_siteadmin($USER)) { // Only admins may edit other admins.
print_error('useradmineditadmin');
}
}
if ($user->deleted) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('userdeleted'));
echo $OUTPUT->footer();
die;
}
$PAGE->set_pagelayout('admin');
$PAGE->set_context($personalcontext);
if ($USER->id != $user->id) {
$PAGE->navigation->extend_for_user($user);
} else {
if ($node = $PAGE->navigation->find('myprofile', navigation_node::TYPE_ROOTNODE)) {
$node->force_open();
}
}
return array($user, $course);
}
/**
* Loads the given users preferences into the given user object.
*
@ -220,6 +313,13 @@ function useredit_shared_definition(&$mform, $editoroptions, $filemanageroptions
$mform->setType('email', PARAM_RAW_TRIMMED);
}
$choices = array();
$choices['0'] = get_string('emaildisplayno');
$choices['1'] = get_string('emaildisplayyes');
$choices['2'] = get_string('emaildisplaycourse');
$mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
$mform->setDefault('maildisplay', $CFG->defaultpreference_maildisplay);
$mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"');
$mform->setType('city', PARAM_TEXT);
if (!empty($CFG->defaultcity)) {
@ -267,9 +367,6 @@ function useredit_shared_definition(&$mform, $editoroptions, $filemanageroptions
$mform->setType('description_editor', PARAM_CLEANHTML);
$mform->addHelpButton('description_editor', 'userdescription');
$mform->addElement('header', 'moodle_userpreferences', get_string('preferences'));
useredit_shared_definition_preferences($user, $mform, $editoroptions, $filemanageroptions);
if (empty($USER->newadminuser)) {
$mform->addElement('header', 'moodle_picture', get_string('pictureofuser'));

70
user/editor.php Normal file
View File

@ -0,0 +1,70 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Allows you to edit a users editor preferences
*
* @copyright 1999 Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_user
*/
require_once('../config.php');
require_once($CFG->libdir.'/gdlib.php');
require_once($CFG->dirroot.'/user/editor_form.php');
require_once($CFG->dirroot.'/user/editlib.php');
require_once($CFG->dirroot.'/user/lib.php');
$userid = optional_param('id', $USER->id, PARAM_INT); // User id.
$courseid = optional_param('course', SITEID, PARAM_INT); // Course id (defaults to Site).
$PAGE->set_url('/user/editor.php', array('id' => $userid, 'course' => $courseid));
list($user, $course) = useredit_setup_preference_page($userid, $courseid);
// Create form.
$editorform = new user_edit_editor_form(null, array('userid' => $user->id));
$user->preference_htmleditor = get_user_preferences( 'htmleditor', '', $user->id);
$editorform->set_data($user);
if ($data = $editorform->get_data()) {
$user->preference_htmleditor = $data->preference_htmleditor;
useredit_update_user_preference($user, false, false);
// Trigger event.
\core\event\user_updated::create_from_userid($user->id)->trigger();
redirect("$CFG->wwwroot/user/preferences.php?userid=$user->id");
}
// Display page header.
$streditmyeditor = get_string('editorpreferences');
$userfullname = fullname($user, true);
$PAGE->set_title("$course->shortname: $streditmyeditor");
$PAGE->set_heading($userfullname);
echo $OUTPUT->header();
echo $OUTPUT->heading($streditmyeditor);
// Finally display THE form.
$editorform->display();
// And proper footer.
echo $OUTPUT->footer();

70
user/editor_form.php Normal file
View File

@ -0,0 +1,70 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Form to edit a users editor preferences.
*
* @copyright 1999 Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_user
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
}
require_once($CFG->dirroot.'/lib/formslib.php');
/**
* Class user_edit_editor_form.
*
* @copyright 1999 Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_edit_editor_form extends moodleform {
/**
* Define the form.
*/
public function definition () {
global $CFG, $COURSE;
$mform = $this->_form;
$editors = editors_get_enabled();
if (count($editors) > 1) {
$choices = array('' => get_string('defaulteditor'));
$firsteditor = '';
foreach (array_keys($editors) as $editor) {
if (!$firsteditor) {
$firsteditor = $editor;
}
$choices[$editor] = get_string('pluginname', 'editor_' . $editor);
}
$mform->addElement('select', 'preference_htmleditor', get_string('textediting'), $choices);
$mform->setDefault('preference_htmleditor', '');
} else {
// Empty string means use the first chosen text editor.
$mform->addElement('hidden', 'preference_htmleditor');
$mform->setDefault('preference_htmleditor', '');
$mform->setType('preference_htmleditor', PARAM_PLUGIN);
}
$this->add_action_buttons(false, get_string('savechanges'));
}
}

71
user/forum.php Normal file
View File

@ -0,0 +1,71 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Allows you to edit a users forum preferences
*
* @copyright 1999 Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_user
*/
require_once('../config.php');
require_once($CFG->libdir.'/gdlib.php');
require_once($CFG->dirroot.'/user/forum_form.php');
require_once($CFG->dirroot.'/user/editlib.php');
require_once($CFG->dirroot.'/user/lib.php');
$userid = optional_param('id', $USER->id, PARAM_INT); // User id.
$courseid = optional_param('course', SITEID, PARAM_INT); // Course id (defaults to Site).
$PAGE->set_url('/user/forum.php', array('id' => $userid, 'course' => $courseid));
list($user, $course) = useredit_setup_preference_page($userid, $courseid);
// Create form.
$forumform = new user_edit_forum_form(null, array('userid' => $user->id));
$forumform->set_data($user);
if ($data = $forumform->get_data()) {
$user->maildigest = $data->maildigest;
$user->autosubscribe = $data->autosubscribe;
$user->trackforums = $data->trackforums;
user_update_user($user, false, false);
// Trigger event.
\core\event\user_updated::create_from_userid($user->id)->trigger();
redirect("$CFG->wwwroot/user/preferences.php?userid=$user->id");
}
// Display page header.
$streditmyforum = get_string('forumpreferences');
$userfullname = fullname($user, true);
$PAGE->set_title("$course->shortname: $streditmyforum");
$PAGE->set_heading($userfullname);
echo $OUTPUT->header();
echo $OUTPUT->heading($streditmyforum);
// Finally display THE form.
$forumform->display();
// And proper footer.
echo $OUTPUT->footer();

80
user/forum_form.php Normal file
View File

@ -0,0 +1,80 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Form to edit a users forum preferences. These are stored as columns in the user table, which
* is why they are in /user and not /mod/forum.
*
* @copyright 1999 Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_user
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
}
require_once($CFG->dirroot.'/lib/formslib.php');
/**
* Class user_edit_forum_form.
*
* @copyright 1999 Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_edit_forum_form extends moodleform {
/**
* Define the form.
*/
public function definition () {
global $CFG, $COURSE;
$mform = $this->_form;
$choices = array();
$choices['0'] = get_string('emaildigestoff');
$choices['1'] = get_string('emaildigestcomplete');
$choices['2'] = get_string('emaildigestsubjects');
$mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
$mform->setDefault('maildigest', $CFG->defaultpreference_maildigest);
$mform->addHelpButton('maildigest', 'emaildigest');
$choices = array();
$choices['1'] = get_string('autosubscribeyes');
$choices['0'] = get_string('autosubscribeno');
$mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
$mform->setDefault('autosubscribe', $CFG->defaultpreference_autosubscribe);
if (!empty($CFG->forum_trackreadposts)) {
$choices = array();
$choices['0'] = get_string('trackforumsno');
$choices['1'] = get_string('trackforumsyes');
$mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
$mform->setDefault('trackforums', $CFG->defaultpreference_trackforums);
}
// Add some extra hidden fields.
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'course', $COURSE->id);
$mform->setType('course', PARAM_INT);
$this->add_action_buttons(false, get_string('savechanges'));
}
}

74
user/language.php Normal file
View File

@ -0,0 +1,74 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Allows you to edit a users profile
*
* @copyright 1999 Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_user
*/
require_once('../config.php');
require_once($CFG->libdir.'/gdlib.php');
require_once($CFG->dirroot.'/user/language_form.php');
require_once($CFG->dirroot.'/user/editlib.php');
require_once($CFG->dirroot.'/user/lib.php');
$userid = optional_param('id', $USER->id, PARAM_INT); // User id.
$courseid = optional_param('course', SITEID, PARAM_INT); // Course id (defaults to Site).
$PAGE->set_url('/user/language.php', array('id' => $userid, 'course' => $courseid));
list($user, $course) = useredit_setup_preference_page($userid, $courseid);
// Create form.
$languageform = new user_edit_language_form(null, array('userid' => $user->id));
$languageform->set_data($user);
if ($data = $languageform->get_data()) {
$lang = $data->lang;
// If the specified language does not exist, use the site default.
if (!get_string_manager()->translation_exists($lang, false)) {
$lang = $CFG->lang;
}
$user->lang = $lang;
// Update user with new language.
user_update_user($user, false, false);
// Trigger event.
\core\event\user_updated::create_from_userid($user->id)->trigger();
redirect("$CFG->wwwroot/user/preferences.php?userid=$user->id");
}
// Display page header.
$streditmylanguage = get_string('preferredlanguage');
$userfullname = fullname($user, true);
$PAGE->set_title("$course->shortname: $streditmylanguage");
$PAGE->set_heading($userfullname);
echo $OUTPUT->header();
echo $OUTPUT->heading($userfullname);
// Finally display THE form.
$languageform->display();
// And proper footer.
echo $OUTPUT->footer();

88
user/language_form.php Normal file
View File

@ -0,0 +1,88 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Form to edit a users preferred language
*
* @copyright 1999 Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_user
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
}
require_once($CFG->dirroot.'/lib/formslib.php');
/**
* Class user_edit_form.
*
* @copyright 1999 Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_edit_language_form extends moodleform {
/**
* Define the form.
*/
public function definition () {
global $CFG, $COURSE, $USER;
$mform = $this->_form;
$userid = $USER->id;
if (is_array($this->_customdata)) {
if (array_key_exists('userid', $this->_customdata)) {
$userid = $this->_customdata['userid'];
}
}
// Add some extra hidden fields.
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'course', $COURSE->id);
$mform->setType('course', PARAM_INT);
$mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
$mform->setDefault('lang', $CFG->lang);
$this->add_action_buttons(false, get_string('savechanges'));
}
/**
* Extend the form definition after the data has been parsed.
*/
public function definition_after_data() {
global $CFG, $DB, $OUTPUT;
$mform = $this->_form;
// If language does not exist, use site default lang.
if ($langsel = $mform->getElementValue('lang')) {
$lang = reset($langsel);
// Check lang exists.
if (!get_string_manager()->translation_exists($lang, false)) {
$langel =& $mform->getElement('lang');
$langel->setValue($CFG->lang);
}
}
}
}