Merge branch 'MDL-74866-311-behat' of https://github.com/HuongNV13/moodle into MOODLE...
[moodle.git] / message / notificationpreferences.php
blob9a6ac52563fab1d1418fc6b1f6117ba4f9d37bcf
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 notification preferences
20 * @package core_message
21 * @copyright 2016 Ryan Wyllie <ryan@moodle.com>
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('userid', $USER->id, PARAM_INT); // User id.
30 $url = new moodle_url('/message/notificationpreferences.php');
31 $url->param('userid', $userid);
33 $PAGE->set_url($url);
35 require_login();
37 if (isguestuser()) {
38 print_error('guestnoeditmessage', 'message');
41 $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
43 $systemcontext = context_system::instance();
44 $personalcontext = context_user::instance($user->id);
46 $PAGE->set_context($personalcontext);
47 $PAGE->set_pagelayout('admin');
49 // Check access control.
50 if ($user->id == $USER->id) {
51 // Editing own message profile.
52 require_capability('moodle/user:editownmessageprofile', $systemcontext);
53 } else {
54 // Teachers, parents, etc.
55 require_capability('moodle/user:editmessageprofile', $personalcontext);
56 // No editing of guest user account.
57 if (isguestuser($user->id)) {
58 print_error('guestnoeditmessageother', 'message');
60 // No editing of admins by non admins!
61 if (is_siteadmin($user) and !is_siteadmin($USER)) {
62 print_error('useradmineditadmin');
64 $PAGE->navbar->includesettingsbase = true;
65 $PAGE->navigation->extend_for_user($user);
68 // Display page header.
69 $strmessaging = get_string('notificationpreferences', 'message');
70 $PAGE->set_title($strmessaging);
71 $PAGE->set_heading(fullname($user));
73 // Grab the renderer.
74 $renderer = $PAGE->get_renderer('core', 'message');
75 $messagingoptions = $renderer->render_user_notification_preferences($user);
77 echo $OUTPUT->header();
78 echo $messagingoptions;
79 echo $OUTPUT->footer();