weekly release 3.10.1+
[moodle.git] / message / edit.php
CommitLineData
eb5334ff 1<?php
eb5334ff 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/>.
3b120e46 16
17/**
18 * Edit user message preferences
19 *
6fbd60ef
AD
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
3b120e46 23 */
24
1fcf0ca8 25require_once(__DIR__ . '/../config.php');
60bbe768 26require_once($CFG->dirroot . '/message/lib.php');
479fa47d 27require_once($CFG->dirroot . '/user/lib.php');
3b120e46 28
59d52284 29$userid = optional_param('id', 0, PARAM_INT); // User id.
17d982d7 30$currentuser = true;
3b120e46 31
59d52284
DC
32if (!$userid) {
33 $userid = $USER->id;
34}
35
a6855934 36$url = new moodle_url('/message/edit.php');
ff038e4b 37$url->param('id', $userid);
ff038e4b 38
eb5334ff 39$PAGE->set_url($url);
3b120e46 40
5e008d36 41require_login();
3b120e46 42
eb5334ff 43if (isguestuser()) {
44 print_error('guestnoeditmessage', 'message');
45}
3b120e46 46
eb5334ff 47if (!$user = $DB->get_record('user', array('id' => $userid))) {
48 print_error('invaliduserid');
49}
3b120e46 50
bf0f06b1
AA
51$systemcontext = context_system::instance();
52$personalcontext = context_user::instance($user->id);
3b120e46 53
5ac851fb 54$PAGE->set_context($personalcontext);
d5814f4e 55$PAGE->set_pagelayout('admin');
3b120e46 56
eb5334ff 57// check access control
58if ($user->id == $USER->id) {
59 //editing own message profile
60 require_capability('moodle/user:editownmessageprofile', $systemcontext);
eb5334ff 61} else {
17d982d7 62 $currentuser = false;
eb5334ff 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');
68 }
4f622c38 69 // no editing of admins by non admins!
1e725535 70 if (is_siteadmin($user) and !is_siteadmin($USER)) {
4f622c38 71 print_error('useradmineditadmin');
3b120e46 72 }
f495187d 73 $PAGE->navbar->includesettingsbase = true;
5ac851fb 74 $PAGE->navigation->extend_for_user($user);
eb5334ff 75}
3b120e46 76
eb5334ff 77/// Display page header
14501b1c 78$strmessaging = get_string('messagepreferences', 'message');
058dadb0 79$PAGE->set_title($strmessaging);
479fa47d 80$PAGE->set_heading(fullname($user));
3b120e46 81
814e3735 82echo $OUTPUT->header();
17d982d7
RW
83if ($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);
91}
92
eb5334ff 93echo $OUTPUT->footer();
3b120e46 94