Implemented bug 2676 - jump back to working section after clicking
[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
e41ddc4b 8 optional_variable($id);
9 optional_variable($course);
cadb96f2 10 optional_variable($enable, "");
11 optional_variable($disable, "");
f9903ed0 12
20fde7b1 13 if (!empty($SESSION->wantsurl)) {
14 $wantsurl = $SESSION->wantsurl;
15 unset($SESSION->wantsurl);
16 redirect($wantsurl);
17 }
18
e41ddc4b 19 if (empty($id)) { // See your own profile by default
20 require_login();
21 $id = $USER->id;
22 }
23
24 if (empty($course)) { // See it at site level by default
25 $course = SITEID;
26 }
f9903ed0 27
28 if (! $user = get_record("user", "id", $id) ) {
29 error("No such user in this course");
30 }
31
32 if (! $course = get_record("course", "id", $course) ) {
33 error("No such course id");
34 }
35
555b8513 36 if ($course->category) {
f9903ed0 37 require_login($course->id);
ab1324e4 38 } else if ($CFG->forcelogin or !empty($CFG->forceloginforprofiles)) {
555b8513 39 if (isguest()) {
40 redirect("$CFG->wwwroot/login/index.php");
41 }
42 require_login();
f9903ed0 43 }
44
8f0cd6ef 45 add_to_log($course->id, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
f9903ed0 46
c6c558d7 47 if ($course->id != SITEID) {
48 if ($student = get_record("user_students", "userid", $user->id, "course", $course->id)) {
49 $user->lastaccess = $student->timeaccess;
50 } else if ($teacher = get_record("user_teachers", "userid", $user->id, "course", $course->id)) {
51 $user->lastaccess = $teacher->timeaccess;
52 }
f1603208 53 }
54
5fde0ca6 55 $fullname = fullname($user, isteacher($course->id));
fa0626c6 56 $personalprofile = get_string("personalprofile");
57 $participants = get_string("participants");
58
a9cbf8cc 59 if (empty($USER->id)) {
60 $currentuser = false;
61 } else {
62 $currentuser = ($user->id == $USER->id);
63 }
64
b1d530d2 65 if (groupmode($course) == SEPARATEGROUPS and !isteacheredit($course->id)) { // Groups must be kept separate
66 require_login();
67
ccfd6c83 68 if (!$currentuser && !isteacheredit($course->id, $user->id) && !ismember(mygroupid($course->id), $user->id)) {
b1d530d2 69 print_header("$personalprofile: ", "$personalprofile: ",
70 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
71 <a href=\"index.php?id=$course->id\">$participants</a>",
72 "", "", true, "&nbsp;", navmenu($course));
73 error(get_string("groupnotamember"), "../course/view.php?id=$course->id");
dd780a3b 74 }
75 }
76
1610aa49 77 if ($course->id == SITEID and !$currentuser) { // To reduce possibility of "browsing" userbase at site level
9407d456 78 if (!isteacherinanycourse() and !isteacherinanycourse($user->id) ) { // Teachers can browse and be browsed at site level
f5ecf2e9 79 print_header("$personalprofile: ", "$personalprofile: ",
80 "<a href=\"index.php?id=$course->id\">$participants</a>",
81 "", "", true, "&nbsp;", navmenu($course));
82 print_heading(get_string('usernotavailable', 'error'));
83 print_footer($course);
84 die;
85 }
86 }
87
88
f9903ed0 89 if ($course->category) {
ab1324e4 90 print_header("$personalprofile: $fullname", "$personalprofile: $fullname",
91 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
1b6a4b1d 92 <a href=\"index.php?id=$course->id\">$participants</a> -> $fullname",
951b22a8 93 "", "", true, "&nbsp;", navmenu($course));
f9903ed0 94 } else {
ab1324e4 95 print_header("$course->fullname: $personalprofile: $fullname", "$course->fullname",
951b22a8 96 "$fullname", "", "", true, "&nbsp;", navmenu($course));
f9903ed0 97 }
98
b1d530d2 99
f5ecf2e9 100 if ($course->category and ! isguest() ) { // Need to have access to a course to see that info
b51e9913 101 if (!isstudent($course->id, $user->id) && !isteacher($course->id, $user->id)) {
fa0626c6 102 print_heading(get_string("notenrolled", "", $fullname));
b51e9913 103 print_footer($course);
104 die;
105 }
8a3b358b 106 }
107
bb09fb11 108 if ($user->deleted) {
109 print_heading(get_string("userdeleted"));
110 }
111
1b6a4b1d 112 echo "<table width=\"80%\" align=\"center\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" class=\"userinfobox\">";
113 echo "<tr>";
114 echo "<td width=\"100\" valign=\"top\" class=\"userinfoboxside\">";
15e4b2ec 115 print_user_picture($user->id, $course->id, $user->picture, true, false, false);
b77c41c1 116 echo "</td><td width=\"100%\" class=\"userinfoboxcontent\">";
f9903ed0 117
118
119 // Print name and edit button across top
120
031c49fa 121 echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td nowrap=\"nowrap\">";
1b6a4b1d 122 echo "<h3>$fullname</h3>";
123 echo "</td><td align=\"right\">";
61e96406 124 if (($currentuser and !isguest()) or isadmin()) {
ab1324e4 125 if(empty($CFG->loginhttps)) {
126 $wwwroot = $CFG->wwwroot;
127 } else {
128 $wwwroot = str_replace('http','https',$CFG->wwwroot);
129 }
7c7d9120 130 echo "<form action=\"$wwwroot/user/edit.php\" method=\"get\">";
ab1324e4 131 echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
132 echo "<input type=\"hidden\" name=\"course\" value=\"$course->id\" />";
133 echo "<input type=\"submit\" value=\"".get_string("editmyprofile")."\" />";
7c7d9120 134 echo "</form>";
f9903ed0 135 }
7c7d9120 136 echo "</td></tr></table>\n\n";
f9903ed0 137
138
f9903ed0 139 // Print the description
140
141 if ($user->description) {
7c7d9120 142 echo format_text($user->description, FORMAT_MOODLE)."<hr />";
f9903ed0 143 }
144
f9903ed0 145 // Print all the little details in a list
146
dadbd758 147 echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\">";
f9903ed0 148
603d4c72 149 if ($user->city or $user->country) {
f1603208 150 $countries = get_list_of_countries();
5833a6c8 151 print_row(get_string("location").":", "$user->city, ".$countries["$user->country"]);
603d4c72 152 }
f9903ed0 153
154 if (isteacher($course->id)) {
155 if ($user->address) {
fa0626c6 156 print_row(get_string("address").":", "$user->address");
f9903ed0 157 }
158 if ($user->phone1) {
fa0626c6 159 print_row(get_string("phone").":", "$user->phone1");
f9903ed0 160 }
161 if ($user->phone2) {
fa0626c6 162 print_row(get_string("phone").":", "$user->phone2");
f9903ed0 163 }
164 }
165
ab1324e4 166 if ($user->maildisplay == 1 or
167 ($user->maildisplay == 2 and $course->category and !isguest()) or
d0ec93fb 168 isteacher($course->id)) {
cadb96f2 169
c6c558d7 170 $emailswitch = '';
171
cadb96f2 172 if (isteacheredit($course->id) or $currentuser) { /// Can use the enable/disable email stuff
c6c558d7 173 if (!empty($_GET['enable'])) { /// Recieved a parameter to enable the email address
cadb96f2 174 set_field('user', 'emailstop', 0, 'id', $user->id);
175 $user->emailstop = 0;
176 }
c6c558d7 177 if (!empty($_GET['disable'])) { /// Recieved a parameter to disable the email address
cadb96f2 178 set_field('user', 'emailstop', 1, 'id', $user->id);
179 $user->emailstop = 1;
180 }
c6c558d7 181 }
182
183 if (isteacheredit($course->id)) { /// Can use the enable/disable email stuff
cadb96f2 184 if ($user->emailstop) {
185 $switchparam = 'enable';
186 $switchtitle = get_string('emaildisable');
dee51de2 187 $switchclick = get_string('emailenableclick');
fa92b42f 188 $switchpix = 'emailno.gif';
cadb96f2 189 } else {
190 $switchparam = 'disable';
191 $switchtitle = get_string('emailenable');
dee51de2 192 $switchclick = get_string('emaildisableclick');
fa92b42f 193 $switchpix = 'email.gif';
cadb96f2 194 }
c6c558d7 195 $emailswitch = "&nbsp<a title=\"$switchclick\" ".
196 "href=\"view.php?id=$user->id&course=$course->id&$switchparam=1\">".
197 "<img border=\"0\" width=11 height=11 src=\"$CFG->pixpath/t/$switchpix\"></a>";
198
199 } else if ($currentuser) { /// Can only re-enable an email this way
200 if ($user->emailstop) { // Include link that tells how to re-enable their email
201 $switchparam = 'enable';
202 $switchtitle = get_string('emaildisable');
203 $switchclick = get_string('emailenableclick');
204
205 $emailswitch = "&nbsp(<a title=\"$switchclick\" ".
206 "href=\"view.php?id=$user->id&course=$course->id&enable=1\">$switchtitle</a>)";
207 }
cadb96f2 208 }
209
210 print_row(get_string("email").":", obfuscate_mailto($user->email, '', $user->emailstop)."$emailswitch");
55e078c0 211 }
f9903ed0 212
213 if ($user->url) {
1b6a4b1d 214 print_row(get_string("webpage").":", "<a href=\"$user->url\">$user->url</a>");
f9903ed0 215 }
216
217 if ($user->icq) {
839f2456 218 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&amp;img=5\" width=\"18\" height=\"18\" border=\"0\" alt=\"\" /></a>");
f9903ed0 219 }
220
9c72928d 221 if (isteacher($course->id)) {
222 if ($mycourses = get_my_courses($user->id)) {
223 $courselisting = '';
224 foreach ($mycourses as $mycourse) {
d552efce 225 if ($mycourse->visible and $mycourse->category) {
839f2456 226 $courselisting .= "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$mycourse->id\">$mycourse->fullname</a>, ";
9c72928d 227 }
228 }
229 print_row(get_string('courses').':', rtrim($courselisting,', '));
230 }
231 }
232
d21fef3a 233 if ($user->lastaccess) {
234 $datestring = userdate($user->lastaccess)."&nbsp (".format_time(time() - $user->lastaccess).")";
235 } else {
97ac9019 236 $datestring = get_string("never");
d21fef3a 237 }
fa0626c6 238 print_row(get_string("lastaccess").":", $datestring);
f9903ed0 239
1b6a4b1d 240 echo "</table>";
f9903ed0 241
1b6a4b1d 242 echo "</td></tr></table>";
f9903ed0 243
7c7d9120 244
3086f3f6 245 $internalpassword = false;
f8c883ce 246 if (is_internal_auth() or (!empty($CFG->{'auth_'.$USER->auth.'_stdchangepassword'}))) {
247 if (empty($CFG->loginhttps)) {
248 $internalpassword = "$CFG->wwwroot/login/change_password.php";
ab1324e4 249 } else {
250 $internalpassword = str_replace('http','https',$CFG->wwwroot.'/login/change_password.php');
251 }
3086f3f6 252 }
253
c888501c 254// Print other functions
173dbed4 255 echo '<div class="buttons"><table align="center"><tr>';
61e96406 256 if ($currentuser and !isguest()) {
e09ecb06 257 if ($internalpassword ) {
09e8a2f8 258 echo "<td nowrap=\"nowrap\"><form action=\"$internalpassword\" method=\"get\">";
031c49fa 259 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
260 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
09e8a2f8 261 echo "</form></td>";
e09ecb06 262 } else if ( strlen($CFG->changepassword) > 1 ) {
09e8a2f8 263 echo "<td nowrap=\"nowrap\"><form action=\"$CFG->changepassword\" method=\"get\">";
031c49fa 264 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
09e8a2f8 265 echo "</form></td>";
3086f3f6 266 }
e1ac4272 267 }
ab1324e4 268 if ($course->category and
269 ((isstudent($course->id) and ($user->id == $USER->id) and !isguest() and $CFG->allowunenroll) or
f7f2ff6d 270 (isteacheredit($course->id) and isstudent($course->id, $user->id))) ) {
09e8a2f8 271 echo "<td nowrap=\"nowrap\"><form action=\"../course/unenrol.php\" method=\"get\" />";
031c49fa 272 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
273 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
274 echo "<input type=\"submit\" value=\"".get_string("unenrolme", "", $course->shortname)."\">";
09e8a2f8 275 echo "</form></td>";
18798c6f 276 }
8f850172 277 if (isteacher($course->id) or ($course->showreports and $USER->id == $user->id)) {
09e8a2f8 278 echo "<td nowrap=\"nowrap\"><form action=\"../course/user.php\" method=\"get\">";
031c49fa 279 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
280 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
281 echo "<input type=\"submit\" value=\"".get_string("activityreport")."\" />";
09e8a2f8 282 echo "</form></td>";
8f850172 283 }
37d83d99 284 if ((isadmin() and !isadmin($user->id)) or (isteacher($course->id) and ($USER->id != $user->id) and !iscreator($user->id))) {
09e8a2f8 285 echo "<td nowrap=\"nowrap\"><form action=\"../course/loginas.php\" method=\"get\">";
031c49fa 286 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
287 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
288 echo "<input type=\"submit\" value=\"".get_string("loginas")."\" />";
09e8a2f8 289 echo "</form></td>";
803b2c76 290 }
cdf39255 291 if (!empty($CFG->messaging)) {
292 if ($USER->id == $user->id) {
293 if ($countmessages = count_records('message', 'useridto', $user->id)) {
294 $messagebuttonname = get_string("messages", "message")."($countmessages)";
295 } else {
296 $messagebuttonname = get_string("messages", "message");
297 }
298 echo "<td nowrap=\"nowrap\"><form target=\"message\" action=\"../message/index.php\" method=\"get\">";
299 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);\" />";
300 echo "</form></td>";
2fc1b1fe 301 } else {
cdf39255 302 echo "<td nowrap=\"nowrap\"><form target=\"message_$user->id\" action=\"../message/user.php\" method=\"get\">";
303 echo "<input type=\"hidden\" name=\"id\" value=\"$user->id\" />";
304 echo "<input type=\"submit\" value=\"".get_string("sendmessage", "message")."\" onclick=\"return openpopup('/message/user.php?id=$user->id', 'message_$user->id', 'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500', 0);\" />";
305 echo "</form></td>";
2fc1b1fe 306 }
2fc1b1fe 307 }
7c7d9120 308 echo "<td></td>";
173dbed4 309 echo "</tr></table></div>\n";
c888501c 310
ab1324e4 311 $isseparategroups = ($course->groupmode == SEPARATEGROUPS and
312 $course->groupmodeforce and
d552efce 313 !isteacheredit($course->id));
314
315 $groupid = $isseparategroups ? get_current_group($course->id) : NULL;
316
317 forum_print_user_discussions($course->id, $user->id, $groupid);
51feb9d5 318
f9903ed0 319 print_footer($course);
320
321/// Functions ///////
322
323function print_row($left, $right) {
7c7d9120 324 echo "\n<tr><td nowrap=\"nowrap\" align=\"right\" valign=\"top\">$left</td><td align=\"left\" valign=\"top\">$right</td></tr>\n";
f9903ed0 325}
326
327?>