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"));
114 /// Get the hidden field list
115 if (isteacher($course->id
) ||
isadmin()) {
116 $hiddenfields = array(); // teachers and admins are allowed to see everything
118 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields
));
121 /// Print tabs at top
122 /// This same call is made in:
126 $currenttab = 'profile';
129 echo "<table width=\"80%\" align=\"center\" border=\"0\" cellspacing=\"0\" class=\"userinfobox\">";
131 echo "<td width=\"100\" valign=\"top\" class=\"side\">";
132 print_user_picture($user->id
, $course->id
, $user->picture
, true, false, false);
133 echo "</td><td width=\"100%\" class=\"content\">";
135 // Print the description
137 if ($user->description
&& !isset($hiddenfields['description'])) {
138 echo format_text($user->description
, FORMAT_MOODLE
)."<hr />";
141 // Print all the little details in a list
143 echo '<table border="0" cellpadding="0" cellspacing="0" class="list">';
145 if (($user->city
or $user->country
) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) {
147 if ($user->city
&& !isset($hiddenfields['city'])) {
148 $location .= $user->city
;
150 if (!empty($countries[$user->country
]) && !isset($hiddenfields['country'])) {
151 if ($user->city
&& !isset($hiddenfields['country'])) {
154 $countries = get_list_of_countries();
155 $location .= $countries[$user->country
];
157 print_row(get_string("location").":", $location);
160 if (isteacher($course->id
)) {
161 if ($user->address
) {
162 print_row(get_string("address").":", "$user->address");
165 print_row(get_string("phone").":", "$user->phone1");
168 print_row(get_string("phone").":", "$user->phone2");
172 if ($user->maildisplay
== 1 or
173 ($user->maildisplay
== 2 and $course->category
and !isguest()) or
174 isteacher($course->id
)) {
178 if (isteacheredit($course->id
) or $currentuser) { /// Can use the enable/disable email stuff
179 if (!empty($enable)) { /// Recieved a parameter to enable the email address
180 set_field('user', 'emailstop', 0, 'id', $user->id
);
181 $user->emailstop
= 0;
183 if (!empty($disable)) { /// Recieved a parameter to disable the email address
184 set_field('user', 'emailstop', 1, 'id', $user->id
);
185 $user->emailstop
= 1;
189 if (isteacheredit($course->id
)) { /// Can use the enable/disable email stuff
190 if ($user->emailstop
) {
191 $switchparam = 'enable';
192 $switchtitle = get_string('emaildisable');
193 $switchclick = get_string('emailenableclick');
194 $switchpix = 'emailno.gif';
196 $switchparam = 'disable';
197 $switchtitle = get_string('emailenable');
198 $switchclick = get_string('emaildisableclick');
199 $switchpix = 'email.gif';
201 $emailswitch = " <a title=\"$switchclick\" ".
202 "href=\"view.php?id=$user->id&course=$course->id&$switchparam=1\">".
203 "<img border=\"0\" width=\"11\" height=\"11\" src=\"$CFG->pixpath/t/$switchpix\" alt=\"\" /></a>";
205 } else if ($currentuser) { /// Can only re-enable an email this way
206 if ($user->emailstop
) { // Include link that tells how to re-enable their email
207 $switchparam = 'enable';
208 $switchtitle = get_string('emaildisable');
209 $switchclick = get_string('emailenableclick');
211 $emailswitch = " (<a title=\"$switchclick\" ".
212 "href=\"view.php?id=$user->id&course=$course->id&enable=1\">$switchtitle</a>)";
216 print_row(get_string("email").":", obfuscate_mailto($user->email
, '', $user->emailstop
)."$emailswitch");
219 if ($user->url
&& !isset($hiddenfields['webpage'])) {
220 print_row(get_string("webpage").":", "<a href=\"$user->url\">$user->url</a>");
223 if ($user->icq
&& !isset($hiddenfields['icqnumber'])) {
224 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>");
227 if ($user->skype
&& !isset($hiddenfields['skypeid'])) {
228 print_row(get_string('skypeid').':','<a href="callto:'.urlencode($user->skype
).'">'.s($user->skype
).
229 ' <img src="http://mystatus.skype.com/smallicon/'.urlencode($user->skype
).'" alt="status" '.
230 ' height="16" width="16" /></a>');
232 if ($user->yahoo
&& !isset($hiddenfields['yahooid'])) {
233 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>");
235 if ($user->aim
&& !isset($hiddenfields['aimid'])) {
236 print_row(get_string('aimid').':', '<a href="aim:goim?screenname='.s($user->aim
).'">'.s($user->aim
).'</a>');
238 if ($user->msn
&& !isset($hiddenfields['msnid'])) {
239 print_row(get_string('msnid').':', s($user->msn
));
242 if (isteacher($course->id
)) {
243 if ($mycourses = get_my_courses($user->id
)) {
245 foreach ($mycourses as $mycourse) {
246 if ($mycourse->visible
and $mycourse->category
) {
247 if ($mycourse->id
!= $course->id
){
248 $courselisting .= "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$mycourse->id\">$mycourse->fullname</a>, ";
251 $courselisting .= "$mycourse->fullname, ";
255 print_row(get_string('courses').':', rtrim($courselisting,', '));
259 if (!isset($hiddenfields['lastaccess'])) {
260 if ($user->lastaccess
) {
261 $datestring = userdate($user->lastaccess
)." (".format_time(time() - $user->lastaccess
).")";
263 $datestring = get_string("never");
265 print_row(get_string("lastaccess").":", $datestring);
270 $isseparategroups = ($course->groupmode
== SEPARATEGROUPS
and $course->groupmodeforce
and
271 !isteacheredit($course->id
));
272 if (!$isseparategroups){
273 if ($usergroups = user_group($course->id
, $user->id
)){
275 foreach ($usergroups as $group){
276 $groupstr .= ' <a href="'.$CFG->wwwroot
.'/user/index.php?id='.$course->id
.'&group='.$group->id
.'">'.$group->name
.'</a>,';
278 print_row(get_string("group").":", rtrim($groupstr, ', '));
281 /// End of printing groups
285 echo "</td></tr></table>";
287 $internalpassword = false;
288 if (is_internal_auth($user->auth
) or (!empty($CFG->{'auth_'.$user->auth
.'_stdchangepassword'}))) {
289 if (empty($CFG->loginhttps
)) {
290 $internalpassword = "$CFG->wwwroot/login/change_password.php";
292 $internalpassword = str_replace('http:','https:',$CFG->wwwroot
.'/login/change_password.php');
296 // Print other functions
297 echo '<div class="buttons"><table align="center"><tr>';
299 if ($currentuser and !isguest() and !is_restricted_user($USER->username
)) {
300 if ($internalpassword ) {
301 echo "<td nowrap=\"nowrap\"><form action=\"$internalpassword\" method=\"get\">";
302 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
303 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
305 } else if ( strlen($CFG->{'auth_'.$user->auth
.'_changepasswordurl'}) > 1 ) {
306 echo "<td nowrap=\"nowrap\"><form action=\"".$CFG->{'auth_'.$user->auth
.'_changepasswordurl'}."\" method=\"get\">";
307 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
311 if ($course->category
and
312 ((isstudent($course->id
) and ($user->id
== $USER->id
) and !isguest() and $CFG->allowunenroll
) or
313 (isteacheredit($course->id
) and isstudent($course->id
, $user->id
))) ) {
314 echo "<td nowrap=\"nowrap\"><form action=\"../course/unenrol.php\" method=\"get\" />";
315 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
316 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
317 echo "<input type=\"submit\" value=\"".get_string("unenrolme", "", $course->shortname
)."\">";
320 /* if (isteacher($course->id) or ($course->showreports and $USER->id == $user->id)) {
321 echo "<td nowrap=\"nowrap\"><form action=\"../course/user.php\" method=\"get\">";
322 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
323 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
324 echo "<input type=\"submit\" value=\"".get_string("activityreport")."\" />";
328 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
))) {
329 echo "<td nowrap=\"nowrap\"><form action=\"../course/loginas.php\" method=\"get\">";
330 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
331 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
332 echo "<input type=\"submit\" value=\"".get_string("loginas")."\" />";
335 if (!empty($CFG->messaging
) and !isguest()) {
336 if (!empty($USER->id
) and ($USER->id
== $user->id
)) {
337 if ($countmessages = count_records('message', 'useridto', $user->id
)) {
338 $messagebuttonname = get_string("messages", "message")."($countmessages)";
340 $messagebuttonname = get_string("messages", "message");
342 echo "<td nowrap=\"nowrap\"><form target=\"message\" action=\"../message/index.php\" method=\"get\">";
343 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);\" />";
346 echo "<td nowrap=\"nowrap\"><form target=\"message_$user->id\" action=\"../message/discussion.php\" method=\"get\">";
347 echo "<input type=\"hidden\" name=\"id\" value=\"$user->id\" />";
348 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);\" />";
352 // Authorize.net: User Payments
353 if ($course->enrol
== 'authorize' ||
(empty($course->enrol
) && $CFG->enrol
== 'authorize')) {
354 echo "<td nowrap=\"nowrap\"><form action=\"../enrol/authorize/index.php\" method=\"get\">";
355 echo "<input type=\"hidden\" name=\"course\" value=\"$course->id\" />";
356 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
357 echo "<input type=\"submit\" value=\"".get_string('payments')."\" />";
361 echo "</tr></table></div>\n";
363 print_footer($course);
365 /// Functions ///////
367 function print_row($left, $right) {
368 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";