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