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 // make sure user can view this student's profile
51 if ($USER->id
!= $user->id
52 && !has_capability('moodle/user:viewdetails', $coursecontext)
53 && !has_capability('moodle/user:viewdetails', $usercontext)) {
54 print_error('cannotviewprofile');
57 if (!empty($CFG->forceloginforprofiles
)) {
60 redirect("$CFG->wwwroot/login/index.php");
64 $strpersonalprofile = get_string('personalprofile');
65 $strparticipants = get_string("participants");
66 $struser = get_string("user");
68 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $coursecontext));
71 $navlinks[] = array('name' => $strparticipants, 'link' => "index.php?id=$course->id", 'type' => 'misc');
73 /// If the user being shown is not ourselves, then make sure we are allowed to see them!
76 if ($course->id
== SITEID
) { // Reduce possibility of "browsing" userbase at site level
77 if ($CFG->forceloginforprofiles
and !isteacherinanycourse()
78 and !isteacherinanycourse($user->id
)
79 and !has_capability('moodle/user:viewdetails', $usercontext)) { // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
81 $navlinks[] = array('name' => $struser, 'link' => null, 'type' => 'misc');
82 $navigation = build_navigation($navlinks);
84 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, " ", navmenu($course));
85 print_heading(get_string('usernotavailable', 'error'));
86 print_footer($course);
89 } else { // Normal course
90 if (!has_capability('moodle/course:view', $coursecontext, $user->id
, false)) {
91 if (has_capability('moodle/course:view', $coursecontext)) {
92 $navlinks[] = array('name' => $fullname, 'link' => null, 'type' => 'misc');
93 $navigation = build_navigation($navlinks);
94 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, " ", navmenu($course));
95 print_heading(get_string('notenrolled', '', $fullname));
97 $navlinks[] = array('name' => $struser, 'link' => null, 'type' => 'misc');
98 $navigation = build_navigation($navlinks);
99 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, " ", navmenu($course));
100 print_heading(get_string('notenrolledprofile'));
102 print_continue($_SERVER['HTTP_REFERER']);
103 print_footer($course);
109 // If groups are in use, make sure we can see that group
110 if (groupmode($course) == SEPARATEGROUPS
and !has_capability('moodle/site:accessallgroups', $coursecontext)) {
113 ///this is changed because of mygroupid
114 $gtrue = (bool)groups_get_all_groups($course->id
, $user->id
);
116 $navigation = build_navigation($navlinks);
117 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, " ", navmenu($course));
118 error(get_string("groupnotamember"), "../course/view.php?id=$course->id");
124 /// We've established they can see the user's name at least, so what about the rest?
126 $navlinks[] = array('name' => $fullname, 'link' => null, 'type' => 'misc');
128 $navigation = build_navigation($navlinks);
130 print_header("$course->fullname: $strpersonalprofile: $fullname", $course->fullname
,
131 $navigation, "", "", true, " ", navmenu($course));
134 if (($course->id
!= SITEID
) and ! isguest() ) { // Need to have access to a course to see that info
135 if (!has_capability('moodle/course:view', $coursecontext, $user->id
)) {
136 print_heading(get_string('notenrolled', '', $fullname));
137 print_footer($course);
142 if ($user->deleted
) {
143 print_heading(get_string('userdeleted'));
146 /// OK, security out the way, now we are showing the user
148 add_to_log($course->id
, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
150 if ($course->id
!= SITEID
) {
151 if ($lastaccess = get_record('user_lastaccess', 'userid', $user->id
, 'courseid', $course->id
)) {
152 $user->lastaccess
= $lastaccess->timeaccess
;
157 /// Get the hidden field list
158 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
159 $hiddenfields = array();
161 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields
));
164 /// Print tabs at top
165 /// This same call is made in:
170 $currenttab = 'profile';
174 if (is_mnet_remote_user($user)) {
180 a.name as application,
183 {$CFG->prefix}mnet_host h,
184 {$CFG->prefix}mnet_application a
186 h.id = '{$user->mnethostid}' AND
187 h.applicationid = a.id
192 $remotehost = get_record_sql($sql);
194 echo '<p class="errorboxcontent">'.get_string('remote'.$remotehost->application
.'user')." <br />\n";
195 if ($USER->id
== $user->id
) {
196 if ($remotehost->application
=='moodle') {
197 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/user/edit.php\">{$remotehost->name}</a> ".get_string('editremoteprofile')." </p>\n";
199 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a> ".get_string('gotoyourserver')." </p>\n";
202 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a></p>\n";
206 echo '<table width="80%" class="userinfobox" summary="">';
208 echo '<td class="side">';
209 print_user_picture($user->id
, $course->id
, $user->picture
, true, false, false);
210 echo '</td><td class="content">';
212 // Print the description
214 if ($user->description
&& !isset($hiddenfields['description'])) {
215 echo format_text($user->description
, FORMAT_MOODLE
)."<hr />";
218 // Print all the little details in a list
220 echo '<table class="list">';
222 if (($user->city
or $user->country
) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) {
224 if ($user->city
&& !isset($hiddenfields['city'])) {
225 $location .= $user->city
;
227 if (!empty($countries[$user->country
]) && !isset($hiddenfields['country'])) {
228 if ($user->city
&& !isset($hiddenfields['country'])) {
231 $countries = get_list_of_countries();
232 $location .= $countries[$user->country
];
234 print_row(get_string("city").":", $location);
237 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
238 if ($user->address
) {
239 print_row(get_string("address").":", "$user->address");
242 print_row(get_string("phone").":", "$user->phone1");
245 print_row(get_string("phone").":", "$user->phone2");
249 if ($user->maildisplay
== 1 or
250 ($user->maildisplay
== 2 and ($course->id
!= SITEID
) and !isguest()) or
251 has_capability('moodle/course:useremail', $coursecontext)) {
255 if (has_capability('moodle/course:useremail', $coursecontext) or $currentuser) { /// Can use the enable/disable email stuff
256 if (!empty($enable)) { /// Recieved a parameter to enable the email address
257 set_field('user', 'emailstop', 0, 'id', $user->id
);
258 $user->emailstop
= 0;
260 if (!empty($disable)) { /// Recieved a parameter to disable the email address
261 set_field('user', 'emailstop', 1, 'id', $user->id
);
262 $user->emailstop
= 1;
266 if (has_capability('moodle/course:useremail', $coursecontext)) { /// Can use the enable/disable email stuff
267 if ($user->emailstop
) {
268 $switchparam = 'enable';
269 $switchtitle = get_string('emaildisable');
270 $switchclick = get_string('emailenableclick');
271 $switchpix = 'emailno.gif';
273 $switchparam = 'disable';
274 $switchtitle = get_string('emailenable');
275 $switchclick = get_string('emaildisableclick');
276 $switchpix = 'email.gif';
278 $emailswitch = " <a title=\"$switchclick\" ".
279 "href=\"view.php?id=$user->id&course=$course->id&$switchparam=1\">".
280 "<img src=\"$CFG->pixpath/t/$switchpix\" alt=\"$switchclick\" /></a>";
282 } else if ($currentuser) { /// Can only re-enable an email this way
283 if ($user->emailstop
) { // Include link that tells how to re-enable their email
284 $switchparam = 'enable';
285 $switchtitle = get_string('emaildisable');
286 $switchclick = get_string('emailenableclick');
288 $emailswitch = " (<a title=\"$switchclick\" ".
289 "href=\"view.php?id=$user->id&course=$course->id&enable=1\">$switchtitle</a>)";
293 print_row(get_string("email").":", obfuscate_mailto($user->email
, '', $user->emailstop
)."$emailswitch");
296 if ($user->url
&& !isset($hiddenfields['webpage'])) {
297 print_row(get_string("webpage").":", "<a href=\"$user->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->visible
and $mycourse->category
) {
328 if ($mycourse->id
!= $course->id
){
329 $courselisting .= "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$mycourse->id\">"
330 . format_string($mycourse->fullname
) . "</a>, ";
333 $courselisting .= format_string($mycourse->fullname
) . ", ";
338 $courselisting.= "...";
342 print_row(get_string('courses').':', rtrim($courselisting,', '));
345 if (!isset($hiddenfields['lastaccess'])) {
346 if ($user->lastaccess
) {
347 $datestring = userdate($user->lastaccess
)." (".format_time(time() - $user->lastaccess
).")";
349 $datestring = get_string("never");
351 print_row(get_string("lastaccess").":", $datestring);
355 if ($rolestring = get_user_roles_in_context($id, $coursecontext->id
)) {
356 print_row(get_string('roles').':', format_string($rolestring, false));
360 $isseparategroups = ($course->groupmode
== SEPARATEGROUPS
and $course->groupmodeforce
and
361 !has_capability('moodle/site:accessallgroups', $coursecontext));
362 if (!$isseparategroups){
363 if ($usergroups = groups_get_all_groups($course->id
, $user->id
)){
365 foreach ($usergroups as $group){
366 $groupstr .= ' <a href="'.$CFG->wwwroot
.'/user/index.php?id='.$course->id
.'&group='.$group->id
.'">'.$group->name
.'</a>,';
368 print_row(get_string("group").":", rtrim($groupstr, ', '));
371 /// End of printing groups
373 /// Printing Interests
374 if( !empty($CFG->usetags
)) {
375 $interests = get_item_tags('user', $user->id
);
377 $instereststr = tag_links_csv($interests);
380 print_row(get_string('interests').": ",rtrim($instereststr));
383 /// End of Printing Interests
387 echo "</td></tr></table>";
389 $userauth = get_auth_plugin($user->auth
);
391 $passwordchangeurl = false;
392 if ($currentuser and $userauth->can_change_password() and !isguestuser() and has_capability('moodle/user:changeownpassword', $systemcontext)) {
393 if (!$passwordchangeurl = $userauth->change_password_url()) {
394 if (empty($CFG->loginhttps
)) {
395 $passwordchangeurl = "$CFG->wwwroot/login/change_password.php";
397 $passwordchangeurl = str_replace('http:', 'https:', $CFG->wwwroot
.'/login/change_password.php');
402 // Print other functions
403 echo '<div class="buttons">';
405 if ($passwordchangeurl) {
406 $params = array('id'=>$course->id
);
408 if (!empty($USER->realuser
)) {
409 $passwordchangeurl = ''; // do not use actual change password url - might contain sensitive data
411 $parts = explode('?', $passwordchangeurl);
412 $passwordchangeurl = reset($parts);
413 $after = next($parts);
414 preg_match_all('/([^&=]+)=([^&=]+)/', $after, $matches);
415 if (count($matches)) {
416 foreach($matches[0] as $key=>$match) {
417 $params[$matches[1][$key]] = $matches[2][$key];
421 echo "<form action=\"$passwordchangeurl\" method=\"get\">";
423 foreach($params as $key=>$value) {
424 echo '<input type="hidden" name="'.$key.'" value="'.s($value).'" />';
426 if (!empty($USER->realuser
)) {
427 // changing of password when "Logged in as" is not allowed
428 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" disabled=\"disabled\" />";
430 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
436 if ($course->id
!= SITEID
&& empty($course->metacourse
)) { // Mostly only useful at course level
438 if (($user->id
== $USER->id
&& // Myself
439 has_capability('moodle/course:view', $coursecontext, NULL) && // Course participant
440 has_capability('moodle/role:unassignself', $coursecontext, NULL, false)) // Can unassign myself
442 (has_capability('moodle/role:assign', $coursecontext, NULL) && // I can assign roles
443 get_user_roles($coursecontext, $user->id
)) ) { // This user has roles
445 echo '<form action="../course/unenrol.php" method="get">';
447 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
448 echo '<input type="hidden" name="user" value="'.$user->id
.'" />';
449 echo '<input type="submit" value="'.get_string('unenrolme', '', $course->shortname
).'" />';
455 if ($USER->id
!= $user->id
&& empty($USER->realuser
) && has_capability('moodle/user:loginas', $coursecontext) &&
456 ! has_capability('moodle/site:doanything', $coursecontext, $user->id
, false)) {
457 echo '<form action="'.$CFG->wwwroot
.'/course/loginas.php" method="get">';
459 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
460 echo '<input type="hidden" name="user" value="'.$user->id
.'" />';
461 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
462 echo '<input type="submit" value="'.get_string('loginas').'" />';
467 if (!empty($CFG->messaging
) and !isguest()) {
468 if (!empty($USER->id
) and ($USER->id
== $user->id
)) {
469 if ($countmessages = count_records('message', 'useridto', $user->id
)) {
470 $messagebuttonname = get_string("messages", "message")."($countmessages)";
472 $messagebuttonname = get_string("messages", "message");
474 echo "<form onclick=\"this.target='message'\" action=\"../message/index.php\" method=\"get\">";
476 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);\" />";
480 echo "<form onclick=\"this.target='message$user->id'\" action=\"../message/discussion.php\" method=\"get\">";
482 echo "<input type=\"hidden\" name=\"id\" value=\"$user->id\" />";
483 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);\" />";
488 // Authorize.net: User Payments
489 if ($course->enrol
== 'authorize' ||
(empty($course->enrol
) && $CFG->enrol
== 'authorize')) {
490 echo "<form action=\"../enrol/authorize/index.php\" method=\"get\">";
492 echo "<input type=\"hidden\" name=\"course\" value=\"$course->id\" />";
493 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
494 echo "<input type=\"submit\" value=\"".get_string('payments')."\" />";
500 if ($CFG->debugdisplay
&& debugging('', DEBUG_DEVELOPER
) && $USER->id
== $user->id
) { // Show user object
502 print_heading('DEBUG MODE: User session variables');
506 print_footer($course);
508 /// Functions ///////
510 function print_row($left, $right) {
511 echo "\n<tr><td class=\"label c0\">$left</td><td class=\"info c1\">$right</td></tr>\n";