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
12 if (!empty($SESSION->wantsurl
)) {
13 $wantsurl = $SESSION->wantsurl
;
14 unset($SESSION->wantsurl
);
18 if (empty($id)) { // See your own profile by default
23 if (! $user = get_record("user", "id", $id) ) {
24 error("No such user in this course");
27 if (! $course = get_record("course", "id", $course) ) {
28 error("No such course id");
31 if ($course->category
) {
32 require_login($course->id
);
33 } else if ($CFG->forcelogin
or !empty($CFG->forceloginforprofiles
)) {
35 redirect("$CFG->wwwroot/login/index.php");
40 add_to_log($course->id
, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
42 if ($course->id
!= SITEID
) {
43 if ($student = get_record("user_students", "userid", $user->id
, "course", $course->id
)) {
44 $user->lastaccess
= $student->timeaccess
;
45 } else if ($teacher = get_record("user_teachers", "userid", $user->id
, "course", $course->id
)) {
46 $user->lastaccess
= $teacher->timeaccess
;
50 $fullname = fullname($user, isteacher($course->id
));
51 $personalprofile = get_string("personalprofile");
52 $participants = get_string("participants");
54 if (empty($USER->id
)) {
57 $currentuser = ($user->id
== $USER->id
);
60 if (groupmode($course) == SEPARATEGROUPS
and !isteacheredit($course->id
)) { // Groups must be kept separate
63 if (!$currentuser && !isteacheredit($course->id
, $user->id
) && !ismember(mygroupid($course->id
), $user->id
)) {
64 print_header("$personalprofile: ", "$personalprofile: ",
65 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
66 <a href=\"index.php?id=$course->id\">$participants</a>",
67 "", "", true, " ", navmenu($course));
68 error(get_string("groupnotamember"), "../course/view.php?id=$course->id");
72 if ($course->id
== SITEID
and !$currentuser) { // To reduce possibility of "browsing" userbase at site level
73 if (!isteacherinanycourse() and !isteacherinanycourse($user->id
) ) { // Teachers can browse and be browsed at site level
74 print_header("$personalprofile: ", "$personalprofile: ",
75 "<a href=\"index.php?id=$course->id\">$participants</a>",
76 "", "", true, " ", navmenu($course));
77 print_heading(get_string('usernotavailable', 'error'));
78 print_footer($course);
84 if ($course->category
) {
85 print_header("$personalprofile: $fullname", "$personalprofile: $fullname",
86 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
87 <a href=\"index.php?id=$course->id\">$participants</a> -> $fullname",
88 "", "", true, " ", navmenu($course));
90 print_header("$course->fullname: $personalprofile: $fullname", "$course->fullname",
91 "$fullname", "", "", true, " ", navmenu($course));
95 if ($course->category
and ! isguest() ) { // Need to have access to a course to see that info
96 if (!isstudent($course->id
, $user->id
) && !isteacher($course->id
, $user->id
)) {
97 print_heading(get_string("notenrolled", "", $fullname));
98 print_footer($course);
103 if ($user->deleted
) {
104 print_heading(get_string("userdeleted"));
108 /// Print tabs at top
109 /// This same call is made in:
113 $currenttab = 'profile';
118 echo "<table width=\"80%\" align=\"center\" border=\"0\" cellspacing=\"0\" class=\"userinfobox\">";
120 echo "<td width=\"100\" valign=\"top\" class=\"side\">";
121 print_user_picture($user->id
, $course->id
, $user->picture
, true, false, false);
122 echo "</td><td width=\"100%\" class=\"content\">";
124 // Print the description
126 if ($user->description
) {
127 echo format_text($user->description
, FORMAT_MOODLE
)."<hr />";
130 // Print all the little details in a list
132 echo '<table border="0" cellpadding="0" cellspacing="0" class="list">';
134 if ($user->city
or $user->country
) {
135 $countries = get_list_of_countries();
136 print_row(get_string("location").":", "$user->city, ".$countries["$user->country"]);
139 if (isteacher($course->id
)) {
140 if ($user->address
) {
141 print_row(get_string("address").":", "$user->address");
144 print_row(get_string("phone").":", "$user->phone1");
147 print_row(get_string("phone").":", "$user->phone2");
151 if ($user->maildisplay
== 1 or
152 ($user->maildisplay
== 2 and $course->category
and !isguest()) or
153 isteacher($course->id
)) {
157 if (isteacheredit($course->id
) or $currentuser) { /// Can use the enable/disable email stuff
158 if (!empty($_GET['enable'])) { /// Recieved a parameter to enable the email address
159 set_field('user', 'emailstop', 0, 'id', $user->id
);
160 $user->emailstop
= 0;
162 if (!empty($_GET['disable'])) { /// Recieved a parameter to disable the email address
163 set_field('user', 'emailstop', 1, 'id', $user->id
);
164 $user->emailstop
= 1;
168 if (isteacheredit($course->id
)) { /// Can use the enable/disable email stuff
169 if ($user->emailstop
) {
170 $switchparam = 'enable';
171 $switchtitle = get_string('emaildisable');
172 $switchclick = get_string('emailenableclick');
173 $switchpix = 'emailno.gif';
175 $switchparam = 'disable';
176 $switchtitle = get_string('emailenable');
177 $switchclick = get_string('emaildisableclick');
178 $switchpix = 'email.gif';
180 $emailswitch = " <a title=\"$switchclick\" ".
181 "href=\"view.php?id=$user->id&course=$course->id&$switchparam=1\">".
182 "<img border=\"0\" width=\"11\" height=\"11\" src=\"$CFG->pixpath/t/$switchpix\" alt=\"\" /></a>";
184 } else if ($currentuser) { /// Can only re-enable an email this way
185 if ($user->emailstop
) { // Include link that tells how to re-enable their email
186 $switchparam = 'enable';
187 $switchtitle = get_string('emaildisable');
188 $switchclick = get_string('emailenableclick');
190 $emailswitch = " (<a title=\"$switchclick\" ".
191 "href=\"view.php?id=$user->id&course=$course->id&enable=1\">$switchtitle</a>)";
195 print_row(get_string("email").":", obfuscate_mailto($user->email
, '', $user->emailstop
)."$emailswitch");
199 print_row(get_string("webpage").":", "<a href=\"$user->url\">$user->url</a>");
203 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>");
207 print_row(get_string('skypeid').':','<a href="callto:'.urlencode($user->skype
).'">'.s($user->skype
).'</a>');
210 print_row(get_string('yahooid').':', '<a href="http://edit.yahoo.com/config/send_webmesg?.target='.s($user->yahoo
).'&.src=pg">'.s($user->yahoo
).'</a>');
213 print_row(get_string('aimid').':', '<a href="aim:goim?screenname='.s($user->aim
).'">'.s($user->aim
).'</a>');
216 print_row(get_string('msnid').':', s($user->msn
));
219 if (isteacher($course->id
)) {
220 if ($mycourses = get_my_courses($user->id
)) {
222 foreach ($mycourses as $mycourse) {
223 if ($mycourse->visible
and $mycourse->category
) {
224 $courselisting .= "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$mycourse->id\">$mycourse->fullname</a>, ";
227 print_row(get_string('courses').':', rtrim($courselisting,', '));
231 if ($user->lastaccess
) {
232 $datestring = userdate($user->lastaccess
)." (".format_time(time() - $user->lastaccess
).")";
234 $datestring = get_string("never");
236 print_row(get_string("lastaccess").":", $datestring);
240 echo "</td></tr></table>";
243 $internalpassword = false;
244 if (is_internal_auth() or (!empty($CFG->{'auth_'.$USER->auth
.'_stdchangepassword'}))) {
245 if (empty($CFG->loginhttps
)) {
246 $internalpassword = "$CFG->wwwroot/login/change_password.php";
248 $internalpassword = str_replace('http','https',$CFG->wwwroot
.'/login/change_password.php');
252 // Print other functions
253 echo '<div class="buttons"><table align="center"><tr>';
254 if ($currentuser and !isguest()) {
255 if ($internalpassword ) {
256 echo "<td nowrap=\"nowrap\"><form action=\"$internalpassword\" method=\"get\">";
257 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
258 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
260 } else if ( strlen($CFG->changepassword
) > 1 ) {
261 echo "<td nowrap=\"nowrap\"><form action=\"$CFG->changepassword\" method=\"get\">";
262 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
266 if ($course->category
and
267 ((isstudent($course->id
) and ($user->id
== $USER->id
) and !isguest() and $CFG->allowunenroll
) or
268 (isteacheredit($course->id
) and isstudent($course->id
, $user->id
))) ) {
269 echo "<td nowrap=\"nowrap\"><form action=\"../course/unenrol.php\" method=\"get\" />";
270 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
271 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
272 echo "<input type=\"submit\" value=\"".get_string("unenrolme", "", $course->shortname
)."\">";
275 /* if (isteacher($course->id) or ($course->showreports and $USER->id == $user->id)) {
276 echo "<td nowrap=\"nowrap\"><form action=\"../course/user.php\" method=\"get\">";
277 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
278 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
279 echo "<input type=\"submit\" value=\"".get_string("activityreport")."\" />";
283 if ((isadmin() and !isadmin($user->id
)) or (isteacher($course->id
) and ($USER->id
!= $user->id
) and !iscreator($user->id
))) {
284 echo "<td nowrap=\"nowrap\"><form action=\"../course/loginas.php\" method=\"get\">";
285 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
286 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
287 echo "<input type=\"submit\" value=\"".get_string("loginas")."\" />";
290 if (!empty($CFG->messaging
) and !isguest()) {
291 if (!empty($USER->id
) and ($USER->id
== $user->id
)) {
292 if ($countmessages = count_records('message', 'useridto', $user->id
)) {
293 $messagebuttonname = get_string("messages", "message")."($countmessages)";
295 $messagebuttonname = get_string("messages", "message");
297 echo "<td nowrap=\"nowrap\"><form target=\"message\" action=\"../message/index.php\" method=\"get\">";
298 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);\" />";
301 echo "<td nowrap=\"nowrap\"><form target=\"message_$user->id\" action=\"../message/discussion.php\" method=\"get\">";
302 echo "<input type=\"hidden\" name=\"id\" value=\"$user->id\" />";
303 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);\" />";
308 echo "</tr></table></div>\n";
311 print_footer($course);
313 /// Functions ///////
315 function print_row($left, $right) {
316 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";