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