2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Edit user message preferences
20 * @package core_message
21 * @copyright 2008 Luis Rodrigues and Martin Dougiamas
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once(__DIR__
. '/../config.php');
26 require_once($CFG->dirroot
. '/message/lib.php');
27 require_once($CFG->dirroot
. '/user/lib.php');
29 $userid = optional_param('id', 0, PARAM_INT
); // User id.
36 $url = new moodle_url('/message/edit.php');
37 $url->param('id', $userid);
44 print_error('guestnoeditmessage', 'message');
47 if (!$user = $DB->get_record('user', array('id' => $userid))) {
48 print_error('invaliduserid');
51 $systemcontext = context_system
::instance();
52 $personalcontext = context_user
::instance($user->id
);
54 $PAGE->set_context($personalcontext);
55 $PAGE->set_pagelayout('admin');
57 // check access control
58 if ($user->id
== $USER->id
) {
59 //editing own message profile
60 require_capability('moodle/user:editownmessageprofile', $systemcontext);
63 // teachers, parents, etc.
64 require_capability('moodle/user:editmessageprofile', $personalcontext);
65 // no editing of guest user account
66 if (isguestuser($user->id
)) {
67 print_error('guestnoeditmessageother', 'message');
69 // no editing of admins by non admins!
70 if (is_siteadmin($user) and !is_siteadmin($USER)) {
71 print_error('useradmineditadmin');
73 $PAGE->navbar
->includesettingsbase
= true;
74 $PAGE->navigation
->extend_for_user($user);
77 /// Display page header
78 $strmessaging = get_string('messagepreferences', 'message');
79 $PAGE->set_title($strmessaging);
80 $PAGE->set_heading(fullname($user));
82 echo $OUTPUT->header();
84 // Open the message drawer to show the settings.
85 echo $OUTPUT->heading(get_string('messagepreferences', 'core_message'));
86 $PAGE->requires
->js_call_amd('core_message/message_drawer_helper', 'showSettings');
88 // Viewing another user's preferences so render the old page.
89 $renderer = $PAGE->get_renderer('core', 'message');
90 echo $renderer->render_user_message_preferences($user);
93 echo $OUTPUT->footer();