"MDL-8642, setting of auto scrolling"
[moodle-linuxchix.git] / user / view.php
blobab052933579502f9edceeb95aeddabd8c76a3349
1 <?PHP // $Id$
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
15 require_login();
16 $id = $USER->id;
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)) {
30 $currentuser = false;
31 } else {
32 $currentuser = ($user->id == $USER->id);
35 if ($course->id == SITEID) {
36 $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
37 } else {
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)) {
51 require_login();
52 if (isguest()) {
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));
63 $navlinks = array();
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!
70 if (!$currentuser) {
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, "&nbsp;", navmenu($course));
80 print_heading(get_string('usernotavailable', 'error'));
81 print_footer($course);
82 exit;
84 } else { // Normal course
85 // check capabilities
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, "&nbsp;", navmenu($course));
96 print_heading(get_string('notenrolled', '', $fullname));
97 } else {
98 $navlinks[] = array('name' => $struser, 'link' => null, 'type' => 'misc');
99 $navigation = build_navigation($navlinks);
100 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, "&nbsp;", navmenu($course));
101 print_heading(get_string('notenrolledprofile'));
103 print_continue($_SERVER['HTTP_REFERER']);
104 print_footer($course);
105 exit;
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)) {
112 require_login();
114 ///this is changed because of mygroupid
115 $gtrue = (bool)groups_get_all_groups($course->id, $user->id);
116 if (!$gtrue) {
117 $navigation = build_navigation($navlinks);
118 print_header("$strpersonalprofile: ", "$strpersonalprofile: ", $navigation, "", "", true, "&nbsp;", 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, "&nbsp;", 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);
139 die;
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();
162 } else {
163 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
166 /// Print tabs at top
167 /// This same call is made in:
168 /// /user/view.php
169 /// /user/edit.php
170 /// /course/user.php
172 $currenttab = 'profile';
173 $showroles = 1;
174 include('tabs.php');
176 if (is_mnet_remote_user($user)) {
177 $sql = "
178 SELECT DISTINCT
179 h.id,
180 h.name,
181 h.wwwroot,
182 a.name as application,
183 a.display_name
184 FROM
185 {$CFG->prefix}mnet_host h,
186 {$CFG->prefix}mnet_application a
187 WHERE
188 h.id = '{$user->mnethostid}' AND
189 h.applicationid = a.id
190 ORDER BY
191 a.display_name,
192 h.name";
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";
200 } else {
201 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a> ".get_string('gotoyourserver')." </p>\n";
203 } else {
204 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a></p>\n";
208 echo '<table width="80%" class="userinfobox" summary="">';
209 echo '<tr>';
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");
237 if ($user->phone1) {
238 print_row(get_string("phone").":", "$user->phone1");
240 if ($user->phone2) {
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)) {
249 $emailswitch = '';
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';
268 } else {
269 $switchparam = 'disable';
270 $switchtitle = get_string('emailenable');
271 $switchclick = get_string('emaildisableclick');
272 $switchpix = 'email.gif';
274 $emailswitch = "&nbsp;<a title=\"$switchclick\" ".
275 "href=\"view.php?id=$user->id&amp;course=$course->id&amp;$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 = "&nbsp;(<a title=\"$switchclick\" ".
285 "href=\"view.php?id=$user->id&amp;course=$course->id&amp;enable=1\">$switchtitle</a>)";
289 print_row(get_string("email").":", obfuscate_mailto($user->email, '', $user->emailstop)."$emailswitch");
292 if ($user->url && !isset($hiddenfields['webpage'])) {
293 $url = $user->url;
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&amp;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').'" '.
307 ' /></a>');
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).'&amp;.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)) {
324 $shown=0;
325 $courselisting = '';
326 foreach ($mycourses as $mycourse) {
327 if ($mycourse->category) {
328 if ($mycourse->id != $course->id){
329 $class = '';
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}&amp;course={$mycourse->id}\" $class >"
337 . format_string($mycourse->fullname) . "</a>, ";
339 else {
340 $courselisting .= format_string($mycourse->fullname) . ", ";
343 $shown++;
344 if($shown==20) {
345 $courselisting.= "...";
346 break;
349 print_row(get_string('courses').':', rtrim($courselisting,', '));
352 if (!isset($hiddenfields['lastaccess'])) {
353 if ($user->lastaccess) {
354 $datestring = userdate($user->lastaccess)."&nbsp; (".format_time(time() - $user->lastaccess).")";
355 } else {
356 $datestring = get_string("never");
358 print_row(get_string("lastaccess").":", $datestring);
360 /// printing roles
362 if ($rolestring = get_user_roles_in_context($id, $coursecontext)) {
363 print_row(get_string('roles').':', format_string($rolestring, false));
366 /// Printing groups
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)){
371 $groupstr = '';
372 foreach ($usergroups as $group){
373 $groupstr .= ' <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;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
388 echo "</table>";
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";
399 } else {
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
413 } else {
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\">";
425 echo "<div>";
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\" />";
432 } else {
433 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
435 echo "</div>";
436 echo "</form>";
439 if ($course->id != SITEID && empty($course->metacourse)) { // Mostly only useful at course level
441 $canunenrol = false;
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)) {
450 $canunenrol = true;
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 :-(
454 break;
460 if ($canunenrol) {
461 echo '<form action="'.$CFG->wwwroot.'/course/unenrol.php" method="get">';
462 echo '<div>';
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)).'" />';
466 echo '</div>';
467 echo '</form>';
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">';
474 echo '<div>';
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').'" />';
479 echo '</div>';
480 echo '</form>';
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)";
487 } else {
488 $messagebuttonname = get_string("messages", "message");
490 echo "<form onclick=\"this.target='message'\" action=\"../message/index.php\" method=\"get\">";
491 echo "<div>";
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);\" />";
493 echo "</div>";
494 echo "</form>";
495 } else {
496 echo "<form onclick=\"this.target='message$user->id'\" action=\"../message/discussion.php\" method=\"get\">";
497 echo "<div>";
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);\" />";
500 echo "</div>";
501 echo "</form>";
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\">";
507 echo "<div>";
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')."\" />";
511 echo "</div>";
512 echo "</form>";
514 echo "</div>\n";
516 if ($CFG->debugdisplay && debugging('', DEBUG_DEVELOPER) && $USER->id == $user->id) { // Show user object
517 echo '<hr />';
518 print_heading('DEBUG MODE: User session variables');
519 print_object($USER);
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";