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 redirect("$CFG->wwwroot/login/index.php");
57 $strpersonalprofile = get_string('personalprofile');
58 $strparticipants = get_string("participants");
59 $struser = get_string("user");
61 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $coursecontext));
64 if (has_capability('moodle/course:viewparticipants', $coursecontext) ||
has_capability('moodle/site:viewparticipants', $systemcontext)) {
65 $navlinks[] = array('name' => $strparticipants, 'link' => "index.php?id=$course->id", 'type' => 'misc');
68 /// If the user being shown is not ourselves, then make sure we are allowed to see them!
71 if ($course->id
== SITEID
) { // Reduce possibility of "browsing" userbase at site level
72 if ($CFG->forceloginforprofiles
and !isteacherinanycourse()
73 and !isteacherinanycourse($user->id
)
74 and !has_capability('moodle/user:viewdetails', $usercontext)) { // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
76 $navlinks[] = array('name' => $struser, 'link' => null, 'type' => 'misc');
77 $navigation = build_navigation($navlinks);
79 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, " ", navmenu($course));
80 print_heading(get_string('usernotavailable', 'error'));
81 print_footer($course);
84 } else { // Normal course
86 if (!has_capability('moodle/user:viewdetails', $coursecontext) &&
87 !has_capability('moodle/user:viewdetails', $usercontext)) {
88 print_error('cannotviewprofile');
91 if (!has_capability('moodle/course:view', $coursecontext, $user->id
, false)) {
92 if (has_capability('moodle/role:assign', $coursecontext)) {
93 $navlinks[] = array('name' => $fullname, 'link' => null, 'type' => 'misc');
94 $navigation = build_navigation($navlinks);
95 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, " ", navmenu($course));
96 print_heading(get_string('notenrolled', '', $fullname));
98 $navlinks[] = array('name' => $struser, 'link' => null, 'type' => 'misc');
99 $navigation = build_navigation($navlinks);
100 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, " ", navmenu($course));
101 print_heading(get_string('notenrolledprofile'));
103 print_continue($_SERVER['HTTP_REFERER']);
104 print_footer($course);
110 // If groups are in use, make sure we can see that group
111 if (groups_get_course_groupmode($course) == SEPARATEGROUPS
and !has_capability('moodle/site:accessallgroups', $coursecontext)) {
114 ///this is changed because of mygroupid
115 $gtrue = (bool)groups_get_all_groups($course->id
, $user->id
);
117 $navigation = build_navigation($navlinks);
118 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, " ", navmenu($course));
119 print_error("groupnotamember", '', "../course/view.php?id=$course->id");
125 /// We've established they can see the user's name at least, so what about the rest?
127 $navlinks[] = array('name' => $fullname, 'link' => null, 'type' => 'misc');
129 $navigation = build_navigation($navlinks);
131 print_header("$course->fullname: $strpersonalprofile: $fullname", $course->fullname
,
132 $navigation, "", "", true, " ", navmenu($course));
135 if (($course->id
!= SITEID
) and ! isguest() ) { // Need to have access to a course to see that info
136 if (!has_capability('moodle/course:view', $coursecontext, $user->id
)) {
137 print_heading(get_string('notenrolled', '', $fullname));
138 print_footer($course);
143 if ($user->deleted
) {
144 print_heading(get_string('userdeleted'));
145 if (!has_capability('moodle/user:update', $coursecontext)) {
146 print_footer($course);
151 /// OK, security out the way, now we are showing the user
153 add_to_log($course->id
, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
155 if ($course->id
!= SITEID
) {
156 $user->lastaccess
= false;
157 if ($lastaccess = get_record('user_lastaccess', 'userid', $user->id
, 'courseid', $course->id
)) {
158 $user->lastaccess
= $lastaccess->timeaccess
;
163 /// Get the hidden field list
164 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
165 $hiddenfields = array();
167 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields
));
170 /// Print tabs at top
171 /// This same call is made in:
176 $currenttab = 'profile';
178 if (!$user->deleted
) {
182 if (is_mnet_remote_user($user)) {
188 a.name as application,
191 {$CFG->prefix}mnet_host h,
192 {$CFG->prefix}mnet_application a
194 h.id = '{$user->mnethostid}' AND
195 h.applicationid = a.id
200 $remotehost = get_record_sql($sql);
202 echo '<p class="errorboxcontent">'.get_string('remoteappuser', $remotehost->application
)." <br />\n";
203 if ($USER->id
== $user->id
) {
204 if ($remotehost->application
=='moodle') {
205 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/user/edit.php\">{$remotehost->name}</a> ".get_string('editremoteprofile')." </p>\n";
207 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a> ".get_string('gotoyourserver')." </p>\n";
210 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a></p>\n";
214 echo '<table width="80%" class="userinfobox" summary="">';
216 echo '<td class="side">';
217 print_user_picture($user, $course->id
, $user->picture
, true, false, false);
218 echo '</td><td class="content">';
220 // Print the description
222 if ($user->description
&& !isset($hiddenfields['description'])) {
223 $has_courseid = ($course->id
!= SITEID
);
224 if (!$has_courseid && !empty($CFG->profilesforenrolledusersonly
) && !record_exists('role_assignments', 'userid', $id)) {
225 echo get_string('profilenotshown', 'moodle').'<hr />';
227 echo format_text($user->description
, FORMAT_MOODLE
)."<hr />";
231 // Print all the little details in a list
233 echo '<table class="list">';
235 if (! isset($hiddenfields['country']) && $user->country
) {
236 $countries = get_list_of_countries();
237 print_row(get_string('country') . ':', $countries[$user->country
]);
240 if (! isset($hiddenfields['city']) && $user->city
) {
241 print_row(get_string('city') . ':', $user->city
);
244 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
245 if ($user->address
) {
246 print_row(get_string("address").":", "$user->address");
249 print_row(get_string("phone").":", "$user->phone1");
252 print_row(get_string("phone2").":", "$user->phone2");
256 if ($user->maildisplay
== 1 or
257 ($user->maildisplay
== 2 and ($course->id
!= SITEID
) and !isguest()) or
258 has_capability('moodle/course:useremail', $coursecontext)) {
262 if (has_capability('moodle/course:useremail', $coursecontext) or $currentuser) { /// Can use the enable/disable email stuff
263 if (!empty($enable) and confirm_sesskey()) { /// Recieved a parameter to enable the email address
264 set_field('user', 'emailstop', 0, 'id', $user->id
);
265 $user->emailstop
= 0;
267 if (!empty($disable) and confirm_sesskey()) { /// Recieved a parameter to disable the email address
268 set_field('user', 'emailstop', 1, 'id', $user->id
);
269 $user->emailstop
= 1;
273 if (has_capability('moodle/course:useremail', $coursecontext)) { /// Can use the enable/disable email stuff
274 if ($user->emailstop
) {
275 $switchparam = 'enable';
276 $switchtitle = get_string('emaildisable');
277 $switchclick = get_string('emailenableclick');
278 $switchpix = 'emailno.gif';
280 $switchparam = 'disable';
281 $switchtitle = get_string('emailenable');
282 $switchclick = get_string('emaildisableclick');
283 $switchpix = 'email.gif';
285 $emailswitch = " <a title=\"$switchclick\" ".
286 "href=\"view.php?id=$user->id&course=$course->id&$switchparam=1&sesskey=".sesskey()."\">".
287 "<img src=\"$CFG->pixpath/t/$switchpix\" alt=\"$switchclick\" /></a>";
289 } else if ($currentuser) { /// Can only re-enable an email this way
290 if ($user->emailstop
) { // Include link that tells how to re-enable their email
291 $switchparam = 'enable';
292 $switchtitle = get_string('emaildisable');
293 $switchclick = get_string('emailenableclick');
295 $emailswitch = " (<a title=\"$switchclick\" ".
296 "href=\"view.php?id=$user->id&course=$course->id&enable=1&sesskey=".sesskey()."\">$switchtitle</a>)";
300 print_row(get_string("email").":", obfuscate_mailto($user->email
, '', $user->emailstop
)."$emailswitch");
303 if ($user->url
&& !isset($hiddenfields['webpage'])) {
305 if (strpos($user->url
, '://') === false) {
306 $url = 'http://'. $url;
308 print_row(get_string("webpage") .":", "<a href=\"$url\">$user->url</a>");
311 if ($user->icq
&& !isset($hiddenfields['icqnumber'])) {
312 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>");
315 if ($user->skype
&& !isset($hiddenfields['skypeid'])) {
316 print_row(get_string('skypeid').':','<a href="callto:'.urlencode($user->skype
).'">'.s($user->skype
).
317 ' <img src="http://mystatus.skype.com/smallicon/'.urlencode($user->skype
).'" alt="'.get_string('status').'" '.
320 if ($user->yahoo
&& !isset($hiddenfields['yahooid'])) {
321 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>");
323 if ($user->aim
&& !isset($hiddenfields['aimid'])) {
324 print_row(get_string('aimid').':', '<a href="aim:goim?screenname='.s($user->aim
).'">'.s($user->aim
).'</a>');
326 if ($user->msn
&& !isset($hiddenfields['msnid'])) {
327 print_row(get_string('msnid').':', s($user->msn
));
330 /// Print the Custom User Fields
331 profile_display_fields($user->id
);
334 if (!isset($hiddenfields['mycourses'])) {
335 if ($mycourses = get_my_courses($user->id
, 'visible DESC,sortorder ASC', null, false, 21)) {
338 foreach ($mycourses as $mycourse) {
339 if ($mycourse->category
) {
340 if ($mycourse->id
!= $course->id
){
342 if ($mycourse->visible
== 0) {
343 // get_my_courses will filter courses $USER cannot see
344 // if we get one with visible 0 it just means it's hidden
345 // ... but not from $USER
346 $class = 'class="dimmed"';
348 $courselisting .= "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&course={$mycourse->id}\" $class >"
349 . format_string($mycourse->fullname
) . "</a>, ";
352 $courselisting .= format_string($mycourse->fullname
) . ", ";
357 $courselisting.= "...";
361 print_row(get_string('courses').':', rtrim($courselisting,', '));
364 if (!isset($hiddenfields['firstaccess'])) {
365 if ($user->firstaccess
) {
366 $datestring = userdate($user->firstaccess
)." (".format_time(time() - $user->firstaccess
).")";
368 $datestring = get_string("never");
370 print_row(get_string("firstaccess").":", $datestring);
372 if (!isset($hiddenfields['lastaccess'])) {
373 if ($user->lastaccess
) {
374 $datestring = userdate($user->lastaccess
)." (".format_time(time() - $user->lastaccess
).")";
376 $datestring = get_string("never");
378 print_row(get_string("lastaccess").":", $datestring);
382 if ($rolestring = get_user_roles_in_context($id, $coursecontext)) {
383 print_row(get_string('roles').':', format_string($rolestring, false));
387 if (!isset($hiddenfields['groups'])) {
388 $isseparategroups = ($course->groupmode
== SEPARATEGROUPS
and !has_capability('moodle/site:accessallgroups', $coursecontext));
389 if (!$isseparategroups){
390 if ($usergroups = groups_get_all_groups($course->id
, $user->id
)){
392 foreach ($usergroups as $group){
393 $groupstr .= ' <a href="'.$CFG->wwwroot
.'/user/index.php?id='.$course->id
.'&group='.$group->id
.'">'.format_string($group->name
).'</a>,';
395 print_row(get_string("group").":", rtrim($groupstr, ', '));
399 /// End of printing groups
401 /// Printing Interests
402 if( !empty($CFG->usetags
)) {
403 if ( $interests = tag_get_tags_csv('user', $user->id
) ) {
404 print_row(get_string('interests') .": ", $interests);
407 /// End of Printing Interests
411 echo "</td></tr></table>";
413 $userauth = get_auth_plugin($user->auth
);
415 $passwordchangeurl = false;
416 if ($currentuser and $userauth->can_change_password() and !isguestuser() and has_capability('moodle/user:changeownpassword', $systemcontext)) {
417 if (!$passwordchangeurl = $userauth->change_password_url()) {
418 if (empty($CFG->loginhttps
)) {
419 $passwordchangeurl = "$CFG->wwwroot/login/change_password.php";
421 $passwordchangeurl = str_replace('http:', 'https:', $CFG->wwwroot
.'/login/change_password.php');
426 // Print other functions
427 echo '<div class="buttons">';
429 if ($passwordchangeurl) {
430 $params = array('id'=>$course->id
);
432 if (!empty($USER->realuser
)) {
433 $passwordchangeurl = ''; // do not use actual change password url - might contain sensitive data
435 $parts = explode('?', $passwordchangeurl);
436 $passwordchangeurl = reset($parts);
437 $after = next($parts);
438 preg_match_all('/([^&=]+)=([^&=]+)/', $after, $matches);
439 if (count($matches)) {
440 foreach($matches[0] as $key=>$match) {
441 $params[$matches[1][$key]] = $matches[2][$key];
445 echo "<form action=\"$passwordchangeurl\" method=\"get\">";
447 foreach($params as $key=>$value) {
448 echo '<input type="hidden" name="'.$key.'" value="'.s($value).'" />';
450 if (!empty($USER->realuser
)) {
451 // changing of password when "Logged in as" is not allowed
452 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" disabled=\"disabled\" />";
454 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
460 if ($course->id
!= SITEID
&& empty($course->metacourse
)) { // Mostly only useful at course level
464 if ($user->id
== $USER->id
) { // Myself
465 $canunenrol = has_capability('moodle/course:view', $coursecontext, NULL) && // Course participant
466 has_capability('moodle/role:unassignself', $coursecontext, NULL, false) && // Can unassign myself
467 get_user_roles($coursecontext, $user->id
, false); // Must have role in course
469 } else if (has_capability('moodle/role:assign', $coursecontext, NULL)) { // I can assign roles
470 if ($roles = get_user_roles($coursecontext, $user->id
, false)) {
472 foreach($roles as $role) {
473 if (!user_can_assign($coursecontext, $role->roleid
)) {
474 $canunenrol = false; // I can not unassign all roles in this course :-(
482 echo '<form action="'.$CFG->wwwroot
.'/course/unenrol.php" method="get">';
484 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
485 echo '<input type="hidden" name="user" value="'.$user->id
.'" />';
486 echo '<input type="submit" value="'.s(get_string('unenrolme', '', $course->shortname
)).'" />';
492 if (!$user->deleted
and $USER->id
!= $user->id
&& empty($USER->realuser
) && has_capability('moodle/user:loginas', $coursecontext) &&
493 ! has_capability('moodle/site:doanything', $coursecontext, $user->id
, false)) {
494 echo '<form action="'.$CFG->wwwroot
.'/course/loginas.php" method="get">';
496 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
497 echo '<input type="hidden" name="user" value="'.$user->id
.'" />';
498 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
499 echo '<input type="submit" value="'.get_string('loginas').'" />';
504 if (!$user->deleted
and !empty($CFG->messaging
) and !isguest() and has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTEM
))) {
505 if (!empty($USER->id
) and ($USER->id
== $user->id
)) {
506 if ($countmessages = count_records('message', 'useridto', $user->id
)) {
507 $messagebuttonname = get_string("messages", "message")."($countmessages)";
509 $messagebuttonname = get_string("messages", "message");
511 echo "<form onclick=\"this.target='message'\" action=\"../message/index.php\" method=\"get\">";
513 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);\" />";
517 echo "<form onclick=\"this.target='message$user->id'\" action=\"../message/discussion.php\" method=\"get\">";
519 echo "<input type=\"hidden\" name=\"id\" value=\"$user->id\" />";
520 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);\" />";
525 // Authorize.net: User Payments
526 if ($course->enrol
== 'authorize' ||
(empty($course->enrol
) && $CFG->enrol
== 'authorize')) {
527 echo "<form action=\"../enrol/authorize/index.php\" method=\"get\">";
529 echo "<input type=\"hidden\" name=\"course\" value=\"$course->id\" />";
530 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
531 echo "<input type=\"submit\" value=\"".get_string('payments')."\" />";
537 if ($CFG->debugdisplay
&& debugging('', DEBUG_DEVELOPER
) && $USER->id
== $user->id
) { // Show user object
539 print_heading('DEBUG MODE: User session variables');
543 print_footer($course);
545 /// Functions ///////
547 function print_row($left, $right) {
548 echo "\n<tr><td class=\"label c0\">$left</td><td class=\"info c1\">$right</td></tr>\n";