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/course:view', $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'));
147 /// OK, security out the way, now we are showing the user
149 add_to_log($course->id
, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
151 if ($course->id
!= SITEID
) {
152 $user->lastaccess
= false;
153 if ($lastaccess = get_record('user_lastaccess', 'userid', $user->id
, 'courseid', $course->id
)) {
154 $user->lastaccess
= $lastaccess->timeaccess
;
159 /// Get the hidden field list
160 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
161 $hiddenfields = array();
163 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields
));
166 /// Print tabs at top
167 /// This same call is made in:
172 $currenttab = 'profile';
176 if (is_mnet_remote_user($user)) {
182 a.name as application,
185 {$CFG->prefix}mnet_host h,
186 {$CFG->prefix}mnet_application a
188 h.id = '{$user->mnethostid}' AND
189 h.applicationid = a.id
194 $remotehost = get_record_sql($sql);
196 echo '<p class="errorboxcontent">'.get_string('remote'.$remotehost->application
.'user')." <br />\n";
197 if ($USER->id
== $user->id
) {
198 if ($remotehost->application
=='moodle') {
199 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/user/edit.php\">{$remotehost->name}</a> ".get_string('editremoteprofile')." </p>\n";
201 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a> ".get_string('gotoyourserver')." </p>\n";
204 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a></p>\n";
208 echo '<table width="80%" class="userinfobox" summary="">';
210 echo '<td class="side">';
211 print_user_picture($user, $course->id
, $user->picture
, true, false, false);
212 echo '</td><td class="content">';
214 // Print the description
216 if ($user->description
&& !isset($hiddenfields['description'])) {
217 echo format_text($user->description
, FORMAT_MOODLE
)."<hr />";
220 // Print all the little details in a list
222 echo '<table class="list">';
224 if (! isset($hiddenfields['country']) && $user->country
) {
225 $countries = get_list_of_countries();
226 print_row(get_string('country') . ':', $countries[$user->country
]);
229 if (! isset($hiddenfields['city']) && $user->city
) {
230 print_row(get_string('city') . ':', $user->city
);
233 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
234 if ($user->address
) {
235 print_row(get_string("address").":", "$user->address");
238 print_row(get_string("phone").":", "$user->phone1");
241 print_row(get_string("phone2").":", "$user->phone2");
245 if ($user->maildisplay
== 1 or
246 ($user->maildisplay
== 2 and ($course->id
!= SITEID
) and !isguest()) or
247 has_capability('moodle/course:useremail', $coursecontext)) {
251 if (has_capability('moodle/course:useremail', $coursecontext) or $currentuser) { /// Can use the enable/disable email stuff
252 if (!empty($enable)) { /// Recieved a parameter to enable the email address
253 set_field('user', 'emailstop', 0, 'id', $user->id
);
254 $user->emailstop
= 0;
256 if (!empty($disable)) { /// Recieved a parameter to disable the email address
257 set_field('user', 'emailstop', 1, 'id', $user->id
);
258 $user->emailstop
= 1;
262 if (has_capability('moodle/course:useremail', $coursecontext)) { /// Can use the enable/disable email stuff
263 if ($user->emailstop
) {
264 $switchparam = 'enable';
265 $switchtitle = get_string('emaildisable');
266 $switchclick = get_string('emailenableclick');
267 $switchpix = 'emailno.gif';
269 $switchparam = 'disable';
270 $switchtitle = get_string('emailenable');
271 $switchclick = get_string('emaildisableclick');
272 $switchpix = 'email.gif';
274 $emailswitch = " <a title=\"$switchclick\" ".
275 "href=\"view.php?id=$user->id&course=$course->id&$switchparam=1\">".
276 "<img src=\"$CFG->pixpath/t/$switchpix\" alt=\"$switchclick\" /></a>";
278 } else if ($currentuser) { /// Can only re-enable an email this way
279 if ($user->emailstop
) { // Include link that tells how to re-enable their email
280 $switchparam = 'enable';
281 $switchtitle = get_string('emaildisable');
282 $switchclick = get_string('emailenableclick');
284 $emailswitch = " (<a title=\"$switchclick\" ".
285 "href=\"view.php?id=$user->id&course=$course->id&enable=1\">$switchtitle</a>)";
289 print_row(get_string("email").":", obfuscate_mailto($user->email
, '', $user->emailstop
)."$emailswitch");
292 if ($user->url
&& !isset($hiddenfields['webpage'])) {
294 if (strpos($user->url
, '://') === false) {
295 $url = 'http://'. $url;
297 print_row(get_string("webpage") .":", "<a href=\"$url\">$user->url</a>");
300 if ($user->icq
&& !isset($hiddenfields['icqnumber'])) {
301 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>");
304 if ($user->skype
&& !isset($hiddenfields['skypeid'])) {
305 print_row(get_string('skypeid').':','<a href="callto:'.urlencode($user->skype
).'">'.s($user->skype
).
306 ' <img src="http://mystatus.skype.com/smallicon/'.urlencode($user->skype
).'" alt="'.get_string('status').'" '.
309 if ($user->yahoo
&& !isset($hiddenfields['yahooid'])) {
310 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>");
312 if ($user->aim
&& !isset($hiddenfields['aimid'])) {
313 print_row(get_string('aimid').':', '<a href="aim:goim?screenname='.s($user->aim
).'">'.s($user->aim
).'</a>');
315 if ($user->msn
&& !isset($hiddenfields['msnid'])) {
316 print_row(get_string('msnid').':', s($user->msn
));
319 /// Print the Custom User Fields
320 profile_display_fields($user->id
);
323 if ($mycourses = get_my_courses($user->id
, null, null, false, 21)) {
326 foreach ($mycourses as $mycourse) {
327 if ($mycourse->category
) {
328 if ($mycourse->id
!= $course->id
){
330 if ($mycourse->visible
== 0) {
331 // get_my_courses will filter courses $USER cannot see
332 // if we get one with visible 0 it just means it's hidden
333 // ... but not from $USER
334 $class = 'class="dimmed"';
336 $courselisting .= "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&course={$mycourse->id}\" $class >"
337 . format_string($mycourse->fullname
) . "</a>, ";
340 $courselisting .= format_string($mycourse->fullname
) . ", ";
345 $courselisting.= "...";
349 print_row(get_string('courses').':', rtrim($courselisting,', '));
352 if (!isset($hiddenfields['lastaccess'])) {
353 if ($user->lastaccess
) {
354 $datestring = userdate($user->lastaccess
)." (".format_time(time() - $user->lastaccess
).")";
356 $datestring = get_string("never");
358 print_row(get_string("lastaccess").":", $datestring);
362 if ($rolestring = get_user_roles_in_context($id, $coursecontext)) {
363 print_row(get_string('roles').':', format_string($rolestring, false));
367 $isseparategroups = ($course->groupmode
== SEPARATEGROUPS
and $course->groupmodeforce
and
368 !has_capability('moodle/site:accessallgroups', $coursecontext));
369 if (!$isseparategroups){
370 if ($usergroups = groups_get_all_groups($course->id
, $user->id
)){
372 foreach ($usergroups as $group){
373 $groupstr .= ' <a href="'.$CFG->wwwroot
.'/user/index.php?id='.$course->id
.'&group='.$group->id
.'">'.format_string($group->name
).'</a>,';
375 print_row(get_string("group").":", rtrim($groupstr, ', '));
378 /// End of printing groups
380 /// Printing Interests
381 if( !empty($CFG->usetags
)) {
382 if ( $interests = tag_get_tags_csv('user', $user->id
) ) {
383 print_row(get_string('interests') .": ", $interests);
386 /// End of Printing Interests
390 echo "</td></tr></table>";
392 $userauth = get_auth_plugin($user->auth
);
394 $passwordchangeurl = false;
395 if ($currentuser and $userauth->can_change_password() and !isguestuser() and has_capability('moodle/user:changeownpassword', $systemcontext)) {
396 if (!$passwordchangeurl = $userauth->change_password_url()) {
397 if (empty($CFG->loginhttps
)) {
398 $passwordchangeurl = "$CFG->wwwroot/login/change_password.php";
400 $passwordchangeurl = str_replace('http:', 'https:', $CFG->wwwroot
.'/login/change_password.php');
405 // Print other functions
406 echo '<div class="buttons">';
408 if ($passwordchangeurl) {
409 $params = array('id'=>$course->id
);
411 if (!empty($USER->realuser
)) {
412 $passwordchangeurl = ''; // do not use actual change password url - might contain sensitive data
414 $parts = explode('?', $passwordchangeurl);
415 $passwordchangeurl = reset($parts);
416 $after = next($parts);
417 preg_match_all('/([^&=]+)=([^&=]+)/', $after, $matches);
418 if (count($matches)) {
419 foreach($matches[0] as $key=>$match) {
420 $params[$matches[1][$key]] = $matches[2][$key];
424 echo "<form action=\"$passwordchangeurl\" method=\"get\">";
426 foreach($params as $key=>$value) {
427 echo '<input type="hidden" name="'.$key.'" value="'.s($value).'" />';
429 if (!empty($USER->realuser
)) {
430 // changing of password when "Logged in as" is not allowed
431 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" disabled=\"disabled\" />";
433 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
439 if ($course->id
!= SITEID
&& empty($course->metacourse
)) { // Mostly only useful at course level
443 if ($user->id
== $USER->id
) { // Myself
444 $canunenrol = has_capability('moodle/course:view', $coursecontext, NULL) && // Course participant
445 has_capability('moodle/role:unassignself', $coursecontext, NULL, false) && // Can unassign myself
446 get_user_roles($coursecontext, $user->id
, false); // Must have role in course
448 } else if (has_capability('moodle/role:assign', $coursecontext, NULL)) { // I can assign roles
449 if ($roles = get_user_roles($coursecontext, $user->id
, false)) {
451 foreach($roles as $role) {
452 if (!user_can_assign($coursecontext, $role->roleid
)) {
453 $canunenrol = false; // I can not unassign all roles in this course :-(
461 echo '<form action="'.$CFG->wwwroot
.'/course/unenrol.php" method="get">';
463 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
464 echo '<input type="hidden" name="user" value="'.$user->id
.'" />';
465 echo '<input type="submit" value="'.s(get_string('unenrolme', '', $course->shortname
)).'" />';
471 if ($USER->id
!= $user->id
&& empty($USER->realuser
) && has_capability('moodle/user:loginas', $coursecontext) &&
472 ! has_capability('moodle/site:doanything', $coursecontext, $user->id
, false)) {
473 echo '<form action="'.$CFG->wwwroot
.'/course/loginas.php" method="get">';
475 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
476 echo '<input type="hidden" name="user" value="'.$user->id
.'" />';
477 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
478 echo '<input type="submit" value="'.get_string('loginas').'" />';
483 if (!empty($CFG->messaging
) and !isguest() and has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTEM
))) {
484 if (!empty($USER->id
) and ($USER->id
== $user->id
)) {
485 if ($countmessages = count_records('message', 'useridto', $user->id
)) {
486 $messagebuttonname = get_string("messages", "message")."($countmessages)";
488 $messagebuttonname = get_string("messages", "message");
490 echo "<form onclick=\"this.target='message'\" action=\"../message/index.php\" method=\"get\">";
492 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);\" />";
496 echo "<form onclick=\"this.target='message$user->id'\" action=\"../message/discussion.php\" method=\"get\">";
498 echo "<input type=\"hidden\" name=\"id\" value=\"$user->id\" />";
499 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);\" />";
504 // Authorize.net: User Payments
505 if ($course->enrol
== 'authorize' ||
(empty($course->enrol
) && $CFG->enrol
== 'authorize')) {
506 echo "<form action=\"../enrol/authorize/index.php\" method=\"get\">";
508 echo "<input type=\"hidden\" name=\"course\" value=\"$course->id\" />";
509 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
510 echo "<input type=\"submit\" value=\"".get_string('payments')."\" />";
516 if ($CFG->debugdisplay
&& debugging('', DEBUG_DEVELOPER
) && $USER->id
== $user->id
) { // Show user object
518 print_heading('DEBUG MODE: User session variables');
522 print_footer($course);
524 /// Functions ///////
526 function print_row($left, $right) {
527 echo "\n<tr><td class=\"label c0\">$left</td><td class=\"info c1\">$right</td></tr>\n";