MDL-77049 core_h5p: Use the styles from Raw SCSS theme settings
[moodle.git] / message / edit.php
blob7882f3493f376c2cec93c5c9121dfab86e3771a1
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
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.
30 $currentuser = true;
32 if (!$userid) {
33 $userid = $USER->id;
36 $url = new moodle_url('/message/edit.php');
37 $url->param('id', $userid);
39 $PAGE->set_url($url);
41 require_login();
43 if (isguestuser()) {
44 throw new \moodle_exception('guestnoeditmessage', 'message');
47 if (!$user = $DB->get_record('user', array('id' => $userid))) {
48 throw new \moodle_exception('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);
61 } else {
62 $currentuser = false;
63 // teachers, parents, etc.
64 require_capability('moodle/user:editmessageprofile', $personalcontext);
65 // no editing of guest user account
66 if (isguestuser($user->id)) {
67 throw new \moodle_exception('guestnoeditmessageother', 'message');
69 // no editing of admins by non admins!
70 if (is_siteadmin($user) and !is_siteadmin($USER)) {
71 throw new \moodle_exception('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();
83 if ($currentuser) {
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');
87 } else {
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();