3 // Display profile for a particular user
5 require_once("../config.php");
7 $id = optional_param('id', 0, PARAM_INT
); // user id
8 $course = optional_param('course', SITEID
, PARAM_INT
); // course id (defaults to Site)
9 $enable = optional_param('enable', ''); // enable email
10 $disable = optional_param('disable', ''); // disable email
13 if (empty($id)) { // See your own profile by default
18 if (! $user = get_record("user", "id", $id) ) {
19 error("No such user in this course");
22 if (! $course = get_record("course", "id", $course) ) {
23 error("No such course id");
26 if (!empty($CFG->forcelogin
) ||
$course->id
!= SITEID
) {
27 require_login($course->id
);
30 if (!empty($CFG->forceloginforprofiles
)) {
33 redirect("$CFG->wwwroot/login/index.php");
37 add_to_log($course->id
, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
39 if ($course->id
!= SITEID
) {
40 if ($student = get_record("user_students", "userid", $user->id
, "course", $course->id
)) {
41 $user->lastaccess
= $student->timeaccess
;
42 } else if ($teacher = get_record("user_teachers", "userid", $user->id
, "course", $course->id
)) {
43 $user->lastaccess
= $teacher->timeaccess
;
47 $fullname = fullname($user, isteacher($course->id
));
48 $personalprofile = get_string("personalprofile");
49 $participants = get_string("participants");
51 if (empty($USER->id
)) {
54 $currentuser = ($user->id
== $USER->id
);
57 if (groupmode($course) == SEPARATEGROUPS
and !isteacheredit($course->id
)) { // Groups must be kept separate
60 ///this is changed because of mygroupid
62 if ($mygroups = mygroupid($course->id
)){
63 foreach ($mygroups as $group){
64 if (ismember($group, $user->id
)){
70 if (!$currentuser && !isteacheredit($course->id
, $user->id
) && !$gtrue) {
71 print_header("$personalprofile: ", "$personalprofile: ",
72 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
73 <a href=\"index.php?id=$course->id\">$participants</a>",
74 "", "", true, " ", navmenu($course));
75 error(get_string("groupnotamember"), "../course/view.php?id=$course->id");
79 if ($course->id
== SITEID
and !$currentuser) { // To reduce possibility of "browsing" userbase at site level
80 if ($CFG->forceloginforprofiles
and !isteacherinanycourse() and !isteacherinanycourse($user->id
)) { // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
81 print_header("$personalprofile: ", "$personalprofile: ",
82 "<a href=\"index.php?id=$course->id\">$participants</a>",
83 "", "", true, " ", navmenu($course));
84 print_heading(get_string('usernotavailable', 'error'));
85 print_footer($course);
91 if ($course->category
) {
92 print_header("$personalprofile: $fullname", "$personalprofile: $fullname",
93 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
94 <a href=\"index.php?id=$course->id\">$participants</a> -> $fullname",
95 "", "", true, " ", navmenu($course));
97 print_header("$course->fullname: $personalprofile: $fullname", "$course->fullname",
98 "$fullname", "", "", true, " ", navmenu($course));
102 if ($course->category
and ! isguest() ) { // Need to have access to a course to see that info
103 if (!isstudent($course->id
, $user->id
) && !isteacher($course->id
, $user->id
)) {
104 print_heading(get_string("notenrolled", "", $fullname));
105 print_footer($course);
110 if ($user->deleted
) {
111 print_heading(get_string("userdeleted"));
112 print_footer($course);
116 /// Get the hidden field list
117 if (isteacher($course->id
) ||
isadmin()) {
118 $hiddenfields = array(); // teachers and admins are allowed to see everything
120 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields
));
123 /// Print tabs at top
124 /// This same call is made in:
128 $currenttab = 'profile';
131 echo "<table width=\"80%\" align=\"center\" border=\"0\" cellspacing=\"0\" class=\"userinfobox\">";
133 echo "<td width=\"100\" valign=\"top\" class=\"side\">";
134 print_user_picture($user->id
, $course->id
, $user->picture
, true, false, false);
135 echo "</td><td width=\"100%\" class=\"content\">";
137 // Print the description
139 if ($user->description
&& !isset($hiddenfields['description'])) {
140 echo format_text($user->description
, FORMAT_MOODLE
)."<hr />";
143 // Print all the little details in a list
145 echo '<table border="0" cellpadding="0" cellspacing="0" class="list">';
147 if (($user->city
or $user->country
) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) {
149 if ($user->city
&& !isset($hiddenfields['city'])) {
150 $location .= $user->city
;
152 if (!empty($countries[$user->country
]) && !isset($hiddenfields['country'])) {
153 if ($user->city
&& !isset($hiddenfields['country'])) {
156 $countries = get_list_of_countries();
157 $location .= $countries[$user->country
];
159 print_row(get_string("location").":", $location);
162 if (isteacher($course->id
)) {
163 if ($user->address
) {
164 print_row(get_string("address").":", "$user->address");
167 print_row(get_string("phone").":", "$user->phone1");
170 print_row(get_string("phone").":", "$user->phone2");
174 if ($user->maildisplay
== 1 or
175 ($user->maildisplay
== 2 and $course->category
and !isguest()) or
176 isteacher($course->id
)) {
180 if (isteacheredit($course->id
) or $currentuser) { /// Can use the enable/disable email stuff
181 if (!empty($enable)) { /// Recieved a parameter to enable the email address
182 set_field('user', 'emailstop', 0, 'id', $user->id
);
183 $user->emailstop
= 0;
185 if (!empty($disable)) { /// Recieved a parameter to disable the email address
186 set_field('user', 'emailstop', 1, 'id', $user->id
);
187 $user->emailstop
= 1;
191 if (isteacheredit($course->id
)) { /// Can use the enable/disable email stuff
192 if ($user->emailstop
) {
193 $switchparam = 'enable';
194 $switchtitle = get_string('emaildisable');
195 $switchclick = get_string('emailenableclick');
196 $switchpix = 'emailno.gif';
198 $switchparam = 'disable';
199 $switchtitle = get_string('emailenable');
200 $switchclick = get_string('emaildisableclick');
201 $switchpix = 'email.gif';
203 $emailswitch = " <a title=\"$switchclick\" ".
204 "href=\"view.php?id=$user->id&course=$course->id&$switchparam=1\">".
205 "<img border=\"0\" width=\"11\" height=\"11\" src=\"$CFG->pixpath/t/$switchpix\" alt=\"\" /></a>";
207 } else if ($currentuser) { /// Can only re-enable an email this way
208 if ($user->emailstop
) { // Include link that tells how to re-enable their email
209 $switchparam = 'enable';
210 $switchtitle = get_string('emaildisable');
211 $switchclick = get_string('emailenableclick');
213 $emailswitch = " (<a title=\"$switchclick\" ".
214 "href=\"view.php?id=$user->id&course=$course->id&enable=1\">$switchtitle</a>)";
218 print_row(get_string("email").":", obfuscate_mailto($user->email
, '', $user->emailstop
)."$emailswitch");
221 if ($user->url
&& !isset($hiddenfields['webpage'])) {
222 print_row(get_string("webpage").":", "<a href=\"$user->url\">$user->url</a>");
225 if ($user->icq
&& !isset($hiddenfields['icqnumber'])) {
226 print_row(get_string('icqnumber').':',"<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>");
229 if ($user->skype
&& !isset($hiddenfields['skypeid'])) {
230 print_row(get_string('skypeid').':','<a href="callto:'.urlencode($user->skype
).'">'.s($user->skype
).
231 ' <img src="http://mystatus.skype.com/smallicon/'.urlencode($user->skype
).'" alt="status" '.
232 ' height="16" width="16" /></a>');
234 if ($user->yahoo
&& !isset($hiddenfields['yahooid'])) {
235 print_row(get_string('yahooid').':', '<a href="http://edit.yahoo.com/config/send_webmesg?.target='.urlencode($user->yahoo
).'&.src=pg">'.s($user->yahoo
)." <img border=0 src=\"http://opi.yahoo.com/online?u=".urlencode($user->yahoo
)."&m=g&t=0\" width=\"12\" height=\"12\" alt=\"\"></a>");
237 if ($user->aim
&& !isset($hiddenfields['aimid'])) {
238 print_row(get_string('aimid').':', '<a href="aim:goim?screenname='.s($user->aim
).'">'.s($user->aim
).'</a>');
240 if ($user->msn
&& !isset($hiddenfields['msnid'])) {
241 print_row(get_string('msnid').':', s($user->msn
));
244 if (isteacher($course->id
)) {
245 if ($mycourses = get_my_courses($user->id
)) {
247 foreach ($mycourses as $mycourse) {
248 if ($mycourse->visible
and $mycourse->category
) {
249 if ($mycourse->id
!= $course->id
){
250 $courselisting .= "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$mycourse->id\">$mycourse->fullname</a>, ";
253 $courselisting .= "$mycourse->fullname, ";
257 print_row(get_string('courses').':', rtrim($courselisting,', '));
261 if (!isset($hiddenfields['lastaccess'])) {
262 if ($user->lastaccess
) {
263 $datestring = userdate($user->lastaccess
)." (".format_time(time() - $user->lastaccess
).")";
265 $datestring = get_string("never");
267 print_row(get_string("lastaccess").":", $datestring);
272 $isseparategroups = ($course->groupmode
== SEPARATEGROUPS
and $course->groupmodeforce
and
273 !isteacheredit($course->id
));
274 if (!$isseparategroups){
275 if ($usergroups = user_group($course->id
, $user->id
)){
277 foreach ($usergroups as $group){
278 $groupstr .= ' <a href="'.$CFG->wwwroot
.'/user/index.php?id='.$course->id
.'&group='.$group->id
.'">'.$group->name
.'</a>,';
280 print_row(get_string("group").":", rtrim($groupstr, ', '));
283 /// End of printing groups
287 echo "</td></tr></table>";
289 $internalpassword = false;
290 if (is_internal_auth($user->auth
) or (!empty($CFG->{'auth_'.$user->auth
.'_stdchangepassword'}))) {
291 if (empty($CFG->loginhttps
)) {
292 $internalpassword = "$CFG->wwwroot/login/change_password.php";
294 $internalpassword = str_replace('http:','https:',$CFG->wwwroot
.'/login/change_password.php');
298 // Print other functions
299 echo '<div class="buttons"><table align="center"><tr>';
301 if ($currentuser and !isguest() and !is_restricted_user($USER->username
)) {
302 if ($internalpassword ) {
303 echo "<td nowrap=\"nowrap\"><form action=\"$internalpassword\" method=\"get\">";
304 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
305 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
307 } else if ( strlen($CFG->{'auth_'.$user->auth
.'_changepasswordurl'}) > 1 ) {
308 echo "<td nowrap=\"nowrap\"><form action=\"".$CFG->{'auth_'.$user->auth
.'_changepasswordurl'}."\" method=\"get\">";
309 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
313 if ($course->category
and
314 ((isstudent($course->id
) and ($user->id
== $USER->id
) and !isguest() and $CFG->allowunenroll
) or
315 (isteacheredit($course->id
) and isstudent($course->id
, $user->id
))) ) {
316 echo "<td nowrap=\"nowrap\"><form action=\"../course/unenrol.php\" method=\"get\" />";
317 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
318 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
319 echo "<input type=\"submit\" value=\"".get_string("unenrolme", "", $course->shortname
)."\">";
322 /* if (isteacher($course->id) or ($course->showreports and $USER->id == $user->id)) {
323 echo "<td nowrap=\"nowrap\"><form action=\"../course/user.php\" method=\"get\">";
324 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
325 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
326 echo "<input type=\"submit\" value=\"".get_string("activityreport")."\" />";
330 if ((isadmin() and !isadmin($user->id
)) or (isteacher($course->id
) and isstudent($course->id
, $user->id
) and ($USER->id
!= $user->id
) and !iscreator($user->id
))) {
331 echo "<td nowrap=\"nowrap\"><form action=\"../course/loginas.php\" method=\"get\">";
332 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
333 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
334 echo "<input type=\"submit\" value=\"".get_string("loginas")."\" />";
337 if (!empty($CFG->messaging
) and !isguest()) {
338 if (!empty($USER->id
) and ($USER->id
== $user->id
)) {
339 if ($countmessages = count_records('message', 'useridto', $user->id
)) {
340 $messagebuttonname = get_string("messages", "message")."($countmessages)";
342 $messagebuttonname = get_string("messages", "message");
344 echo "<td nowrap=\"nowrap\"><form target=\"message\" action=\"../message/index.php\" method=\"get\">";
345 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);\" />";
348 echo "<td nowrap=\"nowrap\"><form target=\"message_$user->id\" action=\"../message/discussion.php\" method=\"get\">";
349 echo "<input type=\"hidden\" name=\"id\" value=\"$user->id\" />";
350 echo "<input type=\"submit\" value=\"".get_string("sendmessage", "message")."\" onclick=\"return openpopup('/message/discussion.php?id=$user->id', 'message_$user->id', 'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500', 0);\" />";
354 // Authorize.net: User Payments
355 if ($course->enrol
== 'authorize' ||
(empty($course->enrol
) && $CFG->enrol
== 'authorize')) {
356 echo "<td nowrap=\"nowrap\"><form action=\"../enrol/authorize/index.php\" method=\"get\">";
357 echo "<input type=\"hidden\" name=\"course\" value=\"$course->id\" />";
358 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
359 echo "<input type=\"submit\" value=\"".get_string('payments')."\" />";
363 echo "</tr></table></div>\n";
365 print_footer($course);
367 /// Functions ///////
369 function print_row($left, $right) {
370 echo "\n<tr><td nowrap=\"nowrap\" align=\"right\" valign=\"top\" class=\"label c0\">$left</td><td align=\"left\" valign=\"top\" class=\"info c1\">$right</td></tr>\n";