Whoops, accidentally checked in some aborted code
[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);
ab1324e4 24 } else if ($CFG->forcelogin or !empty($CFG->forceloginforprofiles)) {
555b8513 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
ddc1d46f 46 if (!isteacheredit($course->id, $user->id) and !ismember(mygroupid($course->id), $user->id)) {
b1d530d2 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) {
ab1324e4 56 print_header("$personalprofile: $fullname", "$personalprofile: $fullname",
57 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
1b6a4b1d 58 <a href=\"index.php?id=$course->id\">$participants</a> -> $fullname",
951b22a8 59 "", "", true, "&nbsp;", navmenu($course));
f9903ed0 60 } else {
ab1324e4 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()) {
ab1324e4 96 if(empty($CFG->loginhttps)) {
97 $wwwroot = $CFG->wwwroot;
98 } else {
99 $wwwroot = str_replace('http','https',$CFG->wwwroot);
100 }
101 echo "<p><form action=\"$wwwroot/user/edit.php\" method=\"get\">";
102 echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
103 echo "<input type=\"hidden\" name=\"course\" value=\"$course->id\" />";
104 echo "<input type=\"submit\" value=\"".get_string("editmyprofile")."\" />";
1b6a4b1d 105 echo "</form></p>";
f9903ed0 106 }
1b6a4b1d 107 echo "</td></tr></table>";
f9903ed0 108
109
f9903ed0 110 // Print the description
111
112 if ($user->description) {
d7df380b 113 echo "<p>".format_text(clean_text($user->description, FORMAT_MOODLE))."</p><hr>";
f9903ed0 114 }
115
f9903ed0 116 // Print all the little details in a list
117
dadbd758 118 echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\">";
f9903ed0 119
603d4c72 120 if ($user->city or $user->country) {
f1603208 121 $countries = get_list_of_countries();
5833a6c8 122 print_row(get_string("location").":", "$user->city, ".$countries["$user->country"]);
603d4c72 123 }
f9903ed0 124
125 if (isteacher($course->id)) {
126 if ($user->address) {
fa0626c6 127 print_row(get_string("address").":", "$user->address");
f9903ed0 128 }
129 if ($user->phone1) {
fa0626c6 130 print_row(get_string("phone").":", "$user->phone1");
f9903ed0 131 }
132 if ($user->phone2) {
fa0626c6 133 print_row(get_string("phone").":", "$user->phone2");
f9903ed0 134 }
135 }
136
ab1324e4 137 if ($user->maildisplay == 1 or
138 ($user->maildisplay == 2 and $course->category and !isguest()) or
d0ec93fb 139 isteacher($course->id)) {
cadb96f2 140
141 if (isteacheredit($course->id) or $currentuser) { /// Can use the enable/disable email stuff
142 if (!empty($_GET['enable'])) { /// Recieved a paramter to enable the email address
143 set_field('user', 'emailstop', 0, 'id', $user->id);
144 $user->emailstop = 0;
145 }
146 if (!empty($_GET['disable'])) { /// Recieved a paramter to disable the email address
147 set_field('user', 'emailstop', 1, 'id', $user->id);
148 $user->emailstop = 1;
149 }
150 if ($user->emailstop) {
151 $switchparam = 'enable';
152 $switchtitle = get_string('emaildisable');
dee51de2 153 $switchclick = get_string('emailenableclick');
fa92b42f 154 $switchpix = 'emailno.gif';
cadb96f2 155 } else {
156 $switchparam = 'disable';
157 $switchtitle = get_string('emailenable');
dee51de2 158 $switchclick = get_string('emaildisableclick');
fa92b42f 159 $switchpix = 'email.gif';
cadb96f2 160 }
dee51de2 161 $emailswitch = "&nbsp<a title=\"$switchclick\" ".
cadb96f2 162 "href=\"view.php?id=$user->id&course=$course->id&$switchparam=$user->id\">".
163 "<img border=\"0\" width=11 height=11 src=\"$CFG->pixpath/t/$switchpix\"></a>";
164 } else {
165 $emailswitch = '';
166 }
167
168 print_row(get_string("email").":", obfuscate_mailto($user->email, '', $user->emailstop)."$emailswitch");
55e078c0 169 }
f9903ed0 170
171 if ($user->url) {
1b6a4b1d 172 print_row(get_string("webpage").":", "<a href=\"$user->url\">$user->url</a>");
f9903ed0 173 }
174
175 if ($user->icq) {
088cbaab 176 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 177 }
178
9c72928d 179 if (isteacher($course->id)) {
180 if ($mycourses = get_my_courses($user->id)) {
181 $courselisting = '';
182 foreach ($mycourses as $mycourse) {
d552efce 183 if ($mycourse->visible and $mycourse->category) {
184 $courselisting .= "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$mycourse->id\">$mycourse->fullname</a>, ";
9c72928d 185 }
186 }
187 print_row(get_string('courses').':', rtrim($courselisting,', '));
188 }
189 }
190
d21fef3a 191 if ($user->lastaccess) {
192 $datestring = userdate($user->lastaccess)."&nbsp (".format_time(time() - $user->lastaccess).")";
193 } else {
97ac9019 194 $datestring = get_string("never");
d21fef3a 195 }
fa0626c6 196 print_row(get_string("lastaccess").":", $datestring);
f9903ed0 197
1b6a4b1d 198 echo "</table>";
f9903ed0 199
1b6a4b1d 200 echo "</td></tr></table>";
f9903ed0 201
3086f3f6 202 $internalpassword = false;
ecac660c 203 if (is_internal_auth()) {
ab1324e4 204 if(empty($CFG->loginhttps)) {
3086f3f6 205 $internalpassword = "$CFG->wwwroot/login/change_password.php";
ab1324e4 206 } else {
207 $internalpassword = str_replace('http','https',$CFG->wwwroot.'/login/change_password.php');
208 }
3086f3f6 209 }
210
c888501c 211// Print other functions
1b6a4b1d 212 echo "<center><table align=center><tr>";
61e96406 213 if ($currentuser and !isguest()) {
35d01c7f 214 if ($internalpassword) {
1b6a4b1d 215 echo "<td nowrap><p><form action=\"$internalpassword\" method=get>";
216 echo "<input type=hidden name=id value=\"$course->id\">";
217 echo "<input type=submit value=\"".get_string("changepassword")."\">";
218 echo "</form></p></td>";
61a5e1e9 219 } else if (strlen($CFG->changepassword) > 1) {
1b6a4b1d 220 echo "<td nowrap><p><form action=\"$CFG->changepassword\" method=get>";
221 echo "<input type=submit value=\"".get_string("changepassword")."\">";
222 echo "</form></p></td>";
3086f3f6 223 }
e1ac4272 224 }
ab1324e4 225 if ($course->category and
226 ((isstudent($course->id) and ($user->id == $USER->id) and !isguest() and $CFG->allowunenroll) or
f7f2ff6d 227 (isteacheredit($course->id) and isstudent($course->id, $user->id))) ) {
1b6a4b1d 228 echo "<td nowrap><p><form action=\"../course/unenrol.php\" method=get>";
229 echo "<input type=hidden name=id value=\"$course->id\">";
230 echo "<input type=hidden name=user value=\"$user->id\">";
231 echo "<input type=submit value=\"".get_string("unenrolme", "", $course->shortname)."\">";
232 echo "</form></p></td>";
18798c6f 233 }
8f850172 234 if (isteacher($course->id) or ($course->showreports and $USER->id == $user->id)) {
1b6a4b1d 235 echo "<td nowrap><p><form action=\"../course/user.php\" method=get>";
236 echo "<input type=hidden name=id value=\"$course->id\">";
237 echo "<input type=hidden name=user value=\"$user->id\">";
238 echo "<input type=submit value=\"".get_string("activityreport")."\">";
239 echo "</form></p></td>";
8f850172 240 }
6a7585f2 241 if (isteacher($course->id) and ($USER->id != $user->id) and !iscreator($user->id)) {
8f850172 242 echo "<td nowrap><p><form action=\"../course/loginas.php\" method=get>";
243 echo "<input type=hidden name=id value=\"$course->id\">";
244 echo "<input type=hidden name=user value=\"$user->id\">";
245 echo "<input type=submit value=\"".get_string("loginas")."\">";
246 echo "</form></p></td>";
803b2c76 247 }
1b6a4b1d 248 echo "</tr></table></center>\n";
c888501c 249
ab1324e4 250 $isseparategroups = ($course->groupmode == SEPARATEGROUPS and
251 $course->groupmodeforce and
d552efce 252 !isteacheredit($course->id));
253
254 $groupid = $isseparategroups ? get_current_group($course->id) : NULL;
255
256 forum_print_user_discussions($course->id, $user->id, $groupid);
51feb9d5 257
f9903ed0 258 print_footer($course);
259
260/// Functions ///////
261
262function print_row($left, $right) {
8c8c9baf 263 echo "<tr><td nowrap align=right valign=top><p>$left</td><td align=left valign=top><p>$right</p></td></tr>";
f9903ed0 264}
265
266?>