id; } if (! $user = get_record("user", "id", $id) ) { error("No such user in this course"); } if (! $course = get_record("course", "id", $course) ) { error("No such course id"); } /// Make sure the current user is allowed to see this user if (empty($USER->id)) { $currentuser = false; } else { $currentuser = ($user->id == $USER->id); } if (!empty($CFG->forcelogin) || $course->id != SITEID) { require_login($course->id); } if ($course->id == SITEID) { $coursecontext = get_context_instance(CONTEXT_SYSTEM, SITEID); // SYSTEM context } else { $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context } $usercontext = get_context_instance(CONTEXT_USER, $user->id); // User context // make sure user can view this student's profile if ($USER->id != $user->id && !has_capability('moodle/user:viewdetails', $coursecontext) && !has_capability('moodle/user:viewdetails', $usercontext)) { error('You can not view the profile of this user'); } if (!empty($CFG->forceloginforprofiles)) { require_login(); if (isguest()) { redirect("$CFG->wwwroot/login/index.php"); } } $strpersonalprofile = get_string('personalprofile'); $strparticipants = get_string("participants"); $struser = get_string("user"); $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $coursecontext)); /// If the user being shown is not ourselves, then make sure we are allowed to see them! if (!$currentuser) { if ($course->id == SITEID) { // Reduce possibility of "browsing" userbase at site level if ($CFG->forceloginforprofiles and !isteacherinanycourse() and !isteacherinanycourse($user->id)) { // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366) print_header("$strpersonalprofile: ", "$strpersonalprofile: ", "id\">$strparticipants -> $struser", "", "", true, " ", navmenu($course)); print_heading(get_string('usernotavailable', 'error')); print_footer($course); exit; } } else { // Normal course if (!has_capability('moodle/course:view', $coursecontext, $user->id, false)) { if (has_capability('moodle/course:view', $coursecontext)) { print_header("$strpersonalprofile: ", "$strpersonalprofile: ", "id\">$course->shortname -> id\">$strparticipants -> $fullname", "", "", true, " ", navmenu($course)); print_heading(get_string('notenrolled', '', $fullname)); } else { print_header("$strpersonalprofile: ", "$strpersonalprofile: ", "id\">$course->shortname -> id\">$strparticipants -> $struser", "", "", true, " ", navmenu($course)); print_heading(get_string('notenrolledprofile')); } print_continue($_SERVER['HTTP_REFERER']); print_footer($course); exit; } } // If groups are in use, make sure we can see that group if (groupmode($course) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $coursecontext)) { require_login(); ///this is changed because of mygroupid $gtrue = (bool)groups_get_groups_for_user($user->id, $course->id); /*TODO: $gtrue = false; if ($mygroups = mygroupid($course->id)){ foreach ($mygroups as $group){ if (ismember($group, $user->id)){ $gtrue = true; } } }*/ if (!$gtrue) { print_header("$strpersonalprofile: ", "$strpersonalprofile: ", "id\">$course->shortname -> id\">$strparticipants", "", "", true, " ", navmenu($course)); error(get_string("groupnotamember"), "../course/view.php?id=$course->id"); } } } /// We've established they can see the user's name at least, so what about the rest? if ($course->id != SITEID) { print_header("$strpersonalprofile: $fullname", "$strpersonalprofile: $fullname", "id\">$course->shortname -> id\">$strparticipants -> $fullname", "", "", true, " ", navmenu($course)); } else { print_header("$course->fullname: $strpersonalprofile: $fullname", "$course->fullname", "$fullname", "", "", true, " ", navmenu($course)); } if (($course->id != SITEID) and ! isguest() ) { // Need to have access to a course to see that info if (!has_capability('moodle/course:view', $coursecontext)) { print_heading(get_string('notenrolled', '', $fullname)); print_footer($course); die; } } if ($user->deleted) { print_heading(get_string('userdeleted')); } /// OK, security out the way, now we are showing the user add_to_log($course->id, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id"); if ($course->id != SITEID) { if ($lastaccess = get_record('user_lastaccess', 'userid', $user->id, 'courseid', $course->id)) { $user->lastaccess = $lastaccess->timeaccess; } } /// Get the hidden field list if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) { $hiddenfields = array(); } else { $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields)); } /// Print tabs at top /// This same call is made in: /// /user/view.php /// /user/edit.php /// /course/user.php $currenttab = 'profile'; $showroles = 1; include('tabs.php'); if (is_mnet_remote_user($user)) { echo "
This profile is for a remote user from another Moodle system.
\n";
$remotehost = get_record('mnet_host', 'id', $user->mnethostid);
echo "Remote Moodle: wwwroot}/user/edit.php\">{$remotehost->name} (click here to edit your profile on the remote server)
"; print_user_picture($user->id, $course->id, $user->picture, true, false, false); echo " | ";
// Print the description
if ($user->description && !isset($hiddenfields['description'])) {
echo format_text($user->description, FORMAT_MOODLE)." "; } // Print all the little details in a list echo ' |