|
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 require_once("permissions_forms.php"); 00030 00031 $contextid = required_param('contextid',PARAM_INT); 00032 00033 $roleid = optional_param('roleid', 0, PARAM_INT); 00034 $capability = optional_param('capability', false, PARAM_CAPABILITY); 00035 $confirm = optional_param('confirm', 0, PARAM_BOOL); 00036 $prevent = optional_param('prevent', 0, PARAM_BOOL); 00037 $allow = optional_param('allow', 0, PARAM_BOOL); 00038 $unprohibit = optional_param('unprohibit', 0, PARAM_BOOL); 00039 $prohibit = optional_param('prohibit', 0, PARAM_BOOL); 00040 00041 list($context, $course, $cm) = get_context_info_array($contextid); 00042 00043 $url = new moodle_url('/admin/roles/permissions.php', array('contextid' => $contextid)); 00044 00045 if ($course) { 00046 $isfrontpage = ($course->id == SITEID); 00047 } else { 00048 $isfrontpage = false; 00049 if ($context->contextlevel == CONTEXT_USER) { 00050 $course = $DB->get_record('course', array('id'=>optional_param('courseid', SITEID, PARAM_INT)), '*', MUST_EXIST); 00051 $user = $DB->get_record('user', array('id'=>$context->instanceid), '*', MUST_EXIST); 00052 $url->param('courseid', $course->id); 00053 $url->param('userid', $user->id); 00054 } else { 00055 $course = $SITE; 00056 } 00057 } 00058 00059 // security first 00060 require_login($course, false, $cm); 00061 require_capability('moodle/role:review', $context); 00062 $PAGE->set_url($url); 00063 $PAGE->set_context($context); 00064 $courseid = $course->id; 00065 00066 00067 // These are needed early because of tabs.php 00068 $assignableroles = get_assignable_roles($context, ROLENAME_BOTH); 00069 list($overridableroles, $overridecounts, $nameswithcounts) = get_overridable_roles($context, ROLENAME_BOTH, true); 00070 if ($capability) { 00071 $capability = $DB->get_record('capabilities', array('name'=>$capability), '*', MUST_EXIST); 00072 } 00073 00074 $allowoverrides = has_capability('moodle/role:override', $context); 00075 $allowsafeoverrides = has_capability('moodle/role:safeoverride', $context); 00076 00077 $contextname = print_context_name($context); 00078 $title = get_string('permissionsincontext', 'role', $contextname); 00079 $straction = get_string('permissions', 'role'); // Used by tabs.php 00080 $currenttab = 'permissions'; 00081 00082 $PAGE->set_pagelayout('admin'); 00083 $PAGE->set_title($title); 00084 switch ($context->contextlevel) { 00085 case CONTEXT_SYSTEM: 00086 print_error('cannotoverridebaserole', 'error'); 00087 break; 00088 case CONTEXT_USER: 00089 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context)); 00090 $PAGE->set_heading($fullname); 00091 $showroles = 1; 00092 break; 00093 case CONTEXT_COURSECAT: 00094 $PAGE->set_heading("$SITE->fullname: ".get_string("categories")); 00095 break; 00096 case CONTEXT_COURSE: 00097 if ($isfrontpage) { 00098 admin_externalpage_setup('frontpageroles', '', array(), $PAGE->url); 00099 } else { 00100 $PAGE->set_heading($course->fullname); 00101 } 00102 break; 00103 case CONTEXT_MODULE: 00104 $PAGE->set_heading(print_context_name($context, false)); 00105 $PAGE->set_cacheable(false); 00106 break; 00107 case CONTEXT_BLOCK: 00108 $PAGE->set_heading($PAGE->course->fullname); 00109 break; 00110 } 00111 00112 // handle confirmations and actions 00113 // We have a capability and overrides are allowed or safe overrides are allowed and this is safe 00114 if ($capability && ($allowoverrides || ($allowsafeoverrides && is_safe_capability($capability)))) { 00115 // If we already know the the role ID, it is overrideable, and we are setting prevent or unprohibit 00116 if (isset($overridableroles[$roleid]) && ($prevent || $unprohibit)) { 00117 // We are preventing 00118 if ($prevent) { 00119 if ($confirm && data_submitted() && confirm_sesskey()) { 00120 role_change_permission($roleid, $context, $capability->name, CAP_PREVENT); 00121 redirect($PAGE->url); 00122 00123 } else { 00124 $a = (object)array('cap'=>get_capability_docs_link($capability)." ($capability->name)", 'role'=>$overridableroles[$roleid], 'context'=>$contextname); 00125 $message = get_string('confirmroleprevent', 'role', $a); 00126 $continueurl = new moodle_url($PAGE->url, array('contextid'=>$context->id, 'roleid'=>$roleid, 'capability'=>$capability->name, 'prevent'=>1, 'sesskey'=>sesskey(), 'confirm'=>1)); 00127 } 00128 } 00129 // We are unprohibiting 00130 if ($unprohibit) { 00131 if ($confirm && data_submitted() && confirm_sesskey()) { 00132 role_change_permission($roleid, $context, $capability->name, CAP_INHERIT); 00133 redirect($PAGE->url); 00134 } else { 00135 $a = (object)array('cap'=>get_capability_docs_link($capability)." ($capability->name)", 'role'=>$overridableroles[$roleid], 'context'=>$contextname); 00136 $message = get_string('confirmroleunprohibit', 'role', $a); 00137 $continueurl = new moodle_url($PAGE->url, array('contextid'=>$context->id, 'roleid'=>$roleid, 'capability'=>$capability->name, 'unprohibit'=>1, 'sesskey'=>sesskey(), 'confirm'=>1)); 00138 } 00139 } 00140 // Display and print 00141 echo $OUTPUT->header(); 00142 echo $OUTPUT->heading($title); 00143 echo $OUTPUT->confirm($message, $continueurl, $PAGE->url); 00144 echo $OUTPUT->footer(); 00145 die; 00146 } 00147 00148 if ($allow || $prohibit) { 00149 if ($allow) { 00150 $mform = new role_allow_form(null, array($context, $capability, $overridableroles)); 00151 if ($mform->is_cancelled()) { 00152 redirect($PAGE->url); 00153 } else if ($data = $mform->get_data() and !empty($data->roleid)) { 00154 $roleid = $data->roleid; 00155 if (isset($overridableroles[$roleid])) { 00156 role_change_permission($roleid, $context, $capability->name, CAP_ALLOW); 00157 } 00158 redirect($PAGE->url); 00159 } else { 00160 $a = (object)array('cap'=>get_capability_docs_link($capability)." ($capability->name)", 'context'=>$contextname); 00161 $message = get_string('roleallowinfo', 'role', $a); 00162 } 00163 } 00164 if ($prohibit) { 00165 $mform = new role_prohibit_form(null, array($context, $capability, $overridableroles)); 00166 if ($mform->is_cancelled()) { 00167 redirect($PAGE->url); 00168 } else if ($data = $mform->get_data() and !empty($data->roleid)) { 00169 $roleid = $data->roleid; 00170 if (isset($overridableroles[$roleid])) { 00171 role_change_permission($roleid, $context, $capability->name, CAP_PROHIBIT); 00172 } 00173 redirect($PAGE->url); 00174 } else { 00175 $a = (object)array('cap'=>get_capability_docs_link($capability)." ($capability->name)", 'context'=>$contextname); 00176 $message = get_string('roleprohibitinfo', 'role', $a); 00177 } 00178 } 00179 echo $OUTPUT->header(); 00180 echo $OUTPUT->heading($title); 00181 echo $OUTPUT->box($message); 00182 $mform->display(); 00183 echo $OUTPUT->footer(); 00184 die; 00185 } 00186 } 00187 00188 echo $OUTPUT->header(); 00189 echo $OUTPUT->heading($title); 00190 00191 $table = new permissions_table($context, $contextname, $allowoverrides, $allowsafeoverrides, $overridableroles); 00192 echo $OUTPUT->box_start('generalbox capbox'); 00193 // print link to advanced override page 00194 if ($overridableroles) { 00195 $overrideurl = new moodle_url('/admin/roles/override.php', array('contextid' => $context->id)); 00196 $select = new single_select($overrideurl, 'roleid', $nameswithcounts); 00197 $select->label = get_string('advancedoverride', 'role'); 00198 echo html_writer::tag('div', $OUTPUT->render($select), array('class'=>'advancedoverride')); 00199 } 00200 $table->display(); 00201 echo $OUTPUT->box_end(); 00202 00203 00204 if ($context->contextlevel > CONTEXT_USER) { 00205 echo html_writer::start_tag('div', array('class'=>'backlink')); 00206 echo html_writer::tag('a', get_string('backto', '', $contextname), array('href'=>get_context_url($context))); 00207 echo html_writer::end_tag('div'); 00208 } 00209 00210 echo $OUTPUT->footer($course); 00211