Commit | Line | Data |
---|---|---|
8c125526 RW |
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. | |
13 | // | |
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/>. | |
16 | ||
17 | /** | |
18 | * Edit user notification preferences | |
19 | * | |
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 | |
23 | */ | |
24 | ||
25 | require_once(__DIR__ . '/../config.php'); | |
26 | require_once($CFG->dirroot . '/message/lib.php'); | |
27 | require_once($CFG->dirroot . '/user/lib.php'); | |
28 | ||
bab2ec46 | 29 | $userid = optional_param('userid', $USER->id, PARAM_INT); // User id. |
8c125526 | 30 | $url = new moodle_url('/message/notificationpreferences.php'); |
bab2ec46 | 31 | $url->param('userid', $userid); |
8c125526 RW |
32 | |
33 | $PAGE->set_url($url); | |
34 | ||
35 | require_login(); | |
36 | ||
37 | if (isguestuser()) { | |
38 | print_error('guestnoeditmessage', 'message'); | |
39 | } | |
40 | ||
bab2ec46 | 41 | $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); |
8c125526 RW |
42 | |
43 | $systemcontext = context_system::instance(); | |
44 | $personalcontext = context_user::instance($user->id); | |
45 | ||
46 | $PAGE->set_context($personalcontext); | |
47 | $PAGE->set_pagelayout('admin'); | |
48 | ||
7b55aaa1 | 49 | // Check access control. |
8c125526 | 50 | if ($user->id == $USER->id) { |
7b55aaa1 | 51 | // Editing own message profile. |
8c125526 RW |
52 | require_capability('moodle/user:editownmessageprofile', $systemcontext); |
53 | } else { | |
7b55aaa1 | 54 | // Teachers, parents, etc. |
8c125526 | 55 | require_capability('moodle/user:editmessageprofile', $personalcontext); |
7b55aaa1 | 56 | // No editing of guest user account. |
8c125526 RW |
57 | if (isguestuser($user->id)) { |
58 | print_error('guestnoeditmessageother', 'message'); | |
59 | } | |
7b55aaa1 | 60 | // No editing of admins by non admins! |
8c125526 RW |
61 | if (is_siteadmin($user) and !is_siteadmin($USER)) { |
62 | print_error('useradmineditadmin'); | |
63 | } | |
64 | $PAGE->navbar->includesettingsbase = true; | |
65 | $PAGE->navigation->extend_for_user($user); | |
66 | } | |
67 | ||
7b55aaa1 | 68 | // Display page header. |
8c125526 RW |
69 | $strmessaging = get_string('notificationpreferences', 'message'); |
70 | $PAGE->set_title($strmessaging); | |
71 | $PAGE->set_heading(fullname($user)); | |
72 | ||
7b55aaa1 | 73 | // Grab the renderer. |
8c125526 RW |
74 | $renderer = $PAGE->get_renderer('core', 'message'); |
75 | $messagingoptions = $renderer->render_user_notification_preferences($user); | |
76 | ||
77 | echo $OUTPUT->header(); | |
78 | echo $messagingoptions; | |
79 | echo $OUTPUT->footer(); | |
80 |