Latest tags
[moodle.git] / user / view.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2
3// Display profile for a particular user
4
b0e3a925 5 require_once("../config.php");
b0e3a925 6 require_once("../mod/forum/lib.php");
7 require_once("lib.php");
f9903ed0 8
9 require_variable($id);
10 require_variable($course);
11
12
13 if (! $user = get_record("user", "id", $id) ) {
14 error("No such user in this course");
15 }
16
17 if (! $course = get_record("course", "id", $course) ) {
18 error("No such course id");
19 }
20
21 if ($course->category) {
22 require_login($course->id);
23 }
24
da3a08d7 25 add_to_log($course->id, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
f9903ed0 26
f1603208 27 if ($student = get_record("user_students", "userid", $user->id, "course", $course->id)) {
28 $user->lastaccess = $student->timeaccess;
29 } else if ($teacher = get_record("user_teachers", "userid", $user->id, "course", $course->id)) {
30 $user->lastaccess = $teacher->timeaccess;
31 }
32
fa0626c6 33 $fullname = "$user->firstname $user->lastname";
34 $personalprofile = get_string("personalprofile");
35 $participants = get_string("participants");
36
02e44e7c 37 $loggedinas = "<p class=\"logininfo\">".user_login_string($course, $USER)."</p>";
38
f9903ed0 39 if ($course->category) {
fa0626c6 40 print_header("$personalprofile: $fullname", "$personalprofile: $fullname",
1b6a4b1d 41 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
42 <a href=\"index.php?id=$course->id\">$participants</a> -> $fullname",
02e44e7c 43 "", "", true, "&nbsp;", $loggedinas);
f9903ed0 44 } else {
02e44e7c 45 print_header("$course->fullname: $personalprofile: $fullname", "$course->fullname",
46 "$fullname", "", "", true, "&nbsp;", $loggedinas);
f9903ed0 47 }
48
603d4c72 49 if ($course->category and ! isguest() ) {
b51e9913 50 if (!isstudent($course->id, $user->id) && !isteacher($course->id, $user->id)) {
fa0626c6 51 print_heading(get_string("notenrolled", "", $fullname));
b51e9913 52 print_footer($course);
53 die;
54 }
8a3b358b 55 }
56
bb09fb11 57 if ($user->deleted) {
58 print_heading(get_string("userdeleted"));
59 }
60
1b6a4b1d 61 echo "<table width=\"80%\" align=\"center\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" class=\"userinfobox\">";
62 echo "<tr>";
63 echo "<td width=\"100\" valign=\"top\" class=\"userinfoboxside\">";
15e4b2ec 64 print_user_picture($user->id, $course->id, $user->picture, true, false, false);
1b6a4b1d 65 echo "</td><td width=\"100%\" bgcolor=\"$THEME->cellcontent\" class=\"userinfoboxcontent\">";
f9903ed0 66
67
68 // Print name and edit button across top
69
1b6a4b1d 70 echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td nowrap>";
71 echo "<h3>$fullname</h3>";
72 echo "</td><td align=\"right\">";
61e96406 73 if (empty($USER->id)) {
74 $currentuser = false;
75 } else {
76 $currentuser = ($user->id == $USER->id);
77 }
78 if (($currentuser and !isguest()) or isadmin()) {
1b6a4b1d 79 echo "<p><form action=edit.php method=get>";
80 echo "<input type=hidden name=id value=\"$id\">";
81 echo "<input type=hidden name=course value=\"$course->id\">";
82 echo "<input type=submit value=\"".get_string("editmyprofile")."\">";
83 echo "</form></p>";
f9903ed0 84 }
1b6a4b1d 85 echo "</td></tr></table>";
f9903ed0 86
87
f9903ed0 88 // Print the description
89
90 if ($user->description) {
1b6a4b1d 91 echo "<p>".text_to_html($user->description)."</p><hr>";
f9903ed0 92 }
93
f9903ed0 94 // Print all the little details in a list
95
1b6a4b1d 96 echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\"";
f9903ed0 97
603d4c72 98 if ($user->city or $user->country) {
f1603208 99 $countries = get_list_of_countries();
5833a6c8 100 print_row(get_string("location").":", "$user->city, ".$countries["$user->country"]);
603d4c72 101 }
f9903ed0 102
103 if (isteacher($course->id)) {
104 if ($user->address) {
fa0626c6 105 print_row(get_string("address").":", "$user->address");
f9903ed0 106 }
107 if ($user->phone1) {
fa0626c6 108 print_row(get_string("phone").":", "$user->phone1");
f9903ed0 109 }
110 if ($user->phone2) {
fa0626c6 111 print_row(get_string("phone").":", "$user->phone2");
f9903ed0 112 }
113 }
114
55e078c0 115 if ($user->maildisplay == 1 or ($user->maildisplay == 2 and $course->category) or isteacher($course->id)) {
43373804 116 print_row(get_string("email").":", obfuscate_mailto($user->email));
55e078c0 117 }
f9903ed0 118
119 if ($user->url) {
1b6a4b1d 120 print_row(get_string("webpage").":", "<a href=\"$user->url\">$user->url</a>");
f9903ed0 121 }
122
123 if ($user->icq) {
1b6a4b1d 124 print_row("icq:","<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\" width=18 height=18 border=0></a>");
f9903ed0 125 }
126
d21fef3a 127 if ($user->lastaccess) {
128 $datestring = userdate($user->lastaccess)."&nbsp (".format_time(time() - $user->lastaccess).")";
129 } else {
97ac9019 130 $datestring = get_string("never");
d21fef3a 131 }
fa0626c6 132 print_row(get_string("lastaccess").":", $datestring);
f9903ed0 133
1b6a4b1d 134 echo "</table>";
f9903ed0 135
1b6a4b1d 136 echo "</td></tr></table>";
f9903ed0 137
3086f3f6 138 $internalpassword = false;
ecac660c 139 if (is_internal_auth()) {
3086f3f6 140 $internalpassword = "$CFG->wwwroot/login/change_password.php";
141 }
142
c888501c 143// Print other functions
1b6a4b1d 144 echo "<center><table align=center><tr>";
61e96406 145 if ($currentuser and !isguest()) {
35d01c7f 146 if ($internalpassword) {
1b6a4b1d 147 echo "<td nowrap><p><form action=\"$internalpassword\" method=get>";
148 echo "<input type=hidden name=id value=\"$course->id\">";
149 echo "<input type=submit value=\"".get_string("changepassword")."\">";
150 echo "</form></p></td>";
61a5e1e9 151 } else if (strlen($CFG->changepassword) > 1) {
1b6a4b1d 152 echo "<td nowrap><p><form action=\"$CFG->changepassword\" method=get>";
153 echo "<input type=submit value=\"".get_string("changepassword")."\">";
154 echo "</form></p></td>";
3086f3f6 155 }
e1ac4272 156 }
ebc3bd2b 157 if ($course->category and
5204d831 158 ((isstudent($course->id) and ($user->id == $USER->id) and !isguest() and $CFG->allowunenroll) or
ebc3bd2b 159 (isteacher($course->id) and isstudent($course->id, $user->id))) ) {
1b6a4b1d 160 echo "<td nowrap><p><form action=\"../course/unenrol.php\" method=get>";
161 echo "<input type=hidden name=id value=\"$course->id\">";
162 echo "<input type=hidden name=user value=\"$user->id\">";
163 echo "<input type=submit value=\"".get_string("unenrolme", "", $course->shortname)."\">";
164 echo "</form></p></td>";
18798c6f 165 }
8f850172 166 if (isteacher($course->id) or ($course->showreports and $USER->id == $user->id)) {
1b6a4b1d 167 echo "<td nowrap><p><form action=\"../course/user.php\" method=get>";
168 echo "<input type=hidden name=id value=\"$course->id\">";
169 echo "<input type=hidden name=user value=\"$user->id\">";
170 echo "<input type=submit value=\"".get_string("activityreport")."\">";
171 echo "</form></p></td>";
8f850172 172 }
6a7585f2 173 if (isteacher($course->id) and ($USER->id != $user->id) and !iscreator($user->id)) {
8f850172 174 echo "<td nowrap><p><form action=\"../course/loginas.php\" method=get>";
175 echo "<input type=hidden name=id value=\"$course->id\">";
176 echo "<input type=hidden name=user value=\"$user->id\">";
177 echo "<input type=submit value=\"".get_string("loginas")."\">";
178 echo "</form></p></td>";
803b2c76 179 }
1b6a4b1d 180 echo "</tr></table></center>\n";
c888501c 181
11b0c469 182 forum_print_user_discussions($course->id, $user->id);
51feb9d5 183
f9903ed0 184 print_footer($course);
185
186/// Functions ///////
187
188function print_row($left, $right) {
1b6a4b1d 189 echo "<tr><td nowrap align=right><p>$left</td><td align=left><p>$right</p></td></tr>";
f9903ed0 190}
191
192?>