|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 require('../../config.php'); 00028 require_once("$CFG->dirroot/$CFG->admin/roles/lib.php"); 00029 00030 $contextid = required_param('contextid', PARAM_INT); // context id 00031 $roleid = required_param('roleid', PARAM_INT); // requested role id 00032 00033 list($context, $course, $cm) = get_context_info_array($contextid); 00034 00035 $url = new moodle_url('/admin/roles/override.php', array('contextid' => $contextid, 'roleid' => $roleid)); 00036 00037 if ($course) { 00038 $isfrontpage = ($course->id == SITEID); 00039 } else { 00040 $isfrontpage = false; 00041 if ($context->contextlevel == CONTEXT_USER) { 00042 $course = $DB->get_record('course', array('id'=>optional_param('courseid', SITEID, PARAM_INT)), '*', MUST_EXIST); 00043 $user = $DB->get_record('user', array('id'=>$context->instanceid), '*', MUST_EXIST); 00044 $url->param('courseid', $course->id); 00045 $url->param('userid', $user->id); 00046 } else { 00047 $course = $SITE; 00048 } 00049 } 00050 00051 // security first 00052 require_login($course, false, $cm); 00053 if (!has_capability('moodle/role:override', $context)) { 00054 require_capability('moodle/role:safeoverride', $context); 00055 } 00056 $PAGE->set_url($url); 00057 $PAGE->set_context($context); 00058 $PAGE->set_pagelayout('admin'); 00059 00060 $courseid = $course->id; 00061 00062 $returnurl = new moodle_url('/admin/roles/permissions.php', array('contextid' => $context->id)); 00063 00064 // Handle the cancel button. 00065 if (optional_param('cancel', false, PARAM_BOOL)) { 00066 redirect($returnurl); 00067 } 00068 00069 $role = $DB->get_record('role', array('id'=>$roleid), '*', MUST_EXIST); 00070 00071 // These are needed early 00072 $assignableroles = get_assignable_roles($context, ROLENAME_BOTH); 00073 list($overridableroles, $overridecounts, $nameswithcounts) = get_overridable_roles($context, ROLENAME_BOTH, true); 00074 00075 // Work out an appropriate page title. 00076 $contextname = print_context_name($context); 00077 $straction = get_string('overrideroles', 'role'); // Used by tabs.php 00078 $a = (object)array('context' => $contextname, 'role' => $overridableroles[$roleid]); 00079 $title = get_string('overridepermissionsforrole', 'role', $a); 00080 00081 $currenttab = 'permissions'; 00082 00083 $PAGE->set_title($title); 00084 $PAGE->navbar->add($straction); 00085 switch ($context->contextlevel) { 00086 case CONTEXT_SYSTEM: 00087 print_error('cannotoverridebaserole', 'error'); 00088 break; 00089 case CONTEXT_USER: 00090 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context)); 00091 $PAGE->set_heading($fullname); 00092 $showroles = 1; 00093 break; 00094 case CONTEXT_COURSECAT: 00095 $PAGE->set_heading("$SITE->fullname: ".get_string("categories")); 00096 break; 00097 case CONTEXT_COURSE: 00098 if ($isfrontpage) { 00099 admin_externalpage_setup('frontpageroles', '', array(), $PAGE->url); 00100 } else { 00101 $PAGE->set_heading($course->fullname); 00102 } 00103 break; 00104 case CONTEXT_MODULE: 00105 $PAGE->set_heading(print_context_name($context, false)); 00106 $PAGE->set_cacheable(false); 00107 break; 00108 case CONTEXT_BLOCK: 00109 $PAGE->set_heading($PAGE->course->fullname); 00110 break; 00111 } 00112 00113 // Make sure this user can override that role 00114 if (empty($overridableroles[$roleid])) { 00115 $a = new stdClass; 00116 $a->roleid = $roleid; 00117 $a->context = $contextname; 00118 print_error('cannotoverriderolehere', '', get_context_url($context), $a); 00119 } 00120 00121 // If we are actually overriding a role, create the table object, and save changes if appropriate. 00122 $overridestable = new override_permissions_table_advanced($context, $roleid, false); 00123 $overridestable->read_submitted_permissions(); 00124 00125 if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) { 00126 $overridestable->save_changes(); 00127 $rolename = $overridableroles[$roleid]; 00128 add_to_log($course->id, 'role', 'override', 'admin/roles/override.php?contextid='.$context->id.'&roleid='.$roleid, $rolename, '', $USER->id); 00129 redirect($returnurl); 00130 } 00131 00132 // Finally start page output 00133 echo $OUTPUT->header(); 00134 echo $OUTPUT->heading_with_help($title, 'overridepermissions', 'role'); 00135 00136 // Show UI for overriding roles. 00137 if (!empty($capabilities)) { 00138 echo $OUTPUT->box(get_string('nocapabilitiesincontext', 'role'), 'generalbox boxaligncenter'); 00139 00140 } else { 00141 // Print the capabilities overrideable in this context 00142 echo $OUTPUT->box_start('generalbox capbox'); 00143 echo html_writer::start_tag('form', array('id'=>'overrideform', 'action'=>$PAGE->url->out(), 'method'=>'post')); 00144 echo html_writer::start_tag('div'); 00145 echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey())); 00146 echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'roleid', 'value'=>$roleid)); 00147 echo html_writer::tag('p', get_string('highlightedcellsshowinherit', 'role'), array('class'=>'overridenotice')); 00148 00149 $overridestable->display(); 00150 if ($overridestable->has_locked_capabilities()) { 00151 echo '<p class="overridenotice">' . get_string('safeoverridenotice', 'role') . "</p>\n"; 00152 } 00153 00154 echo html_writer::start_tag('div', array('class'=>'submit_buttons')); 00155 echo html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'savechanges', 'value'=>get_string('savechanges'))); 00156 echo html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'cancel', 'value'=>get_string('cancel'))); 00157 echo html_writer::end_tag('div'); 00158 echo html_writer::end_tag('div'); 00159 echo html_writer::end_tag('form'); 00160 echo $OUTPUT->box_end(); 00161 } 00162 00163 // Print a form to swap roles, and a link back to the all roles list. 00164 echo html_writer::start_tag('div', array('class'=>'backlink')); 00165 $select = new single_select($PAGE->url, 'roleid', $nameswithcounts, $roleid, null); 00166 $select->label = get_string('overrideanotherrole', 'role'); 00167 echo $OUTPUT->render($select); 00168 echo html_writer::tag('p', html_writer::tag('a', get_string('backtoallroles', 'role'), array('href'=>$returnurl))); 00169 echo html_writer::end_tag('div'); 00170 00171 echo $OUTPUT->footer();