|
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_once(dirname(__FILE__) . '/../../config.php'); 00028 require_once($CFG->dirroot . '/' . $CFG->admin . '/roles/lib.php'); 00029 00030 $contextid = required_param('contextid',PARAM_INT); 00031 00032 list($context, $course, $cm) = get_context_info_array($contextid); 00033 00034 $url = new moodle_url('/admin/roles/check.php', array('contextid' => $contextid)); 00035 00036 if ($course) { 00037 $isfrontpage = ($course->id == SITEID); 00038 } else { 00039 $isfrontpage = false; 00040 if ($context->contextlevel == CONTEXT_USER) { 00041 $course = $DB->get_record('course', array('id'=>optional_param('courseid', SITEID, PARAM_INT)), '*', MUST_EXIST); 00042 $user = $DB->get_record('user', array('id'=>$context->instanceid), '*', MUST_EXIST); 00043 $url->param('courseid', $course->id); 00044 $url->param('userid', $user->id); 00045 } else { 00046 $course = $SITE; 00047 } 00048 } 00049 00050 // security first 00051 require_login($course, false, $cm); 00052 if (!has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:manage'), $context)) { 00053 print_error('nopermissions', 'error', '', get_string('checkpermissions', 'role')); 00054 } 00055 $PAGE->set_url($url); 00056 $PAGE->set_context($context); 00057 00058 $courseid = $course->id; 00059 $contextname = print_context_name($context); 00060 00061 // Get the user_selector we will need. 00062 // Teachers within a course just get to see the same list of people they can 00063 // assign roles to. Admins (people with moodle/role:manage) can run this report for any user. 00064 $options = array('context' => $context, 'roleid' => 0); 00065 if (has_capability('moodle/role:manage', $context)) { 00066 $userselector = new potential_assignees_course_and_above('reportuser', $options); 00067 } else { 00068 $userselector = roles_get_potential_user_selector($context, 'reportuser', $options); 00069 } 00070 $userselector->set_multiselect(false); 00071 $userselector->set_rows(10); 00072 00073 // Work out an appropriate page title. 00074 $title = get_string('checkpermissionsin', 'role', $contextname); 00075 00076 $PAGE->set_pagelayout('admin'); 00077 $PAGE->set_title($title); 00078 00079 switch ($context->contextlevel) { 00080 case CONTEXT_SYSTEM: 00081 admin_externalpage_setup('checkpermissions', '', array('contextid' => $contextid)); 00082 break; 00083 case CONTEXT_USER: 00084 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context)); 00085 $PAGE->set_heading($fullname); 00086 $showroles = 1; 00087 break; 00088 case CONTEXT_COURSECAT: 00089 $PAGE->set_heading("$SITE->fullname: ".get_string("categories")); 00090 break; 00091 case CONTEXT_COURSE: 00092 if ($isfrontpage) { 00093 admin_externalpage_setup('frontpageroles', '', array('contextid' => $contextid), $CFG->wwwroot . '/' . $CFG->admin . '/roles/check.php'); 00094 } else { 00095 $PAGE->set_heading($course->fullname); 00096 } 00097 break; 00098 case CONTEXT_MODULE: 00099 $PAGE->set_heading(print_context_name($context, false)); 00100 $PAGE->set_cacheable(false); 00101 break; 00102 case CONTEXT_BLOCK: 00103 $PAGE->set_heading($PAGE->course->fullname); 00104 break; 00105 } 00106 00107 echo $OUTPUT->header(); 00108 // These are needed early because of tabs.php 00109 $assignableroles = get_assignable_roles($context, ROLENAME_BOTH); 00110 $overridableroles = get_overridable_roles($context, ROLENAME_BOTH); 00111 00112 // Print heading. 00113 echo $OUTPUT->heading($title); 00114 00115 // If a user has been chosen, show all the permissions for this user. 00116 $reportuser = $userselector->get_selected_user(); 00117 if (!is_null($reportuser)) { 00118 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); 00119 echo $OUTPUT->heading(get_string('permissionsforuser', 'role', fullname($reportuser)), 3); 00120 00121 $table = new check_capability_table($context, $reportuser, $contextname); 00122 $table->display(); 00123 echo $OUTPUT->box_end(); 00124 00125 $selectheading = get_string('selectanotheruser', 'role'); 00126 } else { 00127 $selectheading = get_string('selectauser', 'role'); 00128 } 00129 00130 // Show UI for choosing a user to report on. 00131 echo $OUTPUT->box_start('generalbox boxwidthnormal boxaligncenter', 'chooseuser'); 00132 echo '<form method="get" action="' . $CFG->wwwroot . '/' . $CFG->admin . '/roles/check.php" >'; 00133 00134 // Hidden fields. 00135 echo '<input type="hidden" name="contextid" value="' . $context->id . '" />'; 00136 if (!empty($user->id)) { 00137 echo '<input type="hidden" name="userid" value="' . $user->id . '" />'; 00138 } 00139 if ($isfrontpage) { 00140 echo '<input type="hidden" name="courseid" value="' . $courseid . '" />'; 00141 } 00142 00143 // User selector. 00144 echo $OUTPUT->heading('<label for="reportuser">' . $selectheading . '</label>', 3); 00145 $userselector->display(); 00146 00147 // Submit button and the end of the form. 00148 echo '<p id="chooseusersubmit"><input type="submit" value="' . get_string('showthisuserspermissions', 'role') . '" /></p>'; 00149 echo '</form>'; 00150 echo $OUTPUT->box_end(); 00151 00152 // Appropriate back link. 00153 if ($context->contextlevel > CONTEXT_USER) { 00154 echo html_writer::start_tag('div', array('class'=>'backlink')); 00155 echo html_writer::tag('a', get_string('backto', '', $contextname), array('href'=>get_context_url($context))); 00156 echo html_writer::end_tag('div'); 00157 } 00158 00159 echo $OUTPUT->footer(); 00160