From 479fa47d0b5987f6b04676515466eab66558f0c0 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Wed, 8 Apr 2015 13:07:46 +0800 Subject: [PATCH] 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 --- lang/en/admin.php | 2 +- lang/en/moodle.php | 2 + lang/en/webservice.php | 4 +- lib/navigationlib.php | 27 +++++ message/edit.php | 8 +- .../output/email/lang/en/message_email.php | 4 +- message/output/email/message_output_email.php | 48 ++++++-- user/edit.php | 2 +- user/edit_form.php | 10 -- user/editadvanced_form.php | 10 -- user/editlib.php | 103 +++++++++++++++++- user/editor.php | 70 ++++++++++++ user/editor_form.php | 70 ++++++++++++ user/forum.php | 71 ++++++++++++ user/forum_form.php | 80 ++++++++++++++ user/language.php | 74 +++++++++++++ user/language_form.php | 88 +++++++++++++++ 17 files changed, 633 insertions(+), 40 deletions(-) create mode 100644 user/editor.php create mode 100644 user/editor_form.php create mode 100644 user/forum.php create mode 100644 user/forum_form.php create mode 100644 user/language.php create mode 100644 user/language_form.php diff --git a/lang/en/admin.php b/lang/en/admin.php index e6ea984b4da61..423ddda476d89 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -1082,7 +1082,7 @@ $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.'; diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 6287de57b3212..987874f729287 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -552,6 +552,7 @@ $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['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'; diff --git a/lang/en/webservice.php b/lang/en/webservice.php index 83e10564e5848..46fbb2feda8a5 100644 --- a/lang/en/webservice.php +++ b/lang/en/webservice.php @@ -182,7 +182,7 @@ $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. WARNING: The functions that you test WILL BE EXECUTED for this user, so be careful what you choose to test!'; +$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. WARNING: The functions that you test WILL BE EXECUTED for this user, so be careful what you choose to test!'; $string['testclient'] = 'Web service test client'; $string['testclientdescription'] = '* The web service test client executes the functions for REAL. Do not test functions that you don\'t know.
* All existing web service functions are not yet implemented into the test client.
* In order to check that a user cannot access some functions, you can test some functions that you didn\'t allow.
* To see clearer error messages set the debugging to {$a->mode} into {$a->atag}
* Access the {$a->amfatag}.'; $string['testwithtestclient'] = 'Test the service'; @@ -197,7 +197,7 @@ $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.'; diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 387a7d8c0eac7..98eaff5cc58b4 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -4357,6 +4357,33 @@ protected function generate_user_settings($courseid, $userid, $gstitle='usercurr $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)) { diff --git a/message/edit.php b/message/edit.php index 55daa9f942b51..aba110db878b5 100644 --- a/message/edit.php +++ b/message/edit.php @@ -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 @@ 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 @@ //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'); diff --git a/message/output/email/lang/en/message_email.php b/message/output/email/lang/en/message_email.php index c565f0d0eeb9b..a276f2e2837d1 100644 --- a/message/output/email/lang/en/message_email.php +++ b/message/output/email/lang/en/message_email.php @@ -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['smtpmaxbulk'] = 'SMTP session limit'; $string['smtppass'] = 'SMTP password'; $string['smtpsecure'] = 'SMTP security'; -$string['smtpuser'] = 'SMTP username'; \ No newline at end of file +$string['smtpuser'] = 'SMTP username'; diff --git a/message/output/email/message_output_email.php b/message/output/email/message_output_email.php index 1970606c09dd4..dcc5b46f3bcf2 100644 --- a/message/output/email/message_output_email.php +++ b/message/output/email/message_output_email.php @@ -108,20 +108,45 @@ function send_message($eventdata) { */ function config_form($preferences){ global $USER, $OUTPUT, $CFG; - - if (empty($CFG->messagingallowemailoverride)) { - return null; + $string = ''; + + $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 .= '
'; } return $string; @@ -137,6 +162,9 @@ function process_form($form, &$preferences){ if (isset($form->email_email)) { $preferences['message_processor_email_email'] = $form->email_email; } + if (isset($form->preference_mailcharset)) { + $preferences['mailcharset'] = $form->preference_mailcharset; + } } /** diff --git a/user/edit.php b/user/edit.php index 792539d2bb8b7..49da9f27df548 100644 --- a/user/edit.php +++ b/user/edit.php @@ -284,7 +284,7 @@ } 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"); } } diff --git a/user/edit_form.php b/user/edit_form.php index 3603a1029eea8..65e86076d8962 100644 --- a/user/edit_form.php +++ b/user/edit_form.php @@ -99,16 +99,6 @@ public function definition_after_data() { $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. diff --git a/user/editadvanced_form.php b/user/editadvanced_form.php index f6b2a45cacbc3..ea95370ae08f6 100644 --- a/user/editadvanced_form.php +++ b/user/editadvanced_form.php @@ -146,16 +146,6 @@ public function definition_after_data() { $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'); diff --git a/user/editlib.php b/user/editlib.php index a43624bfef68e..205f6df3043c1 100644 --- a/user/editlib.php +++ b/user/editlib.php @@ -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')); diff --git a/user/editor.php b/user/editor.php new file mode 100644 index 0000000000000..57ebaafe1859b --- /dev/null +++ b/user/editor.php @@ -0,0 +1,70 @@ +. + +/** + * 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(); + diff --git a/user/editor_form.php b/user/editor_form.php new file mode 100644 index 0000000000000..e11468ba54423 --- /dev/null +++ b/user/editor_form.php @@ -0,0 +1,70 @@ +. + +/** + * 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')); + } +} + + diff --git a/user/forum.php b/user/forum.php new file mode 100644 index 0000000000000..4947d2ca333a4 --- /dev/null +++ b/user/forum.php @@ -0,0 +1,71 @@ +. + +/** + * 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(); + diff --git a/user/forum_form.php b/user/forum_form.php new file mode 100644 index 0000000000000..2a037f1b347f9 --- /dev/null +++ b/user/forum_form.php @@ -0,0 +1,80 @@ +. + +/** + * 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')); + } +} + + diff --git a/user/language.php b/user/language.php new file mode 100644 index 0000000000000..2feb2c29ad1f4 --- /dev/null +++ b/user/language.php @@ -0,0 +1,74 @@ +. + +/** + * 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(); + diff --git a/user/language_form.php b/user/language_form.php new file mode 100644 index 0000000000000..36f0ef5ae73b1 --- /dev/null +++ b/user/language_form.php @@ -0,0 +1,88 @@ +. + +/** + * 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); + } + } + + } + +} + +