2009-09-30 06:32:25 +00:00
|
|
|
<?php
|
2006-09-20 21:00:45 +00:00
|
|
|
|
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.
|
|
|
|
*
|
2010-09-06 11:17:43 +00:00
|
|
|
* @package core
|
2010-03-07 09:28:54 +00:00
|
|
|
* @subpackage role
|
|
|
|
* @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');
|
|
|
|
require_once("$CFG->dirroot/$CFG->admin/roles/lib.php");
|
2006-09-22 20:09:47 +00:00
|
|
|
|
2010-03-07 09:28:54 +00:00
|
|
|
$contextid = required_param('contextid', PARAM_INT); // context id
|
|
|
|
$roleid = required_param('roleid', PARAM_INT); // requested role id
|
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) {
|
2010-04-21 02:43:02 +00:00
|
|
|
$course = $DB->get_record('course', array('id'=>optional_param('courseid', SITEID, PARAM_INT)), '*', MUST_EXIST);
|
|
|
|
$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
|
|
|
|
2010-03-31 08:23:33 +00:00
|
|
|
// security first
|
|
|
|
require_login($course, false, $cm);
|
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);
|
|
|
|
}
|
2010-04-21 02:43:02 +00:00
|
|
|
$PAGE->set_url($url);
|
|
|
|
$PAGE->set_context($context);
|
2010-07-23 02:09:03 +00:00
|
|
|
$PAGE->set_pagelayout('admin');
|
2010-03-31 08:23:33 +00: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
|
|
|
|
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
|
|
|
// 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.
|
|
|
|
$contextname = print_context_name($context);
|
|
|
|
$straction = get_string('overrideroles', 'role'); // Used by tabs.php
|
|
|
|
$a = (object)array('context' => $contextname, 'role' => $overridableroles[$roleid]);
|
|
|
|
$title = get_string('overridepermissionsforrole', 'role', $a);
|
2006-09-22 20:09:47 +00:00
|
|
|
|
2010-04-21 02:43:02 +00:00
|
|
|
$currenttab = 'permissions';
|
|
|
|
|
|
|
|
$PAGE->set_title($title);
|
|
|
|
$PAGE->navbar->add($straction);
|
|
|
|
switch ($context->contextlevel) {
|
|
|
|
case CONTEXT_SYSTEM:
|
|
|
|
print_error('cannotoverridebaserole', 'error');
|
|
|
|
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:
|
|
|
|
$PAGE->set_heading("$SITE->fullname: ".get_string("categories"));
|
|
|
|
break;
|
|
|
|
case CONTEXT_COURSE:
|
|
|
|
if ($isfrontpage) {
|
|
|
|
admin_externalpage_setup('frontpageroles', '', array(), $PAGE->url);
|
|
|
|
} else {
|
|
|
|
$PAGE->set_heading($course->fullname);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CONTEXT_MODULE:
|
|
|
|
$PAGE->set_heading(print_context_name($context, false));
|
|
|
|
$PAGE->set_cacheable(false);
|
|
|
|
break;
|
|
|
|
case CONTEXT_BLOCK:
|
|
|
|
$PAGE->set_heading($PAGE->course->fullname);
|
|
|
|
break;
|
2010-03-07 09:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure this user can override that role
|
|
|
|
if (empty($overridableroles[$roleid])) {
|
|
|
|
$a = new stdClass;
|
|
|
|
$a->roleid = $roleid;
|
|
|
|
$a->context = $contextname;
|
|
|
|
print_error('cannotoverriderolehere', '', get_context_url($context), $a);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are actually overriding a role, create the table object, and save changes if appropriate.
|
2010-04-21 02:43:02 +00:00
|
|
|
$overridestable = new override_permissions_table_advanced($context, $roleid, false);
|
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];
|
|
|
|
add_to_log($course->id, 'role', 'override', 'admin/roles/override.php?contextid='.$context->id.'&roleid='.$roleid, $rolename, '', $USER->id);
|
|
|
|
redirect($returnurl);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally start page output
|
|
|
|
echo $OUTPUT->header();
|
2010-05-17 12:43:02 +00:00
|
|
|
echo $OUTPUT->heading_with_help($title, 'overridepermissions', 'role');
|
2010-03-07 09:28:54 +00:00
|
|
|
|
|
|
|
// Show UI for overriding roles.
|
|
|
|
if (!empty($capabilities)) {
|
|
|
|
echo $OUTPUT->box(get_string('nocapabilitiesincontext', 'role'), 'generalbox boxaligncenter');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Print the capabilities overrideable in this context
|
|
|
|
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));
|
|
|
|
echo html_writer::tag('p', get_string('highlightedcellsshowinherit', '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();
|
|
|
|
if ($overridestable->has_locked_capabiltites()) {
|
|
|
|
echo '<p class="overridenotice">' . get_string('safeoverridenotice', 'role') . "</p>\n";
|
|
|
|
}
|
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'));
|
|
|
|
echo html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'savechanges', 'value'=>get_string('savechanges')));
|
|
|
|
echo html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'cancel', 'value'=>get_string('cancel')));
|
|
|
|
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);
|
2010-03-07 09:28:54 +00:00
|
|
|
$select->label = get_string('overrideanotherrole', 'role');
|
|
|
|
echo $OUTPUT->render($select);
|
2010-04-21 02:43:02 +00:00
|
|
|
echo html_writer::tag('p', html_writer::tag('a', get_string('backtoallroles', 'role'), array('href'=>$returnurl)));
|
|
|
|
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();
|