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 error('You can not view the profile of this user');
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));
70 /// If the user being shown is not ourselves, then make sure we are allowed to see them!
73 if ($course->id
== SITEID
) { // Reduce possibility of "browsing" userbase at site level
74 if ($CFG->forceloginforprofiles
and !isteacherinanycourse() and !isteacherinanycourse($user->id
) and !has_capability('moodle/user:viewdetails', $usercontext)) { // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
75 print_header("$strpersonalprofile: ", "$strpersonalprofile: ",
76 "<a href=\"index.php?id=$course->id\">$strparticipants</a> -> $struser",
77 "", "", true, " ", navmenu($course));
78 print_heading(get_string('usernotavailable', 'error'));
79 print_footer($course);
82 } else { // Normal course
83 if (!has_capability('moodle/course:view', $coursecontext, $user->id
, false)) {
84 if (has_capability('moodle/course:view', $coursecontext)) {
85 print_header("$strpersonalprofile: ", "$strpersonalprofile: ",
86 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
87 <a href=\"index.php?id=$course->id\">$strparticipants</a> -> $fullname",
88 "", "", true, " ", navmenu($course));
89 print_heading(get_string('notenrolled', '', $fullname));
91 print_header("$strpersonalprofile: ", "$strpersonalprofile: ",
92 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
93 <a href=\"index.php?id=$course->id\">$strparticipants</a> -> $struser",
94 "", "", true, " ", navmenu($course));
95 print_heading(get_string('notenrolledprofile'));
97 print_continue($_SERVER['HTTP_REFERER']);
98 print_footer($course);
104 // If groups are in use, make sure we can see that group
105 if (groupmode($course) == SEPARATEGROUPS
and !has_capability('moodle/site:accessallgroups', $coursecontext)) {
108 ///this is changed because of mygroupid
109 $gtrue = (bool)groups_get_groups_for_user($user->id
, $course->id
);
110 /*TODO: $gtrue = false;
111 if ($mygroups = mygroupid($course->id)){
112 foreach ($mygroups as $group){
113 if (ismember($group, $user->id)){
119 print_header("$strpersonalprofile: ", "$strpersonalprofile: ",
120 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
121 <a href=\"index.php?id=$course->id\">$strparticipants</a>",
122 "", "", true, " ", navmenu($course));
123 error(get_string("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 if ($course->id
!= SITEID
) {
132 print_header("$strpersonalprofile: $fullname", "$strpersonalprofile: $fullname",
133 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
134 <a href=\"index.php?id=$course->id\">$strparticipants</a> -> $fullname",
135 "", "", true, " ", navmenu($course));
137 print_header("$course->fullname: $strpersonalprofile: $fullname", $course->fullname
,
138 "$fullname", "", "", true, " ", navmenu($course));
142 if (($course->id
!= SITEID
) and ! isguest() ) { // Need to have access to a course to see that info
143 if (!has_capability('moodle/course:view', $coursecontext, $user->id
)) {
144 print_heading(get_string('notenrolled', '', $fullname));
145 print_footer($course);
150 if ($user->deleted
) {
151 print_heading(get_string('userdeleted'));
154 /// OK, security out the way, now we are showing the user
156 add_to_log($course->id
, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
158 if ($course->id
!= SITEID
) {
159 if ($lastaccess = get_record('user_lastaccess', 'userid', $user->id
, 'courseid', $course->id
)) {
160 $user->lastaccess
= $lastaccess->timeaccess
;
165 /// Get the hidden field list
166 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
167 $hiddenfields = array();
169 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields
));
172 /// Print tabs at top
173 /// This same call is made in:
178 $currenttab = 'profile';
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('remote'.$remotehost->application
.'user')." <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->id
, $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 echo format_text($user->description
, FORMAT_MOODLE
)."<hr />";
226 // Print all the little details in a list
228 echo '<table class="list">';
230 if (($user->city
or $user->country
) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) {
232 if ($user->city
&& !isset($hiddenfields['city'])) {
233 $location .= $user->city
;
235 if (!empty($countries[$user->country
]) && !isset($hiddenfields['country'])) {
236 if ($user->city
&& !isset($hiddenfields['country'])) {
239 $countries = get_list_of_countries();
240 $location .= $countries[$user->country
];
242 print_row(get_string("city").":", $location);
245 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
246 if ($user->address
) {
247 print_row(get_string("address").":", "$user->address");
250 print_row(get_string("phone").":", "$user->phone1");
253 print_row(get_string("phone").":", "$user->phone2");
257 if ($user->maildisplay
== 1 or
258 ($user->maildisplay
== 2 and ($course->id
!= SITEID
) and !isguest()) or
259 has_capability('moodle/course:useremail', $coursecontext)) {
263 if (has_capability('moodle/course:useremail', $coursecontext) or $currentuser) { /// Can use the enable/disable email stuff
264 if (!empty($enable)) { /// Recieved a parameter to enable the email address
265 set_field('user', 'emailstop', 0, 'id', $user->id
);
266 $user->emailstop
= 0;
268 if (!empty($disable)) { /// Recieved a parameter to disable the email address
269 set_field('user', 'emailstop', 1, 'id', $user->id
);
270 $user->emailstop
= 1;
274 if (has_capability('moodle/course:useremail', $coursecontext)) { /// Can use the enable/disable email stuff
275 if ($user->emailstop
) {
276 $switchparam = 'enable';
277 $switchtitle = get_string('emaildisable');
278 $switchclick = get_string('emailenableclick');
279 $switchpix = 'emailno.gif';
281 $switchparam = 'disable';
282 $switchtitle = get_string('emailenable');
283 $switchclick = get_string('emaildisableclick');
284 $switchpix = 'email.gif';
286 $emailswitch = " <a title=\"$switchclick\" ".
287 "href=\"view.php?id=$user->id&course=$course->id&$switchparam=1\">".
288 "<img src=\"$CFG->pixpath/t/$switchpix\" alt=\"$switchclick\" /></a>";
290 } else if ($currentuser) { /// Can only re-enable an email this way
291 if ($user->emailstop
) { // Include link that tells how to re-enable their email
292 $switchparam = 'enable';
293 $switchtitle = get_string('emaildisable');
294 $switchclick = get_string('emailenableclick');
296 $emailswitch = " (<a title=\"$switchclick\" ".
297 "href=\"view.php?id=$user->id&course=$course->id&enable=1\">$switchtitle</a>)";
301 print_row(get_string("email").":", obfuscate_mailto($user->email
, '', $user->emailstop
)."$emailswitch");
304 if ($user->url
&& !isset($hiddenfields['webpage'])) {
305 print_row(get_string("webpage").":", "<a href=\"$user->url\">$user->url</a>");
308 if ($user->icq
&& !isset($hiddenfields['icqnumber'])) {
309 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>");
312 if ($user->skype
&& !isset($hiddenfields['skypeid'])) {
313 print_row(get_string('skypeid').':','<a href="callto:'.urlencode($user->skype
).'">'.s($user->skype
).
314 ' <img src="http://mystatus.skype.com/smallicon/'.urlencode($user->skype
).'" alt="'.get_string('status').'" '.
317 if ($user->yahoo
&& !isset($hiddenfields['yahooid'])) {
318 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>");
320 if ($user->aim
&& !isset($hiddenfields['aimid'])) {
321 print_row(get_string('aimid').':', '<a href="aim:goim?screenname='.s($user->aim
).'">'.s($user->aim
).'</a>');
323 if ($user->msn
&& !isset($hiddenfields['msnid'])) {
324 print_row(get_string('msnid').':', s($user->msn
));
327 /// Print the Custom User Fields
328 profile_display_fields($user->id
);
331 if ($mycourses = get_my_courses($user->id
, null, null, false, 21)) {
334 foreach ($mycourses as $mycourse) {
335 if ($mycourse->visible
and $mycourse->category
) {
336 if ($mycourse->id
!= $course->id
){
337 $courselisting .= "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$mycourse->id\">"
338 . format_string($mycourse->fullname
) . "</a>, ";
341 $courselisting .= format_string($mycourse->fullname
) . ", ";
346 $courselisting.= "...";
350 print_row(get_string('courses').':', rtrim($courselisting,', '));
353 if (!isset($hiddenfields['lastaccess'])) {
354 if ($user->lastaccess
) {
355 $datestring = userdate($user->lastaccess
)." (".format_time(time() - $user->lastaccess
).")";
357 $datestring = get_string("never");
359 print_row(get_string("lastaccess").":", $datestring);
363 if ($rolestring = get_user_roles_in_context($id, $coursecontext->id
)) {
364 print_row(get_string('roles').':', format_string($rolestring, false));
368 $isseparategroups = ($course->groupmode
== SEPARATEGROUPS
and $course->groupmodeforce
and
369 !has_capability('moodle/site:accessallgroups', $coursecontext));
370 if (!$isseparategroups){
371 if ($usergroups = user_group($course->id
, $user->id
)){
373 foreach ($usergroups as $group){
374 $groupstr .= ' <a href="'.$CFG->wwwroot
.'/user/index.php?id='.$course->id
.'&group='.$group->id
.'">'.$group->name
.'</a>,';
376 print_row(get_string("group").":", rtrim($groupstr, ', '));
379 /// End of printing groups
381 /// Printing Interests
382 if( !empty($CFG->usetags
)) {
383 $interests = get_item_tags('user', $user->id
);
385 $instereststr = tag_links_csv($interests);
388 print_row(get_string('interests').": ",rtrim($instereststr));
391 /// End of Printing Interests
395 echo "</td></tr></table>";
397 $userauth = get_auth_plugin($user->auth
);
399 $passwordchangeurl = false;
400 if ($currentuser and $userauth->can_change_password() and !isguestuser() and has_capability('moodle/user:changeownpassword', $systemcontext)) {
401 if (!$passwordchangeurl = $userauth->change_password_url()) {
402 if (empty($CFG->loginhttps
)) {
403 $passwordchangeurl = "$CFG->wwwroot/login/change_password.php";
405 $passwordchangeurl = str_replace('http:', 'https:', $CFG->wwwroot
.'/login/change_password.php');
410 // Print other functions
411 echo '<div class="buttons">';
413 if ($passwordchangeurl) {
414 $params = array('id'=>$course->id
);
416 if (!empty($USER->realuser
)) {
417 $passwordchangeurl = ''; // do not use actual change password url - might contain sensitive data
419 $parts = explode('?', $passwordchangeurl);
420 $passwordchangeurl = reset($parts);
421 $after = next($parts);
422 preg_match_all('/([^&=]+)=([^&=]+)/', $after, $matches);
423 if (count($matches)) {
424 foreach($matches[0] as $key=>$match) {
425 $params[$matches[1][$key]] = $matches[2][$key];
429 echo "<form action=\"$passwordchangeurl\" method=\"get\">";
431 foreach($params as $key=>$value) {
432 echo '<input type="hidden" name="'.$key.'" value="'.s($value).'" />';
434 if (!empty($USER->realuser
)) {
435 // changing of password when "Logged in as" is not allowed
436 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" disabled=\"disabled\" />";
438 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
444 if ($course->id
!= SITEID
&& empty($course->metacourse
)) { // Mostly only useful at course level
446 if (($user->id
== $USER->id
&& // Myself
447 has_capability('moodle/course:view', $coursecontext, NULL) && // Course participant
448 has_capability('moodle/role:unassignself', $coursecontext, NULL, false)) // Can unassign myself
450 (has_capability('moodle/role:assign', $coursecontext, NULL) && // I can assign roles
451 get_user_roles($coursecontext, $user->id
)) ) { // This user has roles
453 echo '<form action="../course/unenrol.php" method="get">';
455 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
456 echo '<input type="hidden" name="user" value="'.$user->id
.'" />';
457 echo '<input type="submit" value="'.get_string('unenrolme', '', $course->shortname
).'" />';
463 if ($USER->id
!= $user->id
&& empty($USER->realuser
) && has_capability('moodle/user:loginas', $coursecontext) &&
464 ! has_capability('moodle/site:doanything', $coursecontext, $user->id
, false)) {
465 echo '<form action="'.$CFG->wwwroot
.'/course/loginas.php" method="get">';
467 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
468 echo '<input type="hidden" name="user" value="'.$user->id
.'" />';
469 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
470 echo '<input type="submit" value="'.get_string('loginas').'" />';
475 if (!empty($CFG->messaging
) and !isguest()) {
476 if (!empty($USER->id
) and ($USER->id
== $user->id
)) {
477 if ($countmessages = count_records('message', 'useridto', $user->id
)) {
478 $messagebuttonname = get_string("messages", "message")."($countmessages)";
480 $messagebuttonname = get_string("messages", "message");
482 echo "<form onclick=\"this.target='message'\" action=\"../message/index.php\" method=\"get\">";
484 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);\" />";
488 echo "<form onclick=\"this.target='message$user->id'\" action=\"../message/discussion.php\" method=\"get\">";
490 echo "<input type=\"hidden\" name=\"id\" value=\"$user->id\" />";
491 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);\" />";
496 // Authorize.net: User Payments
497 if ($course->enrol
== 'authorize' ||
(empty($course->enrol
) && $CFG->enrol
== 'authorize')) {
498 echo "<form action=\"../enrol/authorize/index.php\" method=\"get\">";
500 echo "<input type=\"hidden\" name=\"course\" value=\"$course->id\" />";
501 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
502 echo "<input type=\"submit\" value=\"".get_string('payments')."\" />";
508 if ($CFG->debugdisplay
&& debugging('', DEBUG_DEVELOPER
) && $USER->id
== $user->id
) { // Show user object
510 print_heading('DEBUG MODE: User session variables');
514 print_footer($course);
516 /// Functions ///////
518 function print_row($left, $right) {
519 echo "\n<tr><td class=\"label c0\">$left</td><td class=\"info c1\">$right</td></tr>\n";