dirroot . '/' . $CFG->admin . '/roles/lib.php'); $contextid = required_param('contextid',PARAM_INT); $userid = optional_param('userid', 0, PARAM_INT); // needed for user tabs $courseid = optional_param('courseid', 0, PARAM_INT); // needed for user tabs if (! $context = get_context_instance_by_id($contextid)) { print_error('wrongcontextid', 'error'); } $isfrontpage = $context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID; $contextname = print_context_name($context); if ($context->contextlevel == CONTEXT_COURSE) { $courseid = $context->instanceid; if (!$course = $DB->get_record('course', array('id'=>$courseid))) { print_error('invalidcourse', 'error'); } } else if (!empty($courseid)){ // we need this for user tabs in user context if (!$course = $DB->get_record('course', array('id'=>$courseid))) { print_error('invalidcourse', 'error'); } } else { $courseid = SITEID; $course = clone($SITE); } /// Check login and permissions. require_login($course); $canview = has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:manage'), $context); if (!$canview) { print_error('nopermissions', 'error', '', get_string('checkpermissions', 'role')); } /// These are needed early because of tabs.php $assignableroles = get_assignable_roles($context, ROLENAME_BOTH); $overridableroles = get_overridable_roles($context, ROLENAME_BOTH); /// Get the user_selector we will need. /// Teachers within a course just get to see the same list of people they can /// assign roles to. Admins (people with moodle/role:manage) can run this report for any user. $options = array('context' => $context, 'roleid' => 0); if ($context->contextlevel > CONTEXT_COURSE && !is_inside_frontpage($context) && !has_capability('moodle/role:manage', $context)) { $userselector = new potential_assignees_below_course('reportuser', $options); } else { $userselector = new potential_assignees_course_and_above('reportuser', $options); } $userselector->set_multiselect(false); $userselector->set_rows(10); /// Work out an appropriate page title. $title = get_string('checkpermissionsin', 'role', $contextname); $straction = get_string('checkpermissions', 'role'); // Used by tabs.php /// Print the header and tabs if ($context->contextlevel == CONTEXT_USER) { $user = $DB->get_record('user', array('id' => $userid)); $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context)); /// course header $navlinks = array(); if ($courseid != SITEID) { if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_COURSE, $courseid))) { $navlinks[] = array('name' => get_string('participants'), 'link' => "$CFG->wwwroot/user/index.php?id=$courseid", 'type' => 'misc'); } $navlinks[] = array('name' => $fullname, 'link' => "$CFG->wwwroot/user/view.php?id=$userid&course=$courseid", 'type' => 'misc'); $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc'); $navigation = build_navigation($navlinks); print_header($title, $fullname, $navigation, '', '', true, ' ', navmenu($course)); /// site header } else { $navlinks[] = array('name' => $fullname, 'link' => "$CFG->wwwroot/user/view.php?id=$userid&course=$courseid", 'type' => 'misc'); $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc'); $navigation = build_navigation($navlinks); print_header($title, $course->fullname, $navigation, "", "", true, " ", navmenu($course)); } $showroles = 1; $currenttab = 'check'; include_once($CFG->dirroot.'/user/tabs.php'); } else if ($context->contextlevel == CONTEXT_SYSTEM) { admin_externalpage_setup('checkpermissions'); admin_externalpage_print_header(); } else if ($context->contextlevel == CONTEXT_COURSE and $context->instanceid == SITEID) { admin_externalpage_setup('frontpageroles'); admin_externalpage_print_header(); $currenttab = 'check'; include_once('tabs.php'); } else { $currenttab = 'check'; include_once('tabs.php'); } /// Print heading. print_heading_with_help($title, 'checkpermissions'); /// If a user has been chosen, show all the permissions for this user. $reportuser = $userselector->get_selected_user(); if (!is_null($reportuser)) { print_box_start('generalbox boxaligncenter boxwidthwide'); print_heading(get_string('permissionsforuser', 'role', fullname($reportuser)), '', 3); $table = new explain_capability_table($context, $reportuser, $contextname); $table->display(); print_box_end(); $selectheading = get_string('selectanotheruser', 'role'); } else { $selectheading = get_string('selectauser', 'role'); } /// Show UI for choosing a user to report on. print_box_start('generalbox boxwidthnormal boxaligncenter', 'chooseuser'); echo '
'; /// Hidden fields. echo ''; if (!empty($userid)) { echo ''; } if ($courseid && $courseid != SITEID) { echo ''; } /// User selector. print_heading('', '', 3); $userselector->display(); /// Submit button and the end of the form. echo '

'; echo '
'; print_box_end(); /// Appropriate back link. if (!$isfrontpage && ($url = get_context_url($context))) { echo ''; } print_footer($course); ?>