2009-09-30 06:32:25 +00:00
|
|
|
<?php
|
2010-03-07 09:28:54 +00:00
|
|
|
// 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-11-13 04:07:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lets you override role definitions in contexts.
|
|
|
|
*
|
2013-06-26 23:18:39 +02:00
|
|
|
* @package core_role
|
2010-03-07 09:28:54 +00:00
|
|
|
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2010-03-07 09:28:54 +00:00
|
|
|
require('../../config.php');
|
2006-09-22 20:09:47 +00:00
|
|
|
|
2013-06-26 23:18:39 +02:00
|
|
|
$contextid = required_param('contextid', PARAM_INT);
|
|
|
|
$roleid = required_param('roleid', PARAM_INT);
|
2006-09-24 13:30:43 +00:00
|
|
|
|
2010-03-07 09:28:54 +00:00
|
|
|
list($context, $course, $cm) = get_context_info_array($contextid);
|
2006-09-22 20:09:47 +00:00
|
|
|
|
2010-04-21 02:43:02 +00:00
|
|
|
$url = new moodle_url('/admin/roles/override.php', array('contextid' => $contextid, 'roleid' => $roleid));
|
2010-03-07 09:28:54 +00:00
|
|
|
|
2010-07-13 21:20:48 +00:00
|
|
|
if ($course) {
|
|
|
|
$isfrontpage = ($course->id == SITEID);
|
|
|
|
} else {
|
|
|
|
$isfrontpage = false;
|
2010-03-07 09:28:54 +00:00
|
|
|
if ($context->contextlevel == CONTEXT_USER) {
|
2013-08-21 13:42:30 +08:00
|
|
|
$course = $DB->get_record('course', array('id'=>optional_param('courseid', SITEID, PARAM_INT)), '*', MUST_EXIST);
|
2010-04-21 02:43:02 +00:00
|
|
|
$user = $DB->get_record('user', array('id'=>$context->instanceid), '*', MUST_EXIST);
|
|
|
|
$url->param('courseid', $course->id);
|
|
|
|
$url->param('userid', $user->id);
|
2010-03-07 09:28:54 +00:00
|
|
|
} else {
|
|
|
|
$course = $SITE;
|
2008-11-14 03:28:15 +00:00
|
|
|
}
|
2010-03-07 09:28:54 +00:00
|
|
|
}
|
2008-11-14 03:28:15 +00:00
|
|
|
|
2013-06-26 23:18:39 +02:00
|
|
|
// Security first.
|
2010-03-31 08:23:33 +00:00
|
|
|
require_login($course, false, $cm);
|
2012-03-19 20:21:33 +13:00
|
|
|
$safeoverridesonly = false;
|
2010-04-21 02:43:02 +00:00
|
|
|
if (!has_capability('moodle/role:override', $context)) {
|
2010-03-31 08:23:33 +00:00
|
|
|
require_capability('moodle/role:safeoverride', $context);
|
2012-03-19 20:21:33 +13:00
|
|
|
$safeoverridesonly = true;
|
2010-03-31 08:23:33 +00:00
|
|
|
}
|
2010-04-21 02:43:02 +00:00
|
|
|
$PAGE->set_url($url);
|
2010-07-23 02:09:03 +00:00
|
|
|
$PAGE->set_pagelayout('admin');
|
2013-10-19 12:22:12 +02:00
|
|
|
|
|
|
|
if ($context->contextlevel == CONTEXT_USER and $USER->id != $context->instanceid) {
|
|
|
|
$PAGE->navigation->extend_for_user($user);
|
|
|
|
$PAGE->set_context(context_course::instance($course->id));
|
|
|
|
navigation_node::override_active_url(new moodle_url('/admin/roles/permissions.php',
|
|
|
|
array('contextid'=>$context->id, 'userid'=>$context->instanceid, 'courseid'=>$course->id)));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$PAGE->set_context($context);
|
|
|
|
navigation_node::override_active_url(new moodle_url('/admin/roles/permissions.php', array('contextid'=>$context->id)));
|
2013-10-17 11:14:33 +08:00
|
|
|
}
|
2013-10-19 12:22:12 +02:00
|
|
|
|
2010-03-07 09:28:54 +00:00
|
|
|
$courseid = $course->id;
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2010-03-07 09:28:54 +00:00
|
|
|
$returnurl = new moodle_url('/admin/roles/permissions.php', array('contextid' => $context->id));
|
2008-11-05 08:17:30 +00:00
|
|
|
|
2010-04-21 02:43:02 +00:00
|
|
|
// Handle the cancel button.
|
|
|
|
if (optional_param('cancel', false, PARAM_BOOL)) {
|
|
|
|
redirect($returnurl);
|
|
|
|
}
|
|
|
|
|
2010-03-07 09:28:54 +00:00
|
|
|
$role = $DB->get_record('role', array('id'=>$roleid), '*', MUST_EXIST);
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2013-06-26 23:18:39 +02:00
|
|
|
// These are needed early.
|
2010-03-07 09:28:54 +00:00
|
|
|
$assignableroles = get_assignable_roles($context, ROLENAME_BOTH);
|
|
|
|
list($overridableroles, $overridecounts, $nameswithcounts) = get_overridable_roles($context, ROLENAME_BOTH, true);
|
2006-09-22 20:09:47 +00:00
|
|
|
|
2010-03-07 09:28:54 +00:00
|
|
|
// Work out an appropriate page title.
|
2013-06-26 23:18:39 +02:00
|
|
|
$contextname = $context->get_context_name();
|
|
|
|
$straction = get_string('overrideroles', 'core_role'); // Used by tabs.php.
|
2013-06-27 09:34:46 +02:00
|
|
|
$a = (object)array('context' => $contextname, 'role' => $overridableroles[$roleid]);
|
2013-06-26 23:18:39 +02:00
|
|
|
$title = get_string('overridepermissionsforrole', 'core_role', $a);
|
2006-09-22 20:09:47 +00:00
|
|
|
|
2010-04-21 02:43:02 +00:00
|
|
|
$currenttab = 'permissions';
|
|
|
|
|
|
|
|
$PAGE->set_title($title);
|
2023-03-29 18:15:21 +02:00
|
|
|
$PAGE->activityheader->disable();
|
2010-04-21 02:43:02 +00:00
|
|
|
$PAGE->navbar->add($straction);
|
|
|
|
switch ($context->contextlevel) {
|
|
|
|
case CONTEXT_SYSTEM:
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('cannotoverridebaserole', 'error');
|
2010-04-21 02:43:02 +00:00
|
|
|
break;
|
|
|
|
case CONTEXT_USER:
|
2010-07-13 21:20:48 +00:00
|
|
|
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
|
|
|
|
$PAGE->set_heading($fullname);
|
2010-04-21 02:43:02 +00:00
|
|
|
$showroles = 1;
|
|
|
|
break;
|
|
|
|
case CONTEXT_COURSECAT:
|
2013-10-19 12:22:12 +02:00
|
|
|
$PAGE->set_heading($SITE->fullname);
|
2010-04-21 02:43:02 +00:00
|
|
|
break;
|
|
|
|
case CONTEXT_COURSE:
|
|
|
|
if ($isfrontpage) {
|
2013-10-19 12:22:12 +02:00
|
|
|
$PAGE->set_heading(get_string('frontpage', 'admin'));
|
2010-04-21 02:43:02 +00:00
|
|
|
} else {
|
|
|
|
$PAGE->set_heading($course->fullname);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CONTEXT_MODULE:
|
2013-06-26 23:18:39 +02:00
|
|
|
$PAGE->set_heading($context->get_context_name(false));
|
2010-04-21 02:43:02 +00:00
|
|
|
$PAGE->set_cacheable(false);
|
|
|
|
break;
|
|
|
|
case CONTEXT_BLOCK:
|
|
|
|
$PAGE->set_heading($PAGE->course->fullname);
|
|
|
|
break;
|
2010-03-07 09:28:54 +00:00
|
|
|
}
|
|
|
|
|
2013-06-26 23:18:39 +02:00
|
|
|
// Make sure this user can override that role.
|
2010-03-07 09:28:54 +00:00
|
|
|
if (empty($overridableroles[$roleid])) {
|
|
|
|
$a = new stdClass;
|
|
|
|
$a->roleid = $roleid;
|
|
|
|
$a->context = $contextname;
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('cannotoverriderolehere', '', $context->get_url(), $a);
|
2010-03-07 09:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we are actually overriding a role, create the table object, and save changes if appropriate.
|
2013-06-26 20:21:21 +02:00
|
|
|
$overridestable = new core_role_override_permissions_table_advanced($context, $roleid, $safeoverridesonly);
|
2010-03-07 09:28:54 +00:00
|
|
|
$overridestable->read_submitted_permissions();
|
|
|
|
|
|
|
|
if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
|
|
|
|
$overridestable->save_changes();
|
|
|
|
$rolename = $overridableroles[$roleid];
|
2013-08-07 10:23:39 +08:00
|
|
|
|
2010-03-07 09:28:54 +00:00
|
|
|
redirect($returnurl);
|
|
|
|
}
|
|
|
|
|
2013-06-26 23:18:39 +02:00
|
|
|
// Finally start page output.
|
2010-03-07 09:28:54 +00:00
|
|
|
echo $OUTPUT->header();
|
2013-06-26 23:18:39 +02:00
|
|
|
echo $OUTPUT->heading_with_help($title, 'overridepermissions', 'core_role');
|
2010-03-07 09:28:54 +00:00
|
|
|
|
|
|
|
// Show UI for overriding roles.
|
|
|
|
if (!empty($capabilities)) {
|
2013-06-26 23:18:39 +02:00
|
|
|
echo $OUTPUT->box(get_string('nocapabilitiesincontext', 'core_role'), 'generalbox boxaligncenter');
|
2010-03-07 09:28:54 +00:00
|
|
|
|
|
|
|
} else {
|
2013-06-26 23:18:39 +02:00
|
|
|
// Print the capabilities overrideable in this context.
|
2010-03-07 09:28:54 +00:00
|
|
|
echo $OUTPUT->box_start('generalbox capbox');
|
2010-04-21 02:43:02 +00:00
|
|
|
echo html_writer::start_tag('form', array('id'=>'overrideform', 'action'=>$PAGE->url->out(), 'method'=>'post'));
|
|
|
|
echo html_writer::start_tag('div');
|
|
|
|
echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
|
|
|
|
echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'roleid', 'value'=>$roleid));
|
2013-06-26 23:18:39 +02:00
|
|
|
echo html_writer::tag('p', get_string('highlightedcellsshowinherit', 'core_role'), array('class'=>'overridenotice'));
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
2010-04-21 02:43:02 +00:00
|
|
|
$overridestable->display();
|
2010-09-17 10:27:26 +00:00
|
|
|
if ($overridestable->has_locked_capabilities()) {
|
2013-06-26 23:18:39 +02:00
|
|
|
echo '<p class="overridenotice">' . get_string('safeoverridenotice', 'core_role') . "</p>\n";
|
2010-04-21 02:43:02 +00:00
|
|
|
}
|
2010-03-07 09:28:54 +00:00
|
|
|
|
2010-04-21 02:43:02 +00:00
|
|
|
echo html_writer::start_tag('div', array('class'=>'submit_buttons'));
|
2016-11-01 14:08:47 +08:00
|
|
|
$attrs = array('type'=>'submit', 'name'=>'savechanges', 'value'=>get_string('savechanges'), 'class'=>'btn btn-primary');
|
|
|
|
echo html_writer::empty_tag('input', $attrs);
|
2022-02-14 15:39:45 +01:00
|
|
|
$attrs = array('type' => 'submit', 'name' => 'cancel', 'value' => get_string('cancel'),
|
|
|
|
'class' => 'btn btn-secondary ml-1');
|
2016-11-01 14:08:47 +08:00
|
|
|
echo html_writer::empty_tag('input', $attrs);
|
2010-04-21 02:43:02 +00:00
|
|
|
echo html_writer::end_tag('div');
|
|
|
|
echo html_writer::end_tag('div');
|
|
|
|
echo html_writer::end_tag('form');
|
2010-03-07 09:28:54 +00:00
|
|
|
echo $OUTPUT->box_end();
|
|
|
|
}
|
2008-11-06 07:34:01 +00:00
|
|
|
|
2010-03-07 09:28:54 +00:00
|
|
|
// Print a form to swap roles, and a link back to the all roles list.
|
2010-04-21 02:43:02 +00:00
|
|
|
echo html_writer::start_tag('div', array('class'=>'backlink'));
|
|
|
|
$select = new single_select($PAGE->url, 'roleid', $nameswithcounts, $roleid, null);
|
2013-06-26 23:18:39 +02:00
|
|
|
$select->label = get_string('overrideanotherrole', 'core_role');
|
2010-03-07 09:28:54 +00:00
|
|
|
echo $OUTPUT->render($select);
|
2013-06-26 23:18:39 +02:00
|
|
|
echo html_writer::tag('p', html_writer::tag('a', get_string('backtoallroles', 'core_role'), array('href'=>$returnurl)));
|
2010-04-21 02:43:02 +00:00
|
|
|
echo html_writer::end_tag('div');
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2010-03-07 09:28:54 +00:00
|
|
|
echo $OUTPUT->footer();
|