. /** * Display profile for a particular user * * @copyright 1999 Martin Dougiamas http://dougiamas.com * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @package user */ require_once("../config.php"); require_once($CFG->dirroot.'/user/profile/lib.php'); require_once($CFG->dirroot.'/tag/lib.php'); require_once($CFG->libdir . '/filelib.php'); $id = optional_param('id', 0, PARAM_INT); // user id $courseid = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site) if (empty($id)) { // See your own profile by default require_login(); $id = $USER->id; } if ($courseid == SITEID) { // Since Moodle 2.0 all site-level profiles are shown by profile.php redirect($CFG->wwwroot.'/user/profile.php?id='.$id); // Immediate redirect } $PAGE->set_url('/user/view.php', array('id'=>$id,'course'=>$courseid)); $user = $DB->get_record('user', array('id'=>$id), '*', MUST_EXIST); $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); $currentuser = ($user->id == $USER->id); $systemcontext = get_context_instance(CONTEXT_SYSTEM); $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); $usercontext = get_context_instance(CONTEXT_USER, $user->id, IGNORE_MISSING); // Require login first if (isguestuser($user)) { // can not view profile of guest - thre is nothing to see there print_error('invaliduserid'); } if (!empty($CFG->forceloginforprofiles)) { require_login(); // we can not log in to course due to the parent hack below } $PAGE->set_context($coursecontext); $PAGE->set_course($course); $PAGE->set_pagetype('course-view-' . $course->format); // To get the blocks exactly like the course $PAGE->add_body_class('path-user'); // So we can style it independently $PAGE->set_other_editing_capability('moodle/course:manageactivities'); $isparent = false; if (!$currentuser and !$user->deleted and $DB->record_exists('role_assignments', array('userid'=>$USER->id, 'contextid'=>$usercontext->id)) and has_capability('moodle/user:viewdetails', $usercontext)) { // TODO: very ugly hack - do not force "parents" to enrol into course their child is enrolled in, // this way they may access the profile where they get overview of grades and child activity in course, // please note this is just a guess! require_login(); $isparent = true; $PAGE->navigation->set_userid_for_parent_checks($id); } else { // normal course require_login($course); // what to do with users temporary accessing this course? should they see the details? } $strpersonalprofile = get_string('personalprofile'); $strparticipants = get_string("participants"); $struser = get_string("user"); $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $coursecontext)); /// Now test the actual capabilities and enrolment in course if ($currentuser) { // me if (!is_viewing($coursecontext) && !is_enrolled($coursecontext)) { // Need to have full access to a course to see the rest of own info echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('notenrolled', '', $fullname)); if (!empty($_SERVER['HTTP_REFERER'])) { echo $OUTPUT->continue_button($_SERVER['HTTP_REFERER']); } echo $OUTPUT->footer(); die; } } else { // somebody else $PAGE->set_title("$strpersonalprofile: "); $PAGE->set_heading("$strpersonalprofile: "); // check course level capabilities if (!has_capability('moodle/user:viewdetails', $coursecontext) && // normal enrolled user or mnager ($user->deleted or !has_capability('moodle/user:viewdetails', $usercontext))) { // usually parent print_error('cannotviewprofile'); } if (!is_enrolled($coursecontext, $user->id)) { // TODO: the only potential problem is that managers and inspectors might post in forum, but the link // to profile would not work - maybe a new capability - moodle/user:freely_acessile_profile_for_anybody // or test for course:inspect capability if (has_capability('moodle/role:assign', $coursecontext)) { $PAGE->navbar->add($fullname); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('notenrolled', '', $fullname)); } else { echo $OUTPUT->header(); $PAGE->navbar->add($struser); echo $OUTPUT->heading(get_string('notenrolledprofile')); } if (!empty($_SERVER['HTTP_REFERER'])) { echo $OUTPUT->continue_button($_SERVER['HTTP_REFERER']); } echo $OUTPUT->footer(); exit; } // If groups are in use and enforced throughout the course, then make sure we can meet in at least one course level group if (groups_get_course_groupmode($course) == SEPARATEGROUPS and $course->groupmodeforce and !has_capability('moodle/site:accessallgroups', $coursecontext) and !has_capability('moodle/site:accessallgroups', $coursecontext, $user->id)) { if (!isloggedin() or isguestuser()) { // do not use require_login() here because we might have already used require_login($course) redirect(get_login_url()); } $mygroups = array_keys(groups_get_all_groups($course->id, $USER->id, $course->defaultgroupingid, 'g.id, g.name')); $usergroups = array_keys(groups_get_all_groups($course->id, $user->id, $course->defaultgroupingid, 'g.id, g.name')); if (!array_intersect($mygroups, $usergroups)) { print_error("groupnotamember", '', "../course/view.php?id=$course->id"); } } } $PAGE->set_title("$course->fullname: $strpersonalprofile: $fullname"); $PAGE->set_heading($course->fullname); $PAGE->set_pagelayout('standard'); // Locate the users settings in the settings navigation and force it open. // This MUST be done after we've set up the page as it is going to cause theme and output to initialise. if (!$currentuser) { $PAGE->navigation->extend_for_user($user); if ($node = $PAGE->settingsnav->get('userviewingsettings'.$user->id)) { $node->forceopen = true; } } else if ($node = $PAGE->settingsnav->get('usercurrentsettings', navigation_node::TYPE_CONTAINER)) { $node->forceopen = true; } if ($node = $PAGE->settingsnav->get('courseadmin')) { $node->forceopen = false; } echo $OUTPUT->header(); echo '