Polished.
[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
8f0cd6ef 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
a9cbf8cc 43 if (empty($USER->id)) {
44 $currentuser = false;
45 } else {
46 $currentuser = ($user->id == $USER->id);
47 }
48
b1d530d2 49 if (groupmode($course) == SEPARATEGROUPS and !isteacheredit($course->id)) { // Groups must be kept separate
50 require_login();
51
ddc1d46f 52 if (!isteacheredit($course->id, $user->id) and !ismember(mygroupid($course->id), $user->id)) {
b1d530d2 53 print_header("$personalprofile: ", "$personalprofile: ",
54 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
55 <a href=\"index.php?id=$course->id\">$participants</a>",
56 "", "", true, "&nbsp;", navmenu($course));
57 error(get_string("groupnotamember"), "../course/view.php?id=$course->id");
dd780a3b 58 }
59 }
60
a9cbf8cc 61 if (!$course->category and !$currentuser) { // To reduce possibility of "browsing" userbase at site level
f5ecf2e9 62 if (!isteacher() and !isteacher(0, $user->id) ) { // Teachers can browse and be browsed at site level
63 print_header("$personalprofile: ", "$personalprofile: ",
64 "<a href=\"index.php?id=$course->id\">$participants</a>",
65 "", "", true, "&nbsp;", navmenu($course));
66 print_heading(get_string('usernotavailable', 'error'));
67 print_footer($course);
68 die;
69 }
70 }
71
72
f9903ed0 73 if ($course->category) {
ab1324e4 74 print_header("$personalprofile: $fullname", "$personalprofile: $fullname",
75 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
1b6a4b1d 76 <a href=\"index.php?id=$course->id\">$participants</a> -> $fullname",
951b22a8 77 "", "", true, "&nbsp;", navmenu($course));
f9903ed0 78 } else {
ab1324e4 79 print_header("$course->fullname: $personalprofile: $fullname", "$course->fullname",
951b22a8 80 "$fullname", "", "", true, "&nbsp;", navmenu($course));
f9903ed0 81 }
82
b1d530d2 83
f5ecf2e9 84 if ($course->category and ! isguest() ) { // Need to have access to a course to see that info
b51e9913 85 if (!isstudent($course->id, $user->id) && !isteacher($course->id, $user->id)) {
fa0626c6 86 print_heading(get_string("notenrolled", "", $fullname));
b51e9913 87 print_footer($course);
88 die;
89 }
8a3b358b 90 }
91
bb09fb11 92 if ($user->deleted) {
93 print_heading(get_string("userdeleted"));
94 }
95
1b6a4b1d 96 echo "<table width=\"80%\" align=\"center\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" class=\"userinfobox\">";
97 echo "<tr>";
98 echo "<td width=\"100\" valign=\"top\" class=\"userinfoboxside\">";
15e4b2ec 99 print_user_picture($user->id, $course->id, $user->picture, true, false, false);
1b6a4b1d 100 echo "</td><td width=\"100%\" bgcolor=\"$THEME->cellcontent\" class=\"userinfoboxcontent\">";
f9903ed0 101
102
103 // Print name and edit button across top
104
031c49fa 105 echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td nowrap=\"nowrap\">";
1b6a4b1d 106 echo "<h3>$fullname</h3>";
107 echo "</td><td align=\"right\">";
61e96406 108 if (($currentuser and !isguest()) or isadmin()) {
ab1324e4 109 if(empty($CFG->loginhttps)) {
110 $wwwroot = $CFG->wwwroot;
111 } else {
112 $wwwroot = str_replace('http','https',$CFG->wwwroot);
113 }
7c7d9120 114 echo "<form action=\"$wwwroot/user/edit.php\" method=\"get\">";
ab1324e4 115 echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
116 echo "<input type=\"hidden\" name=\"course\" value=\"$course->id\" />";
117 echo "<input type=\"submit\" value=\"".get_string("editmyprofile")."\" />";
7c7d9120 118 echo "</form>";
f9903ed0 119 }
7c7d9120 120 echo "</td></tr></table>\n\n";
f9903ed0 121
122
f9903ed0 123 // Print the description
124
125 if ($user->description) {
7c7d9120 126 echo format_text($user->description, FORMAT_MOODLE)."<hr />";
f9903ed0 127 }
128
f9903ed0 129 // Print all the little details in a list
130
dadbd758 131 echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\">";
f9903ed0 132
603d4c72 133 if ($user->city or $user->country) {
f1603208 134 $countries = get_list_of_countries();
5833a6c8 135 print_row(get_string("location").":", "$user->city, ".$countries["$user->country"]);
603d4c72 136 }
f9903ed0 137
138 if (isteacher($course->id)) {
139 if ($user->address) {
fa0626c6 140 print_row(get_string("address").":", "$user->address");
f9903ed0 141 }
142 if ($user->phone1) {
fa0626c6 143 print_row(get_string("phone").":", "$user->phone1");
f9903ed0 144 }
145 if ($user->phone2) {
fa0626c6 146 print_row(get_string("phone").":", "$user->phone2");
f9903ed0 147 }
148 }
149
ab1324e4 150 if ($user->maildisplay == 1 or
151 ($user->maildisplay == 2 and $course->category and !isguest()) or
d0ec93fb 152 isteacher($course->id)) {
cadb96f2 153
154 if (isteacheredit($course->id) or $currentuser) { /// Can use the enable/disable email stuff
155 if (!empty($_GET['enable'])) { /// Recieved a paramter to enable the email address
156 set_field('user', 'emailstop', 0, 'id', $user->id);
157 $user->emailstop = 0;
158 }
159 if (!empty($_GET['disable'])) { /// Recieved a paramter to disable the email address
160 set_field('user', 'emailstop', 1, 'id', $user->id);
161 $user->emailstop = 1;
162 }
163 if ($user->emailstop) {
164 $switchparam = 'enable';
165 $switchtitle = get_string('emaildisable');
dee51de2 166 $switchclick = get_string('emailenableclick');
fa92b42f 167 $switchpix = 'emailno.gif';
cadb96f2 168 } else {
169 $switchparam = 'disable';
170 $switchtitle = get_string('emailenable');
dee51de2 171 $switchclick = get_string('emaildisableclick');
fa92b42f 172 $switchpix = 'email.gif';
cadb96f2 173 }
dee51de2 174 $emailswitch = "&nbsp<a title=\"$switchclick\" ".
839f2456 175 "href=\"view.php?id=$user->id&amp;course=$course->id&$switchparam=$user->id\">".
176 "<img border=\"0\" width=\"11\" height=\"11\" src=\"$CFG->pixpath/t/$switchpix\" alt=\"\" /></a>";
cadb96f2 177 } else {
178 $emailswitch = '';
179 }
180
181 print_row(get_string("email").":", obfuscate_mailto($user->email, '', $user->emailstop)."$emailswitch");
55e078c0 182 }
f9903ed0 183
184 if ($user->url) {
1b6a4b1d 185 print_row(get_string("webpage").":", "<a href=\"$user->url\">$user->url</a>");
f9903ed0 186 }
187
188 if ($user->icq) {
839f2456 189 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 190 }
191
9c72928d 192 if (isteacher($course->id)) {
193 if ($mycourses = get_my_courses($user->id)) {
194 $courselisting = '';
195 foreach ($mycourses as $mycourse) {
d552efce 196 if ($mycourse->visible and $mycourse->category) {
839f2456 197 $courselisting .= "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$mycourse->id\">$mycourse->fullname</a>, ";
9c72928d 198 }
199 }
200 print_row(get_string('courses').':', rtrim($courselisting,', '));
201 }
202 }
203
d21fef3a 204 if ($user->lastaccess) {
205 $datestring = userdate($user->lastaccess)."&nbsp (".format_time(time() - $user->lastaccess).")";
206 } else {
97ac9019 207 $datestring = get_string("never");
d21fef3a 208 }
fa0626c6 209 print_row(get_string("lastaccess").":", $datestring);
f9903ed0 210
1b6a4b1d 211 echo "</table>";
f9903ed0 212
1b6a4b1d 213 echo "</td></tr></table>";
f9903ed0 214
7c7d9120 215
3086f3f6 216 $internalpassword = false;
ecac660c 217 if (is_internal_auth()) {
ab1324e4 218 if(empty($CFG->loginhttps)) {
3086f3f6 219 $internalpassword = "$CFG->wwwroot/login/change_password.php";
ab1324e4 220 } else {
221 $internalpassword = str_replace('http','https',$CFG->wwwroot.'/login/change_password.php');
222 }
3086f3f6 223 }
224
c888501c 225// Print other functions
031c49fa 226 echo "<center><table align=\"center\"><tr>";
61e96406 227 if ($currentuser and !isguest()) {
35d01c7f 228 if ($internalpassword) {
031c49fa 229 echo "<td nowrap=\"nowrap\"><p><form action=\"$internalpassword\" method=\"get\">";
230 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
231 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
1b6a4b1d 232 echo "</form></p></td>";
61a5e1e9 233 } else if (strlen($CFG->changepassword) > 1) {
031c49fa 234 echo "<td nowrap=\"nowrap\"><p><form action=\"$CFG->changepassword\" method=\"get\">";
235 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
1b6a4b1d 236 echo "</form></p></td>";
3086f3f6 237 }
e1ac4272 238 }
ab1324e4 239 if ($course->category and
240 ((isstudent($course->id) and ($user->id == $USER->id) and !isguest() and $CFG->allowunenroll) or
f7f2ff6d 241 (isteacheredit($course->id) and isstudent($course->id, $user->id))) ) {
031c49fa 242 echo "<td nowrap=\"nowrap\"><p><form action=\"../course/unenrol.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("unenrolme", "", $course->shortname)."\">";
1b6a4b1d 246 echo "</form></p></td>";
18798c6f 247 }
8f850172 248 if (isteacher($course->id) or ($course->showreports and $USER->id == $user->id)) {
031c49fa 249 echo "<td nowrap=\"nowrap\"><p><form action=\"../course/user.php\" method=\"get\">";
250 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
251 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
252 echo "<input type=\"submit\" value=\"".get_string("activityreport")."\" />";
1b6a4b1d 253 echo "</form></p></td>";
8f850172 254 }
37d83d99 255 if ((isadmin() and !isadmin($user->id)) or (isteacher($course->id) and ($USER->id != $user->id) and !iscreator($user->id))) {
031c49fa 256 echo "<td nowrap=\"nowrap\"><p><form action=\"../course/loginas.php\" method=\"get\">";
257 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
258 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
259 echo "<input type=\"submit\" value=\"".get_string("loginas")."\" />";
8f850172 260 echo "</form></p></td>";
803b2c76 261 }
7c7d9120 262 echo "<td></td>";
1b6a4b1d 263 echo "</tr></table></center>\n";
c888501c 264
ab1324e4 265 $isseparategroups = ($course->groupmode == SEPARATEGROUPS and
266 $course->groupmodeforce and
d552efce 267 !isteacheredit($course->id));
268
269 $groupid = $isseparategroups ? get_current_group($course->id) : NULL;
270
271 forum_print_user_discussions($course->id, $user->id, $groupid);
51feb9d5 272
f9903ed0 273 print_footer($course);
274
275/// Functions ///////
276
277function print_row($left, $right) {
7c7d9120 278 echo "\n<tr><td nowrap=\"nowrap\" align=\"right\" valign=\"top\">$left</td><td align=\"left\" valign=\"top\">$right</td></tr>\n";
f9903ed0 279}
280
281?>