Merge branch 'MDL-6074-master' of git://github.com/mihailges/moodle
[moodle.git] / message / edit.php
blob3117d9b52e1c509e0c8fbbf1065aa99e9b375a25
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.
31 if (!$userid) {
32 $userid = $USER->id;
35 $url = new moodle_url('/message/edit.php');
36 $url->param('id', $userid);
38 $PAGE->set_url($url);
40 require_login();
42 if (isguestuser()) {
43 print_error('guestnoeditmessage', 'message');
46 if (!$user = $DB->get_record('user', array('id' => $userid))) {
47 print_error('invaliduserid');
50 $systemcontext = context_system::instance();
51 $personalcontext = context_user::instance($user->id);
53 $PAGE->set_context($personalcontext);
54 $PAGE->set_pagelayout('admin');
56 // check access control
57 if ($user->id == $USER->id) {
58 //editing own message profile
59 require_capability('moodle/user:editownmessageprofile', $systemcontext);
60 } else {
61 // teachers, parents, etc.
62 require_capability('moodle/user:editmessageprofile', $personalcontext);
63 // no editing of guest user account
64 if (isguestuser($user->id)) {
65 print_error('guestnoeditmessageother', 'message');
67 // no editing of admins by non admins!
68 if (is_siteadmin($user) and !is_siteadmin($USER)) {
69 print_error('useradmineditadmin');
71 $PAGE->navbar->includesettingsbase = true;
72 $PAGE->navigation->extend_for_user($user);
75 /// Display page header
76 $strmessaging = get_string('messagepreferences', 'message');
77 $PAGE->set_title($strmessaging);
78 $PAGE->set_heading(fullname($user));
80 // Grab the renderer
81 $renderer = $PAGE->get_renderer('core', 'message');
82 $messagingoptions = $renderer->render_user_message_preferences($user);
84 echo $OUTPUT->header();
85 echo $messagingoptions;
86 echo $OUTPUT->footer();