Some changes to make login a little more robust on some sites that have
[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
22 if ($course->category) {
23 require_login($course->id);
24 }
25
da3a08d7 26 add_to_log($course->id, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
f9903ed0 27
f1603208 28 if ($student = get_record("user_students", "userid", $user->id, "course", $course->id)) {
29 $user->lastaccess = $student->timeaccess;
30 } else if ($teacher = get_record("user_teachers", "userid", $user->id, "course", $course->id)) {
31 $user->lastaccess = $teacher->timeaccess;
32 }
33
5fde0ca6 34 $fullname = fullname($user, isteacher($course->id));
fa0626c6 35 $personalprofile = get_string("personalprofile");
36 $participants = get_string("participants");
37
b1d530d2 38 if (groupmode($course) == SEPARATEGROUPS and !isteacheredit($course->id)) { // Groups must be kept separate
39 require_login();
40
41 if (!ismember(mygroupid($course->id), $user->id)) {
42 print_header("$personalprofile: ", "$personalprofile: ",
43 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
44 <a href=\"index.php?id=$course->id\">$participants</a>",
45 "", "", true, "&nbsp;", navmenu($course));
46 error(get_string("groupnotamember"), "../course/view.php?id=$course->id");
dd780a3b 47 }
48 }
49
f9903ed0 50 if ($course->category) {
fa0626c6 51 print_header("$personalprofile: $fullname", "$personalprofile: $fullname",
1b6a4b1d 52 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
53 <a href=\"index.php?id=$course->id\">$participants</a> -> $fullname",
951b22a8 54 "", "", true, "&nbsp;", navmenu($course));
f9903ed0 55 } else {
02e44e7c 56 print_header("$course->fullname: $personalprofile: $fullname", "$course->fullname",
951b22a8 57 "$fullname", "", "", true, "&nbsp;", navmenu($course));
f9903ed0 58 }
59
b1d530d2 60
603d4c72 61 if ($course->category and ! isguest() ) {
b51e9913 62 if (!isstudent($course->id, $user->id) && !isteacher($course->id, $user->id)) {
fa0626c6 63 print_heading(get_string("notenrolled", "", $fullname));
b51e9913 64 print_footer($course);
65 die;
66 }
8a3b358b 67 }
68
bb09fb11 69 if ($user->deleted) {
70 print_heading(get_string("userdeleted"));
71 }
72
1b6a4b1d 73 echo "<table width=\"80%\" align=\"center\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" class=\"userinfobox\">";
74 echo "<tr>";
75 echo "<td width=\"100\" valign=\"top\" class=\"userinfoboxside\">";
15e4b2ec 76 print_user_picture($user->id, $course->id, $user->picture, true, false, false);
1b6a4b1d 77 echo "</td><td width=\"100%\" bgcolor=\"$THEME->cellcontent\" class=\"userinfoboxcontent\">";
f9903ed0 78
79
80 // Print name and edit button across top
81
1b6a4b1d 82 echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td nowrap>";
83 echo "<h3>$fullname</h3>";
84 echo "</td><td align=\"right\">";
61e96406 85 if (empty($USER->id)) {
86 $currentuser = false;
87 } else {
88 $currentuser = ($user->id == $USER->id);
89 }
90 if (($currentuser and !isguest()) or isadmin()) {
1b6a4b1d 91 echo "<p><form action=edit.php method=get>";
92 echo "<input type=hidden name=id value=\"$id\">";
93 echo "<input type=hidden name=course value=\"$course->id\">";
94 echo "<input type=submit value=\"".get_string("editmyprofile")."\">";
95 echo "</form></p>";
f9903ed0 96 }
1b6a4b1d 97 echo "</td></tr></table>";
f9903ed0 98
99
f9903ed0 100 // Print the description
101
102 if ($user->description) {
d7df380b 103 echo "<p>".format_text(clean_text($user->description, FORMAT_MOODLE))."</p><hr>";
f9903ed0 104 }
105
f9903ed0 106 // Print all the little details in a list
107
dadbd758 108 echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\">";
f9903ed0 109
603d4c72 110 if ($user->city or $user->country) {
f1603208 111 $countries = get_list_of_countries();
5833a6c8 112 print_row(get_string("location").":", "$user->city, ".$countries["$user->country"]);
603d4c72 113 }
f9903ed0 114
115 if (isteacher($course->id)) {
116 if ($user->address) {
fa0626c6 117 print_row(get_string("address").":", "$user->address");
f9903ed0 118 }
119 if ($user->phone1) {
fa0626c6 120 print_row(get_string("phone").":", "$user->phone1");
f9903ed0 121 }
122 if ($user->phone2) {
fa0626c6 123 print_row(get_string("phone").":", "$user->phone2");
f9903ed0 124 }
125 }
126
d0ec93fb 127 if ($user->maildisplay == 1 or
128 ($user->maildisplay == 2 and $course->category and !isguest()) or
129 isteacher($course->id)) {
cadb96f2 130
131 if (isteacheredit($course->id) or $currentuser) { /// Can use the enable/disable email stuff
132 if (!empty($_GET['enable'])) { /// Recieved a paramter to enable the email address
133 set_field('user', 'emailstop', 0, 'id', $user->id);
134 $user->emailstop = 0;
135 }
136 if (!empty($_GET['disable'])) { /// Recieved a paramter to disable the email address
137 set_field('user', 'emailstop', 1, 'id', $user->id);
138 $user->emailstop = 1;
139 }
140 if ($user->emailstop) {
141 $switchparam = 'enable';
142 $switchtitle = get_string('emaildisable');
143 $switchpix = 'show.gif';
144 } else {
145 $switchparam = 'disable';
146 $switchtitle = get_string('emailenable');
147 $switchpix = 'hide.gif';
148 }
149 $emailswitch = "&nbsp<a title=\"$switchtitle\" ".
150 "href=\"view.php?id=$user->id&course=$course->id&$switchparam=$user->id\">".
151 "<img border=\"0\" width=11 height=11 src=\"$CFG->pixpath/t/$switchpix\"></a>";
152 } else {
153 $emailswitch = '';
154 }
155
156 print_row(get_string("email").":", obfuscate_mailto($user->email, '', $user->emailstop)."$emailswitch");
55e078c0 157 }
f9903ed0 158
159 if ($user->url) {
1b6a4b1d 160 print_row(get_string("webpage").":", "<a href=\"$user->url\">$user->url</a>");
f9903ed0 161 }
162
163 if ($user->icq) {
088cbaab 164 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 165 }
166
9c72928d 167 if (isteacher($course->id)) {
168 if ($mycourses = get_my_courses($user->id)) {
169 $courselisting = '';
170 foreach ($mycourses as $mycourse) {
171 if ($mycourse->visible) {
172 $courselisting .= "<a href=\"$CFG->wwwroot/course/view.php?id=$mycourse->id\">$mycourse->fullname</a>, ";
173 }
174 }
175 print_row(get_string('courses').':', rtrim($courselisting,', '));
176 }
177 }
178
d21fef3a 179 if ($user->lastaccess) {
180 $datestring = userdate($user->lastaccess)."&nbsp (".format_time(time() - $user->lastaccess).")";
181 } else {
97ac9019 182 $datestring = get_string("never");
d21fef3a 183 }
fa0626c6 184 print_row(get_string("lastaccess").":", $datestring);
f9903ed0 185
1b6a4b1d 186 echo "</table>";
f9903ed0 187
1b6a4b1d 188 echo "</td></tr></table>";
f9903ed0 189
3086f3f6 190 $internalpassword = false;
ecac660c 191 if (is_internal_auth()) {
3086f3f6 192 $internalpassword = "$CFG->wwwroot/login/change_password.php";
193 }
194
c888501c 195// Print other functions
1b6a4b1d 196 echo "<center><table align=center><tr>";
61e96406 197 if ($currentuser and !isguest()) {
35d01c7f 198 if ($internalpassword) {
1b6a4b1d 199 echo "<td nowrap><p><form action=\"$internalpassword\" method=get>";
200 echo "<input type=hidden name=id value=\"$course->id\">";
201 echo "<input type=submit value=\"".get_string("changepassword")."\">";
202 echo "</form></p></td>";
61a5e1e9 203 } else if (strlen($CFG->changepassword) > 1) {
1b6a4b1d 204 echo "<td nowrap><p><form action=\"$CFG->changepassword\" method=get>";
205 echo "<input type=submit value=\"".get_string("changepassword")."\">";
206 echo "</form></p></td>";
3086f3f6 207 }
e1ac4272 208 }
ebc3bd2b 209 if ($course->category and
5204d831 210 ((isstudent($course->id) and ($user->id == $USER->id) and !isguest() and $CFG->allowunenroll) or
ebc3bd2b 211 (isteacher($course->id) and isstudent($course->id, $user->id))) ) {
1b6a4b1d 212 echo "<td nowrap><p><form action=\"../course/unenrol.php\" method=get>";
213 echo "<input type=hidden name=id value=\"$course->id\">";
214 echo "<input type=hidden name=user value=\"$user->id\">";
215 echo "<input type=submit value=\"".get_string("unenrolme", "", $course->shortname)."\">";
216 echo "</form></p></td>";
18798c6f 217 }
8f850172 218 if (isteacher($course->id) or ($course->showreports and $USER->id == $user->id)) {
1b6a4b1d 219 echo "<td nowrap><p><form action=\"../course/user.php\" method=get>";
220 echo "<input type=hidden name=id value=\"$course->id\">";
221 echo "<input type=hidden name=user value=\"$user->id\">";
222 echo "<input type=submit value=\"".get_string("activityreport")."\">";
223 echo "</form></p></td>";
8f850172 224 }
6a7585f2 225 if (isteacher($course->id) and ($USER->id != $user->id) and !iscreator($user->id)) {
8f850172 226 echo "<td nowrap><p><form action=\"../course/loginas.php\" method=get>";
227 echo "<input type=hidden name=id value=\"$course->id\">";
228 echo "<input type=hidden name=user value=\"$user->id\">";
229 echo "<input type=submit value=\"".get_string("loginas")."\">";
230 echo "</form></p></td>";
803b2c76 231 }
1b6a4b1d 232 echo "</tr></table></center>\n";
c888501c 233
11b0c469 234 forum_print_user_discussions($course->id, $user->id);
51feb9d5 235
f9903ed0 236 print_footer($course);
237
238/// Functions ///////
239
240function print_row($left, $right) {
8c8c9baf 241 echo "<tr><td nowrap align=right valign=top><p>$left</td><td align=left valign=top><p>$right</p></td></tr>";
f9903ed0 242}
243
244?>