Fixed a typo, whoops
[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
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
1b6a4b1d 105 echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td nowrap>";
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 }
114 echo "<p><form action=\"$wwwroot/user/edit.php\" method=\"get\">";
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")."\" />";
1b6a4b1d 118 echo "</form></p>";
f9903ed0 119 }
1b6a4b1d 120 echo "</td></tr></table>";
f9903ed0 121
122
f9903ed0 123 // Print the description
124
125 if ($user->description) {
7a2292ae 126 echo "<p>".format_text($user->description, FORMAT_MOODLE)."</p><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\" ".
cadb96f2 175 "href=\"view.php?id=$user->id&course=$course->id&$switchparam=$user->id\">".
176 "<img border=\"0\" width=11 height=11 src=\"$CFG->pixpath/t/$switchpix\"></a>";
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) {
088cbaab 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&img=5\" width=18 height=18 border=0></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) {
197 $courselisting .= "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&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
3086f3f6 215 $internalpassword = false;
ecac660c 216 if (is_internal_auth()) {
ab1324e4 217 if(empty($CFG->loginhttps)) {
3086f3f6 218 $internalpassword = "$CFG->wwwroot/login/change_password.php";
ab1324e4 219 } else {
220 $internalpassword = str_replace('http','https',$CFG->wwwroot.'/login/change_password.php');
221 }
3086f3f6 222 }
223
c888501c 224// Print other functions
1b6a4b1d 225 echo "<center><table align=center><tr>";
61e96406 226 if ($currentuser and !isguest()) {
35d01c7f 227 if ($internalpassword) {
1b6a4b1d 228 echo "<td nowrap><p><form action=\"$internalpassword\" method=get>";
229 echo "<input type=hidden name=id value=\"$course->id\">";
230 echo "<input type=submit value=\"".get_string("changepassword")."\">";
231 echo "</form></p></td>";
61a5e1e9 232 } else if (strlen($CFG->changepassword) > 1) {
1b6a4b1d 233 echo "<td nowrap><p><form action=\"$CFG->changepassword\" method=get>";
234 echo "<input type=submit value=\"".get_string("changepassword")."\">";
235 echo "</form></p></td>";
3086f3f6 236 }
e1ac4272 237 }
ab1324e4 238 if ($course->category and
239 ((isstudent($course->id) and ($user->id == $USER->id) and !isguest() and $CFG->allowunenroll) or
f7f2ff6d 240 (isteacheredit($course->id) and isstudent($course->id, $user->id))) ) {
1b6a4b1d 241 echo "<td nowrap><p><form action=\"../course/unenrol.php\" method=get>";
242 echo "<input type=hidden name=id value=\"$course->id\">";
243 echo "<input type=hidden name=user value=\"$user->id\">";
244 echo "<input type=submit value=\"".get_string("unenrolme", "", $course->shortname)."\">";
245 echo "</form></p></td>";
18798c6f 246 }
8f850172 247 if (isteacher($course->id) or ($course->showreports and $USER->id == $user->id)) {
1b6a4b1d 248 echo "<td nowrap><p><form action=\"../course/user.php\" method=get>";
249 echo "<input type=hidden name=id value=\"$course->id\">";
250 echo "<input type=hidden name=user value=\"$user->id\">";
251 echo "<input type=submit value=\"".get_string("activityreport")."\">";
252 echo "</form></p></td>";
8f850172 253 }
37d83d99 254 if ((isadmin() and !isadmin($user->id)) or (isteacher($course->id) and ($USER->id != $user->id) and !iscreator($user->id))) {
8f850172 255 echo "<td nowrap><p><form action=\"../course/loginas.php\" method=get>";
256 echo "<input type=hidden name=id value=\"$course->id\">";
257 echo "<input type=hidden name=user value=\"$user->id\">";
258 echo "<input type=submit value=\"".get_string("loginas")."\">";
259 echo "</form></p></td>";
803b2c76 260 }
1b6a4b1d 261 echo "</tr></table></center>\n";
c888501c 262
ab1324e4 263 $isseparategroups = ($course->groupmode == SEPARATEGROUPS and
264 $course->groupmodeforce and
d552efce 265 !isteacheredit($course->id));
266
267 $groupid = $isseparategroups ? get_current_group($course->id) : NULL;
268
269 forum_print_user_discussions($course->id, $user->id, $groupid);
51feb9d5 270
f9903ed0 271 print_footer($course);
272
273/// Functions ///////
274
275function print_row($left, $right) {
8c8c9baf 276 echo "<tr><td nowrap align=right valign=top><p>$left</td><td align=left valign=top><p>$right</p></td></tr>";
f9903ed0 277}
278
279?>