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