MDL-54708 message: notification popover respects message preferences
[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.
3b120e46 30
59d52284
DC
31if (!$userid) {
32 $userid = $USER->id;
33}
34
a6855934 35$url = new moodle_url('/message/edit.php');
ff038e4b 36$url->param('id', $userid);
ff038e4b 37
eb5334ff 38$PAGE->set_url($url);
26e02d75 39$PAGE->set_popup_notification_allowed(false); // We are within the messaging system so don't show message popups
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 {
62 // teachers, parents, etc.
63 require_capability('moodle/user:editmessageprofile', $personalcontext);
64 // no editing of guest user account
65 if (isguestuser($user->id)) {
66 print_error('guestnoeditmessageother', 'message');
67 }
4f622c38 68 // no editing of admins by non admins!
1e725535 69 if (is_siteadmin($user) and !is_siteadmin($USER)) {
4f622c38 70 print_error('useradmineditadmin');
3b120e46 71 }
f495187d 72 $PAGE->navbar->includesettingsbase = true;
5ac851fb 73 $PAGE->navigation->extend_for_user($user);
eb5334ff 74}
3b120e46 75
eb5334ff 76/// Display page header
058dadb0
AD
77$strmessaging = get_string('messaging', 'message');
78$PAGE->set_title($strmessaging);
479fa47d 79$PAGE->set_heading(fullname($user));
3b120e46 80
814e3735
RK
81// Grab the renderer
82$renderer = $PAGE->get_renderer('core', 'message');
a0eabdd3 83$messagingoptions = $renderer->render_user_preferences($user);
d18b1bbd 84
814e3735
RK
85echo $OUTPUT->header();
86echo $messagingoptions;
eb5334ff 87echo $OUTPUT->footer();
3b120e46 88