3 // Display profile for a particular user
5 require_once("../config.php");
6 require_once($CFG->dirroot
.'/user/profile/lib.php');
7 require_once($CFG->dirroot
.'/tag/lib.php');
9 $id = optional_param('id', 0, PARAM_INT
); // user id
10 $course = optional_param('course', SITEID
, PARAM_INT
); // course id (defaults to Site)
11 $enable = optional_param('enable', ''); // enable email
12 $disable = optional_param('disable', ''); // disable email
14 if (empty($id)) { // See your own profile by default
19 if (! $user = get_record("user", "id", $id) ) {
20 error("No such user in this course");
23 if (! $course = get_record("course", "id", $course) ) {
24 error("No such course id");
27 /// Make sure the current user is allowed to see this user
29 if (empty($USER->id
)) {
32 $currentuser = ($user->id
== $USER->id
);
35 if ($course->id
== SITEID
) {
36 $coursecontext = get_context_instance(CONTEXT_SYSTEM
); // SYSTEM context
38 $coursecontext = get_context_instance(CONTEXT_COURSE
, $course->id
); // Course context
40 $usercontext = get_context_instance(CONTEXT_USER
, $user->id
); // User context
41 $systemcontext = get_context_instance(CONTEXT_SYSTEM
); // SYSTEM context
43 if (!empty($CFG->forcelogin
) ||
$course->id
!= SITEID
) {
44 // do not force parents to enrol
45 if (!get_record('role_assignments', 'userid', $USER->id
, 'contextid', $usercontext->id
)) {
46 require_login($course->id
);
50 if (!empty($CFG->forceloginforprofiles
)) {
53 $loginurl ="$CFG->wwwroot/login/index.php";
54 if (!empty($CFG->loginhttps
)) {
55 $loginurl = str_replace("http://", "https://", $loginurl);
61 $strpersonalprofile = get_string('personalprofile');
62 $strparticipants = get_string("participants");
63 $struser = get_string("user");
65 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $coursecontext));
68 if (has_capability('moodle/course:viewparticipants', $coursecontext) ||
has_capability('moodle/site:viewparticipants', $systemcontext)) {
69 $navlinks[] = array('name' => $strparticipants, 'link' => "index.php?id=$course->id", 'type' => 'misc');
72 /// If the user being shown is not ourselves, then make sure we are allowed to see them!
75 if ($course->id
== SITEID
) { // Reduce possibility of "browsing" userbase at site level
76 if ($CFG->forceloginforprofiles
and !isteacherinanycourse()
77 and !isteacherinanycourse($user->id
)
78 and !has_capability('moodle/user:viewdetails', $usercontext)) { // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
80 $navlinks[] = array('name' => $struser, 'link' => null, 'type' => 'misc');
81 $navigation = build_navigation($navlinks);
83 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, " ", navmenu($course));
84 print_heading(get_string('usernotavailable', 'error'));
85 print_footer($course);
88 } else { // Normal course
90 if (!has_capability('moodle/user:viewdetails', $coursecontext) &&
91 !has_capability('moodle/user:viewdetails', $usercontext)) {
92 print_error('cannotviewprofile');
95 if (!has_capability('moodle/course:view', $coursecontext, $user->id
, false)) {
96 if (has_capability('moodle/role:assign', $coursecontext)) {
97 $navlinks[] = array('name' => $fullname, 'link' => null, 'type' => 'misc');
98 $navigation = build_navigation($navlinks);
99 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, " ", navmenu($course));
100 print_heading(get_string('notenrolled', '', $fullname));
102 $navlinks[] = array('name' => $struser, 'link' => null, 'type' => 'misc');
103 $navigation = build_navigation($navlinks);
104 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, " ", navmenu($course));
105 print_heading(get_string('notenrolledprofile'));
107 print_continue($_SERVER['HTTP_REFERER']);
108 print_footer($course);
114 // If groups are in use, make sure we can see that group
115 if (groups_get_course_groupmode($course) == SEPARATEGROUPS
and !has_capability('moodle/site:accessallgroups', $coursecontext)) {
118 ///this is changed because of mygroupid
119 $gtrue = (bool)groups_get_all_groups($course->id
, $user->id
);
121 $navigation = build_navigation($navlinks);
122 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, " ", navmenu($course));
123 print_error("groupnotamember", '', "../course/view.php?id=$course->id");
129 /// We've established they can see the user's name at least, so what about the rest?
131 $navlinks[] = array('name' => $fullname, 'link' => null, 'type' => 'misc');
133 $navigation = build_navigation($navlinks);
135 print_header("$course->fullname: $strpersonalprofile: $fullname", $course->fullname
,
136 $navigation, "", "", true, " ", navmenu($course));
139 if (($course->id
!= SITEID
) and ! isguest() ) { // Need to have access to a course to see that info
140 if (!has_capability('moodle/course:view', $coursecontext, $user->id
)) {
141 print_heading(get_string('notenrolled', '', $fullname));
142 print_footer($course);
147 if ($user->deleted
) {
148 print_heading(get_string('userdeleted'));
149 if (!has_capability('moodle/user:update', $coursecontext)) {
150 print_footer($course);
155 /// OK, security out the way, now we are showing the user
157 add_to_log($course->id
, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
159 if ($course->id
!= SITEID
) {
160 $user->lastaccess
= false;
161 if ($lastaccess = get_record('user_lastaccess', 'userid', $user->id
, 'courseid', $course->id
)) {
162 $user->lastaccess
= $lastaccess->timeaccess
;
167 /// Get the hidden field list
168 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
169 $hiddenfields = array();
171 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields
));
174 /// Print tabs at top
175 /// This same call is made in:
180 $currenttab = 'profile';
182 if (!$user->deleted
) {
186 if (is_mnet_remote_user($user)) {
192 a.name as application,
195 {$CFG->prefix}mnet_host h,
196 {$CFG->prefix}mnet_application a
198 h.id = '{$user->mnethostid}' AND
199 h.applicationid = a.id
204 $remotehost = get_record_sql($sql);
206 echo '<p class="errorboxcontent">'.get_string('remoteappuser', $remotehost->application
)." <br />\n";
207 if ($USER->id
== $user->id
) {
208 if ($remotehost->application
=='moodle') {
209 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/user/edit.php\">{$remotehost->name}</a> ".get_string('editremoteprofile')." </p>\n";
211 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a> ".get_string('gotoyourserver')." </p>\n";
214 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a></p>\n";
218 echo '<table width="80%" class="userinfobox" summary="">';
220 echo '<td class="side">';
221 print_user_picture($user, $course->id
, $user->picture
, true, false, false);
222 echo '</td><td class="content">';
224 // Print the description
226 if ($user->description
&& !isset($hiddenfields['description'])) {
227 $has_courseid = ($course->id
!= SITEID
);
228 if (!$has_courseid && !empty($CFG->profilesforenrolledusersonly
) && !record_exists('role_assignments', 'userid', $id)) {
229 echo get_string('profilenotshown', 'moodle').'<hr />';
231 echo format_text($user->description
, FORMAT_MOODLE
)."<hr />";
235 // Print all the little details in a list
237 echo '<table class="list">';
239 if (! isset($hiddenfields['country']) && $user->country
) {
240 $countries = get_list_of_countries();
241 print_row(get_string('country') . ':', $countries[$user->country
]);
244 if (! isset($hiddenfields['city']) && $user->city
) {
245 print_row(get_string('city') . ':', $user->city
);
248 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
249 if ($user->address
) {
250 print_row(get_string("address").":", "$user->address");
253 print_row(get_string("phone").":", "$user->phone1");
256 print_row(get_string("phone2").":", "$user->phone2");
260 if ($user->maildisplay
== 1 or
261 ($user->maildisplay
== 2 and ($course->id
!= SITEID
) and !isguest()) or
262 has_capability('moodle/course:useremail', $coursecontext)) {
266 if (has_capability('moodle/course:useremail', $coursecontext) or $currentuser) { /// Can use the enable/disable email stuff
267 if (!empty($enable) and confirm_sesskey()) { /// Recieved a parameter to enable the email address
268 set_field('user', 'emailstop', 0, 'id', $user->id
);
269 $user->emailstop
= 0;
271 if (!empty($disable) and confirm_sesskey()) { /// Recieved a parameter to disable the email address
272 set_field('user', 'emailstop', 1, 'id', $user->id
);
273 $user->emailstop
= 1;
277 if (has_capability('moodle/course:useremail', $coursecontext)) { /// Can use the enable/disable email stuff
278 if ($user->emailstop
) {
279 $switchparam = 'enable';
280 $switchtitle = get_string('emaildisable');
281 $switchclick = get_string('emailenableclick');
282 $switchpix = 'emailno.gif';
284 $switchparam = 'disable';
285 $switchtitle = get_string('emailenable');
286 $switchclick = get_string('emaildisableclick');
287 $switchpix = 'email.gif';
289 $emailswitch = " <a title=\"$switchclick\" ".
290 "href=\"view.php?id=$user->id&course=$course->id&$switchparam=1&sesskey=".sesskey()."\">".
291 "<img src=\"$CFG->pixpath/t/$switchpix\" alt=\"$switchclick\" /></a>";
293 } else if ($currentuser) { /// Can only re-enable an email this way
294 if ($user->emailstop
) { // Include link that tells how to re-enable their email
295 $switchparam = 'enable';
296 $switchtitle = get_string('emaildisable');
297 $switchclick = get_string('emailenableclick');
299 $emailswitch = " (<a title=\"$switchclick\" ".
300 "href=\"view.php?id=$user->id&course=$course->id&enable=1&sesskey=".sesskey()."\">$switchtitle</a>)";
304 print_row(get_string("email").":", obfuscate_mailto($user->email
, '', $user->emailstop
)."$emailswitch");
307 if ($user->url
&& !isset($hiddenfields['webpage'])) {
309 if (strpos($user->url
, '://') === false) {
310 $url = 'http://'. $url;
312 print_row(get_string("webpage") .":", "<a href=\"$url\">$user->url</a>");
315 if ($user->icq
&& !isset($hiddenfields['icqnumber'])) {
316 print_row(get_string('icqnumber').':',"<a href=\"http://web.icq.com/wwp?uin=$user->icq\">$user->icq <img src=\"http://web.icq.com/whitepages/online?icq=$user->icq&img=5\" alt=\"\" /></a>");
319 if ($user->skype
&& !isset($hiddenfields['skypeid'])) {
320 print_row(get_string('skypeid').':','<a href="callto:'.urlencode($user->skype
).'">'.s($user->skype
).
321 ' <img src="http://mystatus.skype.com/smallicon/'.urlencode($user->skype
).'" alt="'.get_string('status').'" '.
324 if ($user->yahoo
&& !isset($hiddenfields['yahooid'])) {
325 print_row(get_string('yahooid').':', '<a href="http://edit.yahoo.com/config/send_webmesg?.target='.urlencode($user->yahoo
).'&.src=pg">'.s($user->yahoo
)." <img src=\"http://opi.yahoo.com/online?u=".urlencode($user->yahoo
)."&m=g&t=0\" alt=\"\"></a>");
327 if ($user->aim
&& !isset($hiddenfields['aimid'])) {
328 print_row(get_string('aimid').':', '<a href="aim:goim?screenname='.s($user->aim
).'">'.s($user->aim
).'</a>');
330 if ($user->msn
&& !isset($hiddenfields['msnid'])) {
331 print_row(get_string('msnid').':', s($user->msn
));
334 /// Print the Custom User Fields
335 profile_display_fields($user->id
);
338 if (!isset($hiddenfields['mycourses'])) {
339 if ($mycourses = get_my_courses($user->id
, 'visible DESC,sortorder ASC', null, false, 21)) {
342 foreach ($mycourses as $mycourse) {
343 if ($mycourse->category
) {
344 if ($mycourse->id
!= $course->id
){
346 if ($mycourse->visible
== 0) {
347 // get_my_courses will filter courses $USER cannot see
348 // if we get one with visible 0 it just means it's hidden
349 // ... but not from $USER
350 $class = 'class="dimmed"';
352 $courselisting .= "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&course={$mycourse->id}\" $class >"
353 . format_string($mycourse->fullname
) . "</a>, ";
356 $courselisting .= format_string($mycourse->fullname
) . ", ";
361 $courselisting.= "...";
365 print_row(get_string('courses').':', rtrim($courselisting,', '));
368 if (!isset($hiddenfields['firstaccess'])) {
369 if ($user->firstaccess
) {
370 $datestring = userdate($user->firstaccess
)." (".format_time(time() - $user->firstaccess
).")";
372 $datestring = get_string("never");
374 print_row(get_string("firstaccess").":", $datestring);
376 if (!isset($hiddenfields['lastaccess'])) {
377 if ($user->lastaccess
) {
378 $datestring = userdate($user->lastaccess
)." (".format_time(time() - $user->lastaccess
).")";
380 $datestring = get_string("never");
382 print_row(get_string("lastaccess").":", $datestring);
386 if ($rolestring = get_user_roles_in_context($id, $coursecontext)) {
387 print_row(get_string('roles').':', format_string($rolestring, false));
391 if (!isset($hiddenfields['groups'])) {
392 $isseparategroups = ($course->groupmode
== SEPARATEGROUPS
and !has_capability('moodle/site:accessallgroups', $coursecontext));
393 if (!$isseparategroups){
394 if ($usergroups = groups_get_all_groups($course->id
, $user->id
)){
396 foreach ($usergroups as $group){
397 $groupstr .= ' <a href="'.$CFG->wwwroot
.'/user/index.php?id='.$course->id
.'&group='.$group->id
.'">'.format_string($group->name
).'</a>,';
399 print_row(get_string("group").":", rtrim($groupstr, ', '));
403 /// End of printing groups
405 /// Printing Interests
406 if( !empty($CFG->usetags
)) {
407 if ( $interests = tag_get_tags_csv('user', $user->id
) ) {
408 print_row(get_string('interests') .": ", $interests);
411 /// End of Printing Interests
415 echo "</td></tr></table>";
417 $userauth = get_auth_plugin($user->auth
);
419 $passwordchangeurl = false;
420 if ($currentuser and $userauth->can_change_password() and !isguestuser() and has_capability('moodle/user:changeownpassword', $systemcontext)) {
421 if (!$passwordchangeurl = $userauth->change_password_url()) {
422 if (empty($CFG->loginhttps
)) {
423 $passwordchangeurl = "$CFG->wwwroot/login/change_password.php";
425 $passwordchangeurl = str_replace('http:', 'https:', $CFG->wwwroot
.'/login/change_password.php');
430 // Print other functions
431 echo '<div class="buttons">';
433 if ($passwordchangeurl) {
434 $params = array('id'=>$course->id
);
436 if (!empty($USER->realuser
)) {
437 $passwordchangeurl = ''; // do not use actual change password url - might contain sensitive data
439 $parts = explode('?', $passwordchangeurl);
440 $passwordchangeurl = reset($parts);
441 $after = next($parts);
442 preg_match_all('/([^&=]+)=([^&=]+)/', $after, $matches);
443 if (count($matches)) {
444 foreach($matches[0] as $key=>$match) {
445 $params[$matches[1][$key]] = $matches[2][$key];
449 echo "<form action=\"$passwordchangeurl\" method=\"get\">";
451 foreach($params as $key=>$value) {
452 echo '<input type="hidden" name="'.$key.'" value="'.s($value).'" />';
454 if (!empty($USER->realuser
)) {
455 // changing of password when "Logged in as" is not allowed
456 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" disabled=\"disabled\" />";
458 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
464 if ($course->id
!= SITEID
&& empty($course->metacourse
)) { // Mostly only useful at course level
468 if ($user->id
== $USER->id
) { // Myself
469 $canunenrol = has_capability('moodle/course:view', $coursecontext, NULL) && // Course participant
470 has_capability('moodle/role:unassignself', $coursecontext, NULL, false) && // Can unassign myself
471 get_user_roles($coursecontext, $user->id
, false); // Must have role in course
473 } else if (has_capability('moodle/role:assign', $coursecontext, NULL)) { // I can assign roles
474 if ($roles = get_user_roles($coursecontext, $user->id
, false)) {
476 foreach($roles as $role) {
477 if (!user_can_assign($coursecontext, $role->roleid
)) {
478 $canunenrol = false; // I can not unassign all roles in this course :-(
486 echo '<form action="'.$CFG->wwwroot
.'/course/unenrol.php" method="get">';
488 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
489 echo '<input type="hidden" name="user" value="'.$user->id
.'" />';
490 echo '<input type="submit" value="'.s(get_string('unenrolme', '', $course->shortname
)).'" />';
496 if (!$user->deleted
and $USER->id
!= $user->id
&& empty($USER->realuser
) && has_capability('moodle/user:loginas', $coursecontext) &&
497 ! has_capability('moodle/site:doanything', $coursecontext, $user->id
, false)) {
498 echo '<form action="'.$CFG->wwwroot
.'/course/loginas.php" method="get">';
500 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
501 echo '<input type="hidden" name="user" value="'.$user->id
.'" />';
502 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
503 echo '<input type="submit" value="'.get_string('loginas').'" />';
508 if (!$user->deleted
and !empty($CFG->messaging
) and !isguest() and has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTEM
))) {
509 if (!empty($USER->id
) and ($USER->id
== $user->id
)) {
510 if ($countmessages = count_records('message', 'useridto', $user->id
)) {
511 $messagebuttonname = get_string("messages", "message")."($countmessages)";
513 $messagebuttonname = get_string("messages", "message");
515 echo "<form onclick=\"this.target='message'\" action=\"../message/index.php\" method=\"get\">";
517 echo "<input type=\"submit\" value=\"$messagebuttonname\" onclick=\"return openpopup('/message/index.php', 'message', 'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500', 0);\" />";
521 echo "<form onclick=\"this.target='message$user->id'\" action=\"../message/discussion.php\" method=\"get\">";
523 echo "<input type=\"hidden\" name=\"id\" value=\"$user->id\" />";
524 echo "<input type=\"submit\" value=\"".get_string("sendmessage", "message")."\" onclick=\"return openpopup('/message/discussion.php?id=$user->id', 'message_$user->id', 'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500', 0);\" />";
529 // Authorize.net: User Payments
530 if ($course->enrol
== 'authorize' ||
(empty($course->enrol
) && $CFG->enrol
== 'authorize')) {
531 echo "<form action=\"../enrol/authorize/index.php\" method=\"get\">";
533 echo "<input type=\"hidden\" name=\"course\" value=\"$course->id\" />";
534 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
535 echo "<input type=\"submit\" value=\"".get_string('payments')."\" />";
541 if ($CFG->debugdisplay
&& debugging('', DEBUG_DEVELOPER
) && $USER->id
== $user->id
) { // Show user object
543 print_heading('DEBUG MODE: User session variables');
547 print_footer($course);
549 /// Functions ///////
551 function print_row($left, $right) {
552 echo "\n<tr><td class=\"label c0\">$left</td><td class=\"info c1\">$right</td></tr>\n";