3 // Display profile for a particular user
5 require_once("../config.php");
6 $id = optional_param('id', 0, PARAM_INT
); // user id
7 $course = optional_param('course', SITEID
, PARAM_INT
); // course id (defaults to Site)
8 $enable = optional_param('enable', ''); // enable email
9 $disable = optional_param('disable', ''); // disable email
11 if (empty($id)) { // See your own profile by default
16 if (! $user = get_record("user", "id", $id) ) {
17 error("No such user in this course");
20 if (! $course = get_record("course", "id", $course) ) {
21 error("No such course id");
24 /// Make sure the current user is allowed to see this user
26 if (empty($USER->id
)) {
29 $currentuser = ($user->id
== $USER->id
);
32 if ($course->id
== SITEID
) {
33 $coursecontext = get_context_instance(CONTEXT_SYSTEM
, SITEID
); // SYSTEM context
35 $coursecontext = get_context_instance(CONTEXT_COURSE
, $course->id
); // Course context
37 $usercontext = get_context_instance(CONTEXT_USER
, $user->id
); // User context
39 if (!empty($CFG->forcelogin
) ||
$course->id
!= SITEID
) {
40 // do not force parents to enrol
41 if (!get_record('role_assignments', 'userid', $USER->id
, 'contextid', $usercontext->id
)) {
42 require_login($course->id
);
46 // make sure user can view this student's profile
47 if ($USER->id
!= $user->id
48 && !has_capability('moodle/user:viewdetails', $coursecontext)
49 && !has_capability('moodle/user:viewdetails', $usercontext)) {
50 error('You can not view the profile of this user');
53 if (!empty($CFG->forceloginforprofiles
)) {
56 redirect("$CFG->wwwroot/login/index.php");
60 $strpersonalprofile = get_string('personalprofile');
61 $strparticipants = get_string("participants");
62 $struser = get_string("user");
64 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $coursecontext));
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() 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)
71 print_header("$strpersonalprofile: ", "$strpersonalprofile: ",
72 "<a href=\"index.php?id=$course->id\">$strparticipants</a> -> $struser",
73 "", "", true, " ", navmenu($course));
74 print_heading(get_string('usernotavailable', 'error'));
75 print_footer($course);
78 } else { // Normal course
79 if (!has_capability('moodle/course:view', $coursecontext, $user->id
, false)) {
80 if (has_capability('moodle/course:view', $coursecontext)) {
81 print_header("$strpersonalprofile: ", "$strpersonalprofile: ",
82 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
83 <a href=\"index.php?id=$course->id\">$strparticipants</a> -> $fullname",
84 "", "", true, " ", navmenu($course));
85 print_heading(get_string('notenrolled', '', $fullname));
87 print_header("$strpersonalprofile: ", "$strpersonalprofile: ",
88 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
89 <a href=\"index.php?id=$course->id\">$strparticipants</a> -> $struser",
90 "", "", true, " ", navmenu($course));
91 print_heading(get_string('notenrolledprofile'));
93 print_continue($_SERVER['HTTP_REFERER']);
94 print_footer($course);
100 // If groups are in use, make sure we can see that group
101 if (groupmode($course) == SEPARATEGROUPS
and !has_capability('moodle/site:accessallgroups', $coursecontext)) {
104 ///this is changed because of mygroupid
105 $gtrue = (bool)groups_get_groups_for_user($user->id
, $course->id
);
106 /*TODO: $gtrue = false;
107 if ($mygroups = mygroupid($course->id)){
108 foreach ($mygroups as $group){
109 if (ismember($group, $user->id)){
115 print_header("$strpersonalprofile: ", "$strpersonalprofile: ",
116 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
117 <a href=\"index.php?id=$course->id\">$strparticipants</a>",
118 "", "", true, " ", navmenu($course));
119 error(get_string("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 if ($course->id
!= SITEID
) {
128 print_header("$strpersonalprofile: $fullname", "$strpersonalprofile: $fullname",
129 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
130 <a href=\"index.php?id=$course->id\">$strparticipants</a> -> $fullname",
131 "", "", true, " ", navmenu($course));
133 print_header("$course->fullname: $strpersonalprofile: $fullname", $course->fullname
,
134 "$fullname", "", "", true, " ", navmenu($course));
138 if (($course->id
!= SITEID
) and ! isguest() ) { // Need to have access to a course to see that info
139 if (!has_capability('moodle/course:view', $coursecontext, $user->id
)) {
140 print_heading(get_string('notenrolled', '', $fullname));
141 print_footer($course);
146 if ($user->deleted
) {
147 print_heading(get_string('userdeleted'));
150 /// OK, security out the way, now we are showing the user
152 add_to_log($course->id
, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
154 if ($course->id
!= SITEID
) {
155 if ($lastaccess = get_record('user_lastaccess', 'userid', $user->id
, 'courseid', $course->id
)) {
156 $user->lastaccess
= $lastaccess->timeaccess
;
161 /// Get the hidden field list
162 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
163 $hiddenfields = array();
165 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields
));
168 /// Print tabs at top
169 /// This same call is made in:
174 $currenttab = 'profile';
178 if (is_mnet_remote_user($user)) {
179 echo "<p class=\"errorboxcontent\">This profile is for a remote user from another Moodle system. <br />\n";
180 $remotehost = get_record('mnet_host', 'id', $user->mnethostid
);
181 echo "Remote Moodle: <a href=\"{$remotehost->wwwroot}/user/edit.php\">{$remotehost->name}</a> (click here to edit your profile on the remote server) </p>\n";
184 echo '<table width="80%" class="userinfobox" summary="">';
186 echo '<td class="side">';
187 print_user_picture($user->id
, $course->id
, $user->picture
, true, false, false);
188 echo '</td><td class="content">';
190 // Print the description
192 if ($user->description
&& !isset($hiddenfields['description'])) {
193 echo format_text($user->description
, FORMAT_MOODLE
)."<hr />";
196 // Print all the little details in a list
198 echo '<table class="list">';
200 if (($user->city
or $user->country
) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) {
202 if ($user->city
&& !isset($hiddenfields['city'])) {
203 $location .= $user->city
;
205 if (!empty($countries[$user->country
]) && !isset($hiddenfields['country'])) {
206 if ($user->city
&& !isset($hiddenfields['country'])) {
209 $countries = get_list_of_countries();
210 $location .= $countries[$user->country
];
212 print_row(get_string("location").":", $location);
215 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
216 if ($user->address
) {
217 print_row(get_string("address").":", "$user->address");
220 print_row(get_string("phone").":", "$user->phone1");
223 print_row(get_string("phone").":", "$user->phone2");
227 if ($user->maildisplay
== 1 or
228 ($user->maildisplay
== 2 and ($course->id
!= SITEID
) and !isguest()) or
229 has_capability('moodle/course:useremail', $coursecontext)) {
233 if (has_capability('moodle/course:useremail', $coursecontext) or $currentuser) { /// Can use the enable/disable email stuff
234 if (!empty($enable)) { /// Recieved a parameter to enable the email address
235 set_field('user', 'emailstop', 0, 'id', $user->id
);
236 $user->emailstop
= 0;
238 if (!empty($disable)) { /// Recieved a parameter to disable the email address
239 set_field('user', 'emailstop', 1, 'id', $user->id
);
240 $user->emailstop
= 1;
244 if (has_capability('moodle/course:useremail', $coursecontext)) { /// Can use the enable/disable email stuff
245 if ($user->emailstop
) {
246 $switchparam = 'enable';
247 $switchtitle = get_string('emaildisable');
248 $switchclick = get_string('emailenableclick');
249 $switchpix = 'emailno.gif';
251 $switchparam = 'disable';
252 $switchtitle = get_string('emailenable');
253 $switchclick = get_string('emaildisableclick');
254 $switchpix = 'email.gif';
256 $emailswitch = " <a title=\"$switchclick\" ".
257 "href=\"view.php?id=$user->id&course=$course->id&$switchparam=1\">".
258 "<img src=\"$CFG->pixpath/t/$switchpix\" alt=\"$switchclick\" /></a>";
260 } else if ($currentuser) { /// Can only re-enable an email this way
261 if ($user->emailstop
) { // Include link that tells how to re-enable their email
262 $switchparam = 'enable';
263 $switchtitle = get_string('emaildisable');
264 $switchclick = get_string('emailenableclick');
266 $emailswitch = " (<a title=\"$switchclick\" ".
267 "href=\"view.php?id=$user->id&course=$course->id&enable=1\">$switchtitle</a>)";
271 print_row(get_string("email").":", obfuscate_mailto($user->email
, '', $user->emailstop
)."$emailswitch");
274 if ($user->url
&& !isset($hiddenfields['webpage'])) {
275 print_row(get_string("webpage").":", "<a href=\"$user->url\">$user->url</a>");
278 if ($user->icq
&& !isset($hiddenfields['icqnumber'])) {
279 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>");
282 if ($user->skype
&& !isset($hiddenfields['skypeid'])) {
283 print_row(get_string('skypeid').':','<a href="callto:'.urlencode($user->skype
).'">'.s($user->skype
).
284 ' <img src="http://mystatus.skype.com/smallicon/'.urlencode($user->skype
).'" alt="'.get_string('status').'" '.
287 if ($user->yahoo
&& !isset($hiddenfields['yahooid'])) {
288 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>");
290 if ($user->aim
&& !isset($hiddenfields['aimid'])) {
291 print_row(get_string('aimid').':', '<a href="aim:goim?screenname='.s($user->aim
).'">'.s($user->aim
).'</a>');
293 if ($user->msn
&& !isset($hiddenfields['msnid'])) {
294 print_row(get_string('msnid').':', s($user->msn
));
297 if ($mycourses = get_my_courses($user->id
,'visible DESC,sortorder ASC', '*', false, 21)) {
300 foreach ($mycourses as $mycourse) {
301 if ($mycourse->visible
and $mycourse->category
) {
302 if ($mycourse->id
!= $course->id
){
303 $courselisting .= "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$mycourse->id\">"
304 . format_string($mycourse->fullname
) . "</a>, ";
307 $courselisting .= format_string($mycourse->fullname
) . ", ";
312 $courselisting.= "...";
316 print_row(get_string('courses').':', rtrim($courselisting,', '));
319 if (!isset($hiddenfields['lastaccess'])) {
320 if ($user->lastaccess
) {
321 $datestring = userdate($user->lastaccess
)." (".format_time(time() - $user->lastaccess
).")";
323 $datestring = get_string("never");
325 print_row(get_string("lastaccess").":", $datestring);
329 if ($rolestring = get_user_roles_in_context($id, $coursecontext->id
)) {
330 print_row(get_string('roles').':', $rolestring);
334 $isseparategroups = ($course->groupmode
== SEPARATEGROUPS
and $course->groupmodeforce
and
335 !has_capability('moodle/site:accessallgroups', $coursecontext));
336 if (!$isseparategroups){
337 if ($usergroups = user_group($course->id
, $user->id
)){
339 foreach ($usergroups as $group){
340 $groupstr .= ' <a href="'.$CFG->wwwroot
.'/user/index.php?id='.$course->id
.'&group='.$group->id
.'">'.$group->name
.'</a>,';
342 print_row(get_string("group").":", rtrim($groupstr, ', '));
345 /// End of printing groups
349 echo "</td></tr></table>";
351 $userauth = get_auth_plugin($user->auth
);
353 $passwordchangeurl = false;
354 if ($userauth->can_change_password()) {
355 if ($userauth->change_password_url()) {
356 $passwordchangeurl = $userauth->change_password_url();
358 if (empty($CFG->loginhttps
)) {
359 $passwordchangeurl = "$CFG->wwwroot/login/change_password.php";
361 $passwordchangeurl = str_replace('http:', 'https:', $CFG->wwwroot
.'/login/change_password.php');
366 // Print other functions
367 echo '<div class="buttons">';
369 if ($currentuser and $passwordchangeurl and !isguest()) { //TODO: add proper capability for password changing
370 echo "<form action=\"$passwordchangeurl\" method=\"get\">";
372 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
373 if (!empty($USER->realuser
)) {
374 // changing of password when "Logged in as" is not allowed
375 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" disabled=\"disabled\" />";
377 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
383 if ($course->id
!= SITEID
&& empty($course->metacourse
)) { // Mostly only useful at course level
385 if (($user->id
== $USER->id
&& // Myself
386 has_capability('moodle/course:view', $coursecontext, NULL) && // Course participant
387 has_capability('moodle/role:unassignself', $coursecontext, NULL, false)) // Can unassign myself
389 (has_capability('moodle/role:assign', $coursecontext, NULL) && // I can assign roles
390 get_user_roles($coursecontext, $user->id
)) ) { // This user has roles
392 echo '<form action="../course/unenrol.php" method="get">';
394 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
395 echo '<input type="hidden" name="user" value="'.$user->id
.'" />';
396 echo '<input type="submit" value="'.get_string('unenrolme', '', $course->shortname
).'" />';
402 if ($USER->id
!= $user->id
&& empty($USER->realuser
) && has_capability('moodle/user:loginas', $coursecontext) &&
403 ! has_capability('moodle/site:doanything', $coursecontext, $user->id
, false)) {
404 echo '<form action="'.$CFG->wwwroot
.'/course/loginas.php" method="get">';
406 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
407 echo '<input type="hidden" name="user" value="'.$user->id
.'" />';
408 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
409 echo '<input type="submit" value="'.get_string('loginas').'" />';
414 if (!empty($CFG->messaging
) and !isguest()) {
415 if (!empty($USER->id
) and ($USER->id
== $user->id
)) {
416 if ($countmessages = count_records('message', 'useridto', $user->id
)) {
417 $messagebuttonname = get_string("messages", "message")."($countmessages)";
419 $messagebuttonname = get_string("messages", "message");
421 echo "<form onclick=\"this.target='message'\" action=\"../message/index.php\" method=\"get\">";
423 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);\" />";
427 echo "<form onclick=\"this.target='message$user->id'\" action=\"../message/discussion.php\" method=\"get\">";
429 echo "<input type=\"hidden\" name=\"id\" value=\"$user->id\" />";
430 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);\" />";
435 // Authorize.net: User Payments
436 if ($course->enrol
== 'authorize' ||
(empty($course->enrol
) && $CFG->enrol
== 'authorize')) {
437 echo "<form action=\"../enrol/authorize/index.php\" method=\"get\">";
439 echo "<input type=\"hidden\" name=\"course\" value=\"$course->id\" />";
440 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
441 echo "<input type=\"submit\" value=\"".get_string('payments')."\" />";
447 if ($CFG->debugdisplay
&& debugging('', DEBUG_DEVELOPER
) && $USER->id
== $user->id
) { // Show user object
449 print_heading('DEBUG MODE: User session variables');
453 print_footer($course);
455 /// Functions ///////
457 function print_row($left, $right) {
458 echo "\n<tr><td class=\"label c0\">$left</td><td class=\"info c1\">$right</td></tr>\n";