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 $navlinks[] = array('name' => $strparticipants, 'link' => "index.php?id=$course->id", 'type' => 'misc');
66 /// If the user being shown is not ourselves, then make sure we are allowed to see them!
69 if ($course->id
== SITEID
) { // Reduce possibility of "browsing" userbase at site level
70 if ($CFG->forceloginforprofiles
and !isteacherinanycourse()
71 and !isteacherinanycourse($user->id
)
72 and !has_capability('moodle/user:viewdetails', $usercontext)) { // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
74 $navlinks[] = array('name' => $struser, 'link' => null, 'type' => 'misc');
75 $navigation = build_navigation($navlinks);
77 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, " ", navmenu($course));
78 print_heading(get_string('usernotavailable', 'error'));
79 print_footer($course);
82 } else { // Normal course
84 if (!has_capability('moodle/user:viewdetails', $coursecontext) &&
85 !has_capability('moodle/user:viewdetails', $usercontext)) {
86 print_error('cannotviewprofile');
89 if (!has_capability('moodle/course:view', $coursecontext, $user->id
, false)) {
90 if (has_capability('moodle/course:view', $coursecontext)) {
91 $navlinks[] = array('name' => $fullname, 'link' => null, 'type' => 'misc');
92 $navigation = build_navigation($navlinks);
93 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, " ", navmenu($course));
94 print_heading(get_string('notenrolled', '', $fullname));
96 $navlinks[] = array('name' => $struser, 'link' => null, 'type' => 'misc');
97 $navigation = build_navigation($navlinks);
98 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, " ", navmenu($course));
99 print_heading(get_string('notenrolledprofile'));
101 print_continue($_SERVER['HTTP_REFERER']);
102 print_footer($course);
108 // If groups are in use, make sure we can see that group
109 if (groups_get_course_groupmode($course) == SEPARATEGROUPS
and !has_capability('moodle/site:accessallgroups', $coursecontext)) {
112 ///this is changed because of mygroupid
113 $gtrue = (bool)groups_get_all_groups($course->id
, $user->id
);
115 $navigation = build_navigation($navlinks);
116 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, " ", navmenu($course));
117 error(get_string("groupnotamember"), "../course/view.php?id=$course->id");
123 /// We've established they can see the user's name at least, so what about the rest?
125 $navlinks[] = array('name' => $fullname, 'link' => null, 'type' => 'misc');
127 $navigation = build_navigation($navlinks);
129 print_header("$course->fullname: $strpersonalprofile: $fullname", $course->fullname
,
130 $navigation, "", "", true, " ", navmenu($course));
133 if (($course->id
!= SITEID
) and ! isguest() ) { // Need to have access to a course to see that info
134 if (!has_capability('moodle/course:view', $coursecontext, $user->id
)) {
135 print_heading(get_string('notenrolled', '', $fullname));
136 print_footer($course);
141 if ($user->deleted
) {
142 print_heading(get_string('userdeleted'));
145 /// OK, security out the way, now we are showing the user
147 add_to_log($course->id
, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
149 if ($course->id
!= SITEID
) {
150 if ($lastaccess = get_record('user_lastaccess', 'userid', $user->id
, 'courseid', $course->id
)) {
151 $user->lastaccess
= $lastaccess->timeaccess
;
156 /// Get the hidden field list
157 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
158 $hiddenfields = array();
160 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields
));
163 /// Print tabs at top
164 /// This same call is made in:
169 $currenttab = 'profile';
173 if (is_mnet_remote_user($user)) {
179 a.name as application,
182 {$CFG->prefix}mnet_host h,
183 {$CFG->prefix}mnet_application a
185 h.id = '{$user->mnethostid}' AND
186 h.applicationid = a.id
191 $remotehost = get_record_sql($sql);
193 echo '<p class="errorboxcontent">'.get_string('remote'.$remotehost->application
.'user')." <br />\n";
194 if ($USER->id
== $user->id
) {
195 if ($remotehost->application
=='moodle') {
196 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/user/edit.php\">{$remotehost->name}</a> ".get_string('editremoteprofile')." </p>\n";
198 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a> ".get_string('gotoyourserver')." </p>\n";
201 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a></p>\n";
205 echo '<table width="80%" class="userinfobox" summary="">';
207 echo '<td class="side">';
208 print_user_picture($user->id
, $course->id
, $user->picture
, true, false, false);
209 echo '</td><td class="content">';
211 // Print the description
213 if ($user->description
&& !isset($hiddenfields['description'])) {
214 echo format_text($user->description
, FORMAT_MOODLE
)."<hr />";
217 // Print all the little details in a list
219 echo '<table class="list">';
221 if (($user->city
or $user->country
) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) {
223 if ($user->city
&& !isset($hiddenfields['city'])) {
224 $location .= $user->city
;
226 if (!empty($countries[$user->country
]) && !isset($hiddenfields['country'])) {
227 if ($user->city
&& !isset($hiddenfields['country'])) {
230 $countries = get_list_of_countries();
231 $location .= $countries[$user->country
];
233 print_row(get_string("city").":", $location);
236 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
237 if ($user->address
) {
238 print_row(get_string("address").":", "$user->address");
241 print_row(get_string("phone").":", "$user->phone1");
244 print_row(get_string("phone").":", "$user->phone2");
248 if ($user->maildisplay
== 1 or
249 ($user->maildisplay
== 2 and ($course->id
!= SITEID
) and !isguest()) or
250 has_capability('moodle/course:useremail', $coursecontext)) {
254 if (has_capability('moodle/course:useremail', $coursecontext) or $currentuser) { /// Can use the enable/disable email stuff
255 if (!empty($enable)) { /// Recieved a parameter to enable the email address
256 set_field('user', 'emailstop', 0, 'id', $user->id
);
257 $user->emailstop
= 0;
259 if (!empty($disable)) { /// Recieved a parameter to disable the email address
260 set_field('user', 'emailstop', 1, 'id', $user->id
);
261 $user->emailstop
= 1;
265 if (has_capability('moodle/course:useremail', $coursecontext)) { /// Can use the enable/disable email stuff
266 if ($user->emailstop
) {
267 $switchparam = 'enable';
268 $switchtitle = get_string('emaildisable');
269 $switchclick = get_string('emailenableclick');
270 $switchpix = 'emailno.gif';
272 $switchparam = 'disable';
273 $switchtitle = get_string('emailenable');
274 $switchclick = get_string('emaildisableclick');
275 $switchpix = 'email.gif';
277 $emailswitch = " <a title=\"$switchclick\" ".
278 "href=\"view.php?id=$user->id&course=$course->id&$switchparam=1\">".
279 "<img src=\"$CFG->pixpath/t/$switchpix\" alt=\"$switchclick\" /></a>";
281 } else if ($currentuser) { /// Can only re-enable an email this way
282 if ($user->emailstop
) { // Include link that tells how to re-enable their email
283 $switchparam = 'enable';
284 $switchtitle = get_string('emaildisable');
285 $switchclick = get_string('emailenableclick');
287 $emailswitch = " (<a title=\"$switchclick\" ".
288 "href=\"view.php?id=$user->id&course=$course->id&enable=1\">$switchtitle</a>)";
292 print_row(get_string("email").":", obfuscate_mailto($user->email
, '', $user->emailstop
)."$emailswitch");
295 if ($user->url
&& !isset($hiddenfields['webpage'])) {
296 print_row(get_string("webpage").":", "<a href=\"$user->url\">$user->url</a>");
299 if ($user->icq
&& !isset($hiddenfields['icqnumber'])) {
300 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>");
303 if ($user->skype
&& !isset($hiddenfields['skypeid'])) {
304 print_row(get_string('skypeid').':','<a href="callto:'.urlencode($user->skype
).'">'.s($user->skype
).
305 ' <img src="http://mystatus.skype.com/smallicon/'.urlencode($user->skype
).'" alt="'.get_string('status').'" '.
308 if ($user->yahoo
&& !isset($hiddenfields['yahooid'])) {
309 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>");
311 if ($user->aim
&& !isset($hiddenfields['aimid'])) {
312 print_row(get_string('aimid').':', '<a href="aim:goim?screenname='.s($user->aim
).'">'.s($user->aim
).'</a>');
314 if ($user->msn
&& !isset($hiddenfields['msnid'])) {
315 print_row(get_string('msnid').':', s($user->msn
));
318 /// Print the Custom User Fields
319 profile_display_fields($user->id
);
322 if ($mycourses = get_my_courses($user->id
, null, null, false, 21)) {
325 foreach ($mycourses as $mycourse) {
326 if ($mycourse->category
) {
327 if ($mycourse->id
!= $course->id
){
329 if ($mycourse->visible
== 0) {
330 // get_my_courses will filter courses $USER cannot see
331 // if we get one with visible 0 it just means it's hidden
332 // ... but not from $USER
333 $class = 'class="dimmed"';
335 $courselisting .= "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&course={$mycourse->id}\" $class >"
336 . format_string($mycourse->fullname
) . "</a>, ";
339 $courselisting .= format_string($mycourse->fullname
) . ", ";
344 $courselisting.= "...";
348 print_row(get_string('courses').':', rtrim($courselisting,', '));
351 if (!isset($hiddenfields['lastaccess'])) {
352 if ($user->lastaccess
) {
353 $datestring = userdate($user->lastaccess
)." (".format_time(time() - $user->lastaccess
).")";
355 $datestring = get_string("never");
357 print_row(get_string("lastaccess").":", $datestring);
361 if ($rolestring = get_user_roles_in_context($id, $coursecontext->id
)) {
362 print_row(get_string('roles').':', format_string($rolestring, false));
366 $isseparategroups = ($course->groupmode
== SEPARATEGROUPS
and $course->groupmodeforce
and
367 !has_capability('moodle/site:accessallgroups', $coursecontext));
368 if (!$isseparategroups){
369 if ($usergroups = groups_get_all_groups($course->id
, $user->id
)){
371 foreach ($usergroups as $group){
372 $groupstr .= ' <a href="'.$CFG->wwwroot
.'/user/index.php?id='.$course->id
.'&group='.$group->id
.'">'.format_string($group->name
).'</a>,';
374 print_row(get_string("group").":", rtrim($groupstr, ', '));
377 /// End of printing groups
379 /// Printing Interests
380 if( !empty($CFG->usetags
)) {
381 $interests = get_item_tags('user', $user->id
);
383 $instereststr = tag_links_csv($interests);
386 print_row(get_string('interests').": ",rtrim($instereststr));
389 /// End of Printing Interests
393 echo "</td></tr></table>";
395 $userauth = get_auth_plugin($user->auth
);
397 $passwordchangeurl = false;
398 if ($currentuser and $userauth->can_change_password() and !isguestuser() and has_capability('moodle/user:changeownpassword', $systemcontext)) {
399 if (!$passwordchangeurl = $userauth->change_password_url()) {
400 if (empty($CFG->loginhttps
)) {
401 $passwordchangeurl = "$CFG->wwwroot/login/change_password.php";
403 $passwordchangeurl = str_replace('http:', 'https:', $CFG->wwwroot
.'/login/change_password.php');
408 // Print other functions
409 echo '<div class="buttons">';
411 if ($passwordchangeurl) {
412 $params = array('id'=>$course->id
);
414 if (!empty($USER->realuser
)) {
415 $passwordchangeurl = ''; // do not use actual change password url - might contain sensitive data
417 $parts = explode('?', $passwordchangeurl);
418 $passwordchangeurl = reset($parts);
419 $after = next($parts);
420 preg_match_all('/([^&=]+)=([^&=]+)/', $after, $matches);
421 if (count($matches)) {
422 foreach($matches[0] as $key=>$match) {
423 $params[$matches[1][$key]] = $matches[2][$key];
427 echo "<form action=\"$passwordchangeurl\" method=\"get\">";
429 foreach($params as $key=>$value) {
430 echo '<input type="hidden" name="'.$key.'" value="'.s($value).'" />';
432 if (!empty($USER->realuser
)) {
433 // changing of password when "Logged in as" is not allowed
434 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" disabled=\"disabled\" />";
436 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
442 if ($course->id
!= SITEID
&& empty($course->metacourse
)) { // Mostly only useful at course level
444 if (($user->id
== $USER->id
&& // Myself
445 has_capability('moodle/course:view', $coursecontext, NULL) && // Course participant
446 has_capability('moodle/role:unassignself', $coursecontext, NULL, false)) // Can unassign myself
448 (has_capability('moodle/role:assign', $coursecontext, NULL) && // I can assign roles
449 get_user_roles($coursecontext, $user->id
)) ) { // This user has roles
451 echo '<form action="../course/unenrol.php" method="get">';
453 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
454 echo '<input type="hidden" name="user" value="'.$user->id
.'" />';
455 echo '<input type="submit" value="'.get_string('unenrolme', '', $course->shortname
).'" />';
461 if ($USER->id
!= $user->id
&& empty($USER->realuser
) && has_capability('moodle/user:loginas', $coursecontext) &&
462 ! has_capability('moodle/site:doanything', $coursecontext, $user->id
, false)) {
463 echo '<form action="'.$CFG->wwwroot
.'/course/loginas.php" method="get">';
465 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
466 echo '<input type="hidden" name="user" value="'.$user->id
.'" />';
467 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
468 echo '<input type="submit" value="'.get_string('loginas').'" />';
473 if (!empty($CFG->messaging
) and !isguest()) {
474 if (!empty($USER->id
) and ($USER->id
== $user->id
)) {
475 if ($countmessages = count_records('message', 'useridto', $user->id
)) {
476 $messagebuttonname = get_string("messages", "message")."($countmessages)";
478 $messagebuttonname = get_string("messages", "message");
480 echo "<form onclick=\"this.target='message'\" action=\"../message/index.php\" method=\"get\">";
482 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);\" />";
486 echo "<form onclick=\"this.target='message$user->id'\" action=\"../message/discussion.php\" method=\"get\">";
488 echo "<input type=\"hidden\" name=\"id\" value=\"$user->id\" />";
489 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);\" />";
494 // Authorize.net: User Payments
495 if ($course->enrol
== 'authorize' ||
(empty($course->enrol
) && $CFG->enrol
== 'authorize')) {
496 echo "<form action=\"../enrol/authorize/index.php\" method=\"get\">";
498 echo "<input type=\"hidden\" name=\"course\" value=\"$course->id\" />";
499 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
500 echo "<input type=\"submit\" value=\"".get_string('payments')."\" />";
506 if ($CFG->debugdisplay
&& debugging('', DEBUG_DEVELOPER
) && $USER->id
== $user->id
) { // Show user object
508 print_heading('DEBUG MODE: User session variables');
512 print_footer($course);
514 /// Functions ///////
516 function print_row($left, $right) {
517 echo "\n<tr><td class=\"label c0\">$left</td><td class=\"info c1\">$right</td></tr>\n";