Finally fixed those annoying 'loginas' links on the main user listing
[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");
f9903ed0 7
8 require_variable($id);
9 require_variable($course);
cadb96f2 10 optional_variable($enable, "");
11 optional_variable($disable, "");
f9903ed0 12
13
14 if (! $user = get_record("user", "id", $id) ) {
15 error("No such user in this course");
16 }
17
18 if (! $course = get_record("course", "id", $course) ) {
19 error("No such course id");
20 }
21
22 if ($course->category) {
23 require_login($course->id);
24 }
25
da3a08d7 26 add_to_log($course->id, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
f9903ed0 27
f1603208 28 if ($student = get_record("user_students", "userid", $user->id, "course", $course->id)) {
29 $user->lastaccess = $student->timeaccess;
30 } else if ($teacher = get_record("user_teachers", "userid", $user->id, "course", $course->id)) {
31 $user->lastaccess = $teacher->timeaccess;
32 }
33
5fde0ca6 34 $fullname = fullname($user, isteacher($course->id));
fa0626c6 35 $personalprofile = get_string("personalprofile");
36 $participants = get_string("participants");
37
dd780a3b 38 $groupmode = groupmode($course);
39
40 if ($groupmode and !isteacheredit($course->id)) { // Groups must be kept separate
41 if ($groupmode == SEPARATEGROUPS) {
42 require_login();
43
44 if (!ismember($USER->groupmember[$course->id], $user->id)) {
45 print_header("$personalprofile: ", "$personalprofile: ",
46 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
47 <a href=\"index.php?id=$course->id\">$participants</a>",
48 "", "", true, "&nbsp;", navmenu($course));
49 print_heading("Sorry, you can't see this user because you are not in his group");
50 print_footer();
51 die;
52 }
53
54 }
55 }
56
f9903ed0 57 if ($course->category) {
fa0626c6 58 print_header("$personalprofile: $fullname", "$personalprofile: $fullname",
1b6a4b1d 59 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
60 <a href=\"index.php?id=$course->id\">$participants</a> -> $fullname",
951b22a8 61 "", "", true, "&nbsp;", navmenu($course));
f9903ed0 62 } else {
02e44e7c 63 print_header("$course->fullname: $personalprofile: $fullname", "$course->fullname",
951b22a8 64 "$fullname", "", "", true, "&nbsp;", navmenu($course));
f9903ed0 65 }
66
603d4c72 67 if ($course->category and ! isguest() ) {
b51e9913 68 if (!isstudent($course->id, $user->id) && !isteacher($course->id, $user->id)) {
fa0626c6 69 print_heading(get_string("notenrolled", "", $fullname));
b51e9913 70 print_footer($course);
71 die;
72 }
8a3b358b 73 }
74
bb09fb11 75 if ($user->deleted) {
76 print_heading(get_string("userdeleted"));
77 }
78
1b6a4b1d 79 echo "<table width=\"80%\" align=\"center\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" class=\"userinfobox\">";
80 echo "<tr>";
81 echo "<td width=\"100\" valign=\"top\" class=\"userinfoboxside\">";
15e4b2ec 82 print_user_picture($user->id, $course->id, $user->picture, true, false, false);
1b6a4b1d 83 echo "</td><td width=\"100%\" bgcolor=\"$THEME->cellcontent\" class=\"userinfoboxcontent\">";
f9903ed0 84
85
86 // Print name and edit button across top
87
1b6a4b1d 88 echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td nowrap>";
89 echo "<h3>$fullname</h3>";
90 echo "</td><td align=\"right\">";
61e96406 91 if (empty($USER->id)) {
92 $currentuser = false;
93 } else {
94 $currentuser = ($user->id == $USER->id);
95 }
96 if (($currentuser and !isguest()) or isadmin()) {
1b6a4b1d 97 echo "<p><form action=edit.php method=get>";
98 echo "<input type=hidden name=id value=\"$id\">";
99 echo "<input type=hidden name=course value=\"$course->id\">";
100 echo "<input type=submit value=\"".get_string("editmyprofile")."\">";
101 echo "</form></p>";
f9903ed0 102 }
1b6a4b1d 103 echo "</td></tr></table>";
f9903ed0 104
105
f9903ed0 106 // Print the description
107
108 if ($user->description) {
d7df380b 109 echo "<p>".format_text(clean_text($user->description, FORMAT_MOODLE))."</p><hr>";
f9903ed0 110 }
111
f9903ed0 112 // Print all the little details in a list
113
1b6a4b1d 114 echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\"";
f9903ed0 115
603d4c72 116 if ($user->city or $user->country) {
f1603208 117 $countries = get_list_of_countries();
5833a6c8 118 print_row(get_string("location").":", "$user->city, ".$countries["$user->country"]);
603d4c72 119 }
f9903ed0 120
121 if (isteacher($course->id)) {
122 if ($user->address) {
fa0626c6 123 print_row(get_string("address").":", "$user->address");
f9903ed0 124 }
125 if ($user->phone1) {
fa0626c6 126 print_row(get_string("phone").":", "$user->phone1");
f9903ed0 127 }
128 if ($user->phone2) {
fa0626c6 129 print_row(get_string("phone").":", "$user->phone2");
f9903ed0 130 }
131 }
132
55e078c0 133 if ($user->maildisplay == 1 or ($user->maildisplay == 2 and $course->category) or isteacher($course->id)) {
cadb96f2 134
135 if (isteacheredit($course->id) or $currentuser) { /// Can use the enable/disable email stuff
136 if (!empty($_GET['enable'])) { /// Recieved a paramter to enable the email address
137 set_field('user', 'emailstop', 0, 'id', $user->id);
138 $user->emailstop = 0;
139 }
140 if (!empty($_GET['disable'])) { /// Recieved a paramter to disable the email address
141 set_field('user', 'emailstop', 1, 'id', $user->id);
142 $user->emailstop = 1;
143 }
144 if ($user->emailstop) {
145 $switchparam = 'enable';
146 $switchtitle = get_string('emaildisable');
147 $switchpix = 'show.gif';
148 } else {
149 $switchparam = 'disable';
150 $switchtitle = get_string('emailenable');
151 $switchpix = 'hide.gif';
152 }
153 $emailswitch = "&nbsp<a title=\"$switchtitle\" ".
154 "href=\"view.php?id=$user->id&course=$course->id&$switchparam=$user->id\">".
155 "<img border=\"0\" width=11 height=11 src=\"$CFG->pixpath/t/$switchpix\"></a>";
156 } else {
157 $emailswitch = '';
158 }
159
160 print_row(get_string("email").":", obfuscate_mailto($user->email, '', $user->emailstop)."$emailswitch");
55e078c0 161 }
f9903ed0 162
163 if ($user->url) {
1b6a4b1d 164 print_row(get_string("webpage").":", "<a href=\"$user->url\">$user->url</a>");
f9903ed0 165 }
166
167 if ($user->icq) {
088cbaab 168 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 169 }
170
9c72928d 171 if (isteacher($course->id)) {
172 if ($mycourses = get_my_courses($user->id)) {
173 $courselisting = '';
174 foreach ($mycourses as $mycourse) {
175 if ($mycourse->visible) {
176 $courselisting .= "<a href=\"$CFG->wwwroot/course/view.php?id=$mycourse->id\">$mycourse->fullname</a>, ";
177 }
178 }
179 print_row(get_string('courses').':', rtrim($courselisting,', '));
180 }
181 }
182
d21fef3a 183 if ($user->lastaccess) {
184 $datestring = userdate($user->lastaccess)."&nbsp (".format_time(time() - $user->lastaccess).")";
185 } else {
97ac9019 186 $datestring = get_string("never");
d21fef3a 187 }
fa0626c6 188 print_row(get_string("lastaccess").":", $datestring);
f9903ed0 189
1b6a4b1d 190 echo "</table>";
f9903ed0 191
1b6a4b1d 192 echo "</td></tr></table>";
f9903ed0 193
3086f3f6 194 $internalpassword = false;
ecac660c 195 if (is_internal_auth()) {
3086f3f6 196 $internalpassword = "$CFG->wwwroot/login/change_password.php";
197 }
198
c888501c 199// Print other functions
1b6a4b1d 200 echo "<center><table align=center><tr>";
61e96406 201 if ($currentuser and !isguest()) {
35d01c7f 202 if ($internalpassword) {
1b6a4b1d 203 echo "<td nowrap><p><form action=\"$internalpassword\" method=get>";
204 echo "<input type=hidden name=id value=\"$course->id\">";
205 echo "<input type=submit value=\"".get_string("changepassword")."\">";
206 echo "</form></p></td>";
61a5e1e9 207 } else if (strlen($CFG->changepassword) > 1) {
1b6a4b1d 208 echo "<td nowrap><p><form action=\"$CFG->changepassword\" method=get>";
209 echo "<input type=submit value=\"".get_string("changepassword")."\">";
210 echo "</form></p></td>";
3086f3f6 211 }
e1ac4272 212 }
ebc3bd2b 213 if ($course->category and
5204d831 214 ((isstudent($course->id) and ($user->id == $USER->id) and !isguest() and $CFG->allowunenroll) or
ebc3bd2b 215 (isteacher($course->id) and isstudent($course->id, $user->id))) ) {
1b6a4b1d 216 echo "<td nowrap><p><form action=\"../course/unenrol.php\" method=get>";
217 echo "<input type=hidden name=id value=\"$course->id\">";
218 echo "<input type=hidden name=user value=\"$user->id\">";
219 echo "<input type=submit value=\"".get_string("unenrolme", "", $course->shortname)."\">";
220 echo "</form></p></td>";
18798c6f 221 }
8f850172 222 if (isteacher($course->id) or ($course->showreports and $USER->id == $user->id)) {
1b6a4b1d 223 echo "<td nowrap><p><form action=\"../course/user.php\" method=get>";
224 echo "<input type=hidden name=id value=\"$course->id\">";
225 echo "<input type=hidden name=user value=\"$user->id\">";
226 echo "<input type=submit value=\"".get_string("activityreport")."\">";
227 echo "</form></p></td>";
8f850172 228 }
6a7585f2 229 if (isteacher($course->id) and ($USER->id != $user->id) and !iscreator($user->id)) {
8f850172 230 echo "<td nowrap><p><form action=\"../course/loginas.php\" method=get>";
231 echo "<input type=hidden name=id value=\"$course->id\">";
232 echo "<input type=hidden name=user value=\"$user->id\">";
233 echo "<input type=submit value=\"".get_string("loginas")."\">";
234 echo "</form></p></td>";
803b2c76 235 }
1b6a4b1d 236 echo "</tr></table></center>\n";
c888501c 237
11b0c469 238 forum_print_user_discussions($course->id, $user->id);
51feb9d5 239
f9903ed0 240 print_footer($course);
241
242/// Functions ///////
243
244function print_row($left, $right) {
8c8c9baf 245 echo "<tr><td nowrap align=right valign=top><p>$left</td><td align=left valign=top><p>$right</p></td></tr>";
f9903ed0 246}
247
248?>