2009-09-29 03:54:14 +00:00
|
|
|
<?php
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2008-07-24 08:38:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit user message preferences
|
|
|
|
*
|
2012-01-05 12:05:02 +07:00
|
|
|
* @package core_message
|
|
|
|
* @copyright 2008 Luis Rodrigues and Martin Dougiamas
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2008-07-24 08:38:03 +00:00
|
|
|
*/
|
|
|
|
|
2016-02-26 17:47:58 +11:00
|
|
|
require_once(__DIR__ . '/../config.php');
|
2011-05-31 15:16:17 +01:00
|
|
|
require_once($CFG->dirroot . '/message/lib.php');
|
2015-04-08 13:07:46 +08:00
|
|
|
require_once($CFG->dirroot . '/user/lib.php');
|
2008-07-24 08:38:03 +00:00
|
|
|
|
2015-01-19 13:16:48 +08:00
|
|
|
$userid = optional_param('id', 0, PARAM_INT); // User id.
|
2018-10-16 11:52:54 +08:00
|
|
|
$currentuser = true;
|
2008-07-24 08:38:03 +00:00
|
|
|
|
2015-01-19 13:16:48 +08:00
|
|
|
if (!$userid) {
|
|
|
|
$userid = $USER->id;
|
|
|
|
}
|
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$url = new moodle_url('/message/edit.php');
|
2012-03-08 14:45:45 +07:00
|
|
|
$url->param('id', $userid);
|
|
|
|
|
2009-09-29 03:54:14 +00:00
|
|
|
$PAGE->set_url($url);
|
2008-07-24 08:38:03 +00:00
|
|
|
|
2012-10-22 16:46:39 +08:00
|
|
|
require_login();
|
2008-07-24 08:38:03 +00:00
|
|
|
|
2009-09-29 03:54:14 +00:00
|
|
|
if (isguestuser()) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('guestnoeditmessage', 'message');
|
2009-09-29 03:54:14 +00:00
|
|
|
}
|
2008-07-24 08:38:03 +00:00
|
|
|
|
2009-09-29 03:54:14 +00:00
|
|
|
if (!$user = $DB->get_record('user', array('id' => $userid))) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('invaliduserid');
|
2009-09-29 03:54:14 +00:00
|
|
|
}
|
2008-07-24 08:38:03 +00:00
|
|
|
|
2012-08-02 11:20:48 +08:00
|
|
|
$systemcontext = context_system::instance();
|
|
|
|
$personalcontext = context_user::instance($user->id);
|
2008-07-24 08:38:03 +00:00
|
|
|
|
2010-07-13 02:35:31 +00:00
|
|
|
$PAGE->set_context($personalcontext);
|
2013-10-19 12:22:12 +02:00
|
|
|
$PAGE->set_pagelayout('admin');
|
2008-07-24 08:38:03 +00:00
|
|
|
|
2009-09-29 03:54:14 +00:00
|
|
|
// check access control
|
|
|
|
if ($user->id == $USER->id) {
|
|
|
|
//editing own message profile
|
|
|
|
require_capability('moodle/user:editownmessageprofile', $systemcontext);
|
|
|
|
} else {
|
2018-10-16 11:52:54 +08:00
|
|
|
$currentuser = false;
|
2009-09-29 03:54:14 +00:00
|
|
|
// teachers, parents, etc.
|
|
|
|
require_capability('moodle/user:editmessageprofile', $personalcontext);
|
|
|
|
// no editing of guest user account
|
|
|
|
if (isguestuser($user->id)) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('guestnoeditmessageother', 'message');
|
2009-09-29 03:54:14 +00:00
|
|
|
}
|
2010-08-12 09:44:28 +00:00
|
|
|
// no editing of admins by non admins!
|
2010-09-17 19:35:21 +00:00
|
|
|
if (is_siteadmin($user) and !is_siteadmin($USER)) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('useradmineditadmin');
|
2008-07-24 08:38:03 +00:00
|
|
|
}
|
2015-03-19 10:59:27 +08:00
|
|
|
$PAGE->navbar->includesettingsbase = true;
|
2010-07-13 02:35:31 +00:00
|
|
|
$PAGE->navigation->extend_for_user($user);
|
2009-09-29 03:54:14 +00:00
|
|
|
}
|
2008-07-24 08:38:03 +00:00
|
|
|
|
2009-09-29 03:54:14 +00:00
|
|
|
/// Display page header
|
2016-08-16 07:03:58 +00:00
|
|
|
$strmessaging = get_string('messagepreferences', 'message');
|
2012-11-01 09:42:11 +08:00
|
|
|
$PAGE->set_title($strmessaging);
|
2015-04-08 13:07:46 +08:00
|
|
|
$PAGE->set_heading(fullname($user));
|
2008-07-24 08:38:03 +00:00
|
|
|
|
2011-05-17 10:47:21 +01:00
|
|
|
echo $OUTPUT->header();
|
2018-10-16 11:52:54 +08:00
|
|
|
if ($currentuser) {
|
|
|
|
// Open the message drawer to show the settings.
|
|
|
|
echo $OUTPUT->heading(get_string('messagepreferences', 'core_message'));
|
|
|
|
$PAGE->requires->js_call_amd('core_message/message_drawer_helper', 'showSettings');
|
|
|
|
} else {
|
|
|
|
// Viewing another user's preferences so render the old page.
|
|
|
|
$renderer = $PAGE->get_renderer('core', 'message');
|
|
|
|
echo $renderer->render_user_message_preferences($user);
|
|
|
|
}
|
|
|
|
|
2009-09-29 03:54:14 +00:00
|
|
|
echo $OUTPUT->footer();
|
2008-07-24 08:38:03 +00:00
|
|
|
|