New user tabs from Shane and myself ... these bring together the
[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
e41ddc4b 8 optional_variable($id);
9 optional_variable($course);
cadb96f2 10 optional_variable($enable, "");
11 optional_variable($disable, "");
f9903ed0 12
20fde7b1 13 if (!empty($SESSION->wantsurl)) {
14 $wantsurl = $SESSION->wantsurl;
15 unset($SESSION->wantsurl);
16 redirect($wantsurl);
17 }
18
e41ddc4b 19 if (empty($id)) { // See your own profile by default
20 require_login();
21 $id = $USER->id;
22 }
23
24 if (empty($course)) { // See it at site level by default
25 $course = SITEID;
26 }
f9903ed0 27
28 if (! $user = get_record("user", "id", $id) ) {
29 error("No such user in this course");
30 }
31
32 if (! $course = get_record("course", "id", $course) ) {
33 error("No such course id");
34 }
35
555b8513 36 if ($course->category) {
f9903ed0 37 require_login($course->id);
ab1324e4 38 } else if ($CFG->forcelogin or !empty($CFG->forceloginforprofiles)) {
555b8513 39 if (isguest()) {
40 redirect("$CFG->wwwroot/login/index.php");
41 }
42 require_login();
f9903ed0 43 }
44
8f0cd6ef 45 add_to_log($course->id, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
f9903ed0 46
c6c558d7 47 if ($course->id != SITEID) {
48 if ($student = get_record("user_students", "userid", $user->id, "course", $course->id)) {
49 $user->lastaccess = $student->timeaccess;
50 } else if ($teacher = get_record("user_teachers", "userid", $user->id, "course", $course->id)) {
51 $user->lastaccess = $teacher->timeaccess;
52 }
f1603208 53 }
54
5fde0ca6 55 $fullname = fullname($user, isteacher($course->id));
fa0626c6 56 $personalprofile = get_string("personalprofile");
57 $participants = get_string("participants");
58
a9cbf8cc 59 if (empty($USER->id)) {
60 $currentuser = false;
61 } else {
62 $currentuser = ($user->id == $USER->id);
63 }
64
b1d530d2 65 if (groupmode($course) == SEPARATEGROUPS and !isteacheredit($course->id)) { // Groups must be kept separate
66 require_login();
67
ccfd6c83 68 if (!$currentuser && !isteacheredit($course->id, $user->id) && !ismember(mygroupid($course->id), $user->id)) {
b1d530d2 69 print_header("$personalprofile: ", "$personalprofile: ",
70 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
71 <a href=\"index.php?id=$course->id\">$participants</a>",
72 "", "", true, "&nbsp;", navmenu($course));
73 error(get_string("groupnotamember"), "../course/view.php?id=$course->id");
dd780a3b 74 }
75 }
76
1610aa49 77 if ($course->id == SITEID and !$currentuser) { // To reduce possibility of "browsing" userbase at site level
9407d456 78 if (!isteacherinanycourse() and !isteacherinanycourse($user->id) ) { // Teachers can browse and be browsed at site level
f5ecf2e9 79 print_header("$personalprofile: ", "$personalprofile: ",
80 "<a href=\"index.php?id=$course->id\">$participants</a>",
81 "", "", true, "&nbsp;", navmenu($course));
82 print_heading(get_string('usernotavailable', 'error'));
83 print_footer($course);
84 die;
85 }
86 }
87
88
f9903ed0 89 if ($course->category) {
ab1324e4 90 print_header("$personalprofile: $fullname", "$personalprofile: $fullname",
91 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
1b6a4b1d 92 <a href=\"index.php?id=$course->id\">$participants</a> -> $fullname",
951b22a8 93 "", "", true, "&nbsp;", navmenu($course));
f9903ed0 94 } else {
ab1324e4 95 print_header("$course->fullname: $personalprofile: $fullname", "$course->fullname",
951b22a8 96 "$fullname", "", "", true, "&nbsp;", navmenu($course));
f9903ed0 97 }
98
b1d530d2 99
f5ecf2e9 100 if ($course->category and ! isguest() ) { // Need to have access to a course to see that info
b51e9913 101 if (!isstudent($course->id, $user->id) && !isteacher($course->id, $user->id)) {
fa0626c6 102 print_heading(get_string("notenrolled", "", $fullname));
b51e9913 103 print_footer($course);
104 die;
105 }
8a3b358b 106 }
107
bb09fb11 108 if ($user->deleted) {
109 print_heading(get_string("userdeleted"));
110 }
111
f9903ed0 112
f9a0ea69 113/// Print tabs at top
114/// This same call is made in:
115/// /user/view.php
116/// /user/edit.php
117/// /course/user.php
118 $currenttab = 'profile';
119 include('tabs.php');
f9903ed0 120
f9903ed0 121
f9903ed0 122
f9a0ea69 123 echo "<table width=\"80%\" align=\"center\" border=\"0\" cellspacing=\"0\" class=\"userinfobox\">";
124 echo "<tr>";
125 echo "<td width=\"100\" valign=\"top\" class=\"side\">";
126 print_user_picture($user->id, $course->id, $user->picture, true, false, false);
127 echo "</td><td width=\"100%\" class=\"content\">";
f9903ed0 128
f9903ed0 129 // Print the description
130
131 if ($user->description) {
7c7d9120 132 echo format_text($user->description, FORMAT_MOODLE)."<hr />";
f9903ed0 133 }
134
f9903ed0 135 // Print all the little details in a list
136
f9a0ea69 137 echo '<table border="0" cellpadding="0" cellspacing="0" class="list">';
f9903ed0 138
603d4c72 139 if ($user->city or $user->country) {
f1603208 140 $countries = get_list_of_countries();
5833a6c8 141 print_row(get_string("location").":", "$user->city, ".$countries["$user->country"]);
603d4c72 142 }
f9903ed0 143
144 if (isteacher($course->id)) {
145 if ($user->address) {
fa0626c6 146 print_row(get_string("address").":", "$user->address");
f9903ed0 147 }
148 if ($user->phone1) {
fa0626c6 149 print_row(get_string("phone").":", "$user->phone1");
f9903ed0 150 }
151 if ($user->phone2) {
fa0626c6 152 print_row(get_string("phone").":", "$user->phone2");
f9903ed0 153 }
154 }
155
ab1324e4 156 if ($user->maildisplay == 1 or
157 ($user->maildisplay == 2 and $course->category and !isguest()) or
d0ec93fb 158 isteacher($course->id)) {
cadb96f2 159
c6c558d7 160 $emailswitch = '';
161
cadb96f2 162 if (isteacheredit($course->id) or $currentuser) { /// Can use the enable/disable email stuff
c6c558d7 163 if (!empty($_GET['enable'])) { /// Recieved a parameter to enable the email address
cadb96f2 164 set_field('user', 'emailstop', 0, 'id', $user->id);
165 $user->emailstop = 0;
166 }
c6c558d7 167 if (!empty($_GET['disable'])) { /// Recieved a parameter to disable the email address
cadb96f2 168 set_field('user', 'emailstop', 1, 'id', $user->id);
169 $user->emailstop = 1;
170 }
c6c558d7 171 }
172
173 if (isteacheredit($course->id)) { /// Can use the enable/disable email stuff
cadb96f2 174 if ($user->emailstop) {
175 $switchparam = 'enable';
176 $switchtitle = get_string('emaildisable');
dee51de2 177 $switchclick = get_string('emailenableclick');
fa92b42f 178 $switchpix = 'emailno.gif';
cadb96f2 179 } else {
180 $switchparam = 'disable';
181 $switchtitle = get_string('emailenable');
dee51de2 182 $switchclick = get_string('emaildisableclick');
fa92b42f 183 $switchpix = 'email.gif';
cadb96f2 184 }
c6c558d7 185 $emailswitch = "&nbsp<a title=\"$switchclick\" ".
186 "href=\"view.php?id=$user->id&course=$course->id&$switchparam=1\">".
187 "<img border=\"0\" width=11 height=11 src=\"$CFG->pixpath/t/$switchpix\"></a>";
188
189 } else if ($currentuser) { /// Can only re-enable an email this way
190 if ($user->emailstop) { // Include link that tells how to re-enable their email
191 $switchparam = 'enable';
192 $switchtitle = get_string('emaildisable');
193 $switchclick = get_string('emailenableclick');
194
195 $emailswitch = "&nbsp(<a title=\"$switchclick\" ".
196 "href=\"view.php?id=$user->id&course=$course->id&enable=1\">$switchtitle</a>)";
197 }
cadb96f2 198 }
199
200 print_row(get_string("email").":", obfuscate_mailto($user->email, '', $user->emailstop)."$emailswitch");
55e078c0 201 }
f9903ed0 202
203 if ($user->url) {
1b6a4b1d 204 print_row(get_string("webpage").":", "<a href=\"$user->url\">$user->url</a>");
f9903ed0 205 }
206
207 if ($user->icq) {
766d2bf3 208 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&amp;img=5\" width=\"18\" height=\"18\" border=\"0\" alt=\"\" /></a>");
209 }
210
211 if ($user->skype) {
212 print_row(get_string('skypeid').':','<a href="callto:'.urlencode($user->skype).'">'.s($user->skype).'</a>');
213 }
214 if ($user->yahoo) {
772fa490 215 print_row(get_string('yahooid').':', '<a href="http://edit.yahoo.com/config/send_webmesg?.target='.s($user->yahoo).'&amp;.src=pg">'.s($user->yahoo).'</a>');
766d2bf3 216 }
217 if ($user->aim) {
772fa490 218 print_row(get_string('aimid').':', '<a href="aim:goim?screenname='.s($user->aim).'">'.s($user->aim).'</a>');
766d2bf3 219 }
220 if ($user->msn) {
221 print_row(get_string('msnid').':', s($user->msn));
f9903ed0 222 }
223
9c72928d 224 if (isteacher($course->id)) {
225 if ($mycourses = get_my_courses($user->id)) {
226 $courselisting = '';
227 foreach ($mycourses as $mycourse) {
d552efce 228 if ($mycourse->visible and $mycourse->category) {
839f2456 229 $courselisting .= "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$mycourse->id\">$mycourse->fullname</a>, ";
9c72928d 230 }
231 }
232 print_row(get_string('courses').':', rtrim($courselisting,', '));
233 }
234 }
235
d21fef3a 236 if ($user->lastaccess) {
237 $datestring = userdate($user->lastaccess)."&nbsp (".format_time(time() - $user->lastaccess).")";
238 } else {
97ac9019 239 $datestring = get_string("never");
d21fef3a 240 }
fa0626c6 241 print_row(get_string("lastaccess").":", $datestring);
f9903ed0 242
1b6a4b1d 243 echo "</table>";
f9903ed0 244
1b6a4b1d 245 echo "</td></tr></table>";
f9903ed0 246
7c7d9120 247
3086f3f6 248 $internalpassword = false;
f8c883ce 249 if (is_internal_auth() or (!empty($CFG->{'auth_'.$USER->auth.'_stdchangepassword'}))) {
250 if (empty($CFG->loginhttps)) {
251 $internalpassword = "$CFG->wwwroot/login/change_password.php";
ab1324e4 252 } else {
253 $internalpassword = str_replace('http','https',$CFG->wwwroot.'/login/change_password.php');
254 }
3086f3f6 255 }
256
c888501c 257// Print other functions
173dbed4 258 echo '<div class="buttons"><table align="center"><tr>';
61e96406 259 if ($currentuser and !isguest()) {
e09ecb06 260 if ($internalpassword ) {
09e8a2f8 261 echo "<td nowrap=\"nowrap\"><form action=\"$internalpassword\" method=\"get\">";
031c49fa 262 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
263 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
09e8a2f8 264 echo "</form></td>";
e09ecb06 265 } else if ( strlen($CFG->changepassword) > 1 ) {
09e8a2f8 266 echo "<td nowrap=\"nowrap\"><form action=\"$CFG->changepassword\" method=\"get\">";
031c49fa 267 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
09e8a2f8 268 echo "</form></td>";
3086f3f6 269 }
e1ac4272 270 }
ab1324e4 271 if ($course->category and
272 ((isstudent($course->id) and ($user->id == $USER->id) and !isguest() and $CFG->allowunenroll) or
f7f2ff6d 273 (isteacheredit($course->id) and isstudent($course->id, $user->id))) ) {
09e8a2f8 274 echo "<td nowrap=\"nowrap\"><form action=\"../course/unenrol.php\" method=\"get\" />";
031c49fa 275 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
276 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
277 echo "<input type=\"submit\" value=\"".get_string("unenrolme", "", $course->shortname)."\">";
09e8a2f8 278 echo "</form></td>";
18798c6f 279 }
f9a0ea69 280/* if (isteacher($course->id) or ($course->showreports and $USER->id == $user->id)) {
09e8a2f8 281 echo "<td nowrap=\"nowrap\"><form action=\"../course/user.php\" method=\"get\">";
031c49fa 282 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
283 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
284 echo "<input type=\"submit\" value=\"".get_string("activityreport")."\" />";
09e8a2f8 285 echo "</form></td>";
8f850172 286 }
f9a0ea69 287*/
37d83d99 288 if ((isadmin() and !isadmin($user->id)) or (isteacher($course->id) and ($USER->id != $user->id) and !iscreator($user->id))) {
09e8a2f8 289 echo "<td nowrap=\"nowrap\"><form action=\"../course/loginas.php\" method=\"get\">";
031c49fa 290 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
291 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
292 echo "<input type=\"submit\" value=\"".get_string("loginas")."\" />";
09e8a2f8 293 echo "</form></td>";
803b2c76 294 }
a9d9b46a 295 if (!empty($CFG->messaging) and !isguest()) {
f9a0ea69 296 if (!empty($USER->id) and ($USER->id == $user->id)) {
cdf39255 297 if ($countmessages = count_records('message', 'useridto', $user->id)) {
298 $messagebuttonname = get_string("messages", "message")."($countmessages)";
299 } else {
300 $messagebuttonname = get_string("messages", "message");
301 }
302 echo "<td nowrap=\"nowrap\"><form target=\"message\" action=\"../message/index.php\" method=\"get\">";
303 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);\" />";
304 echo "</form></td>";
2fc1b1fe 305 } else {
cdf39255 306 echo "<td nowrap=\"nowrap\"><form target=\"message_$user->id\" action=\"../message/user.php\" method=\"get\">";
307 echo "<input type=\"hidden\" name=\"id\" value=\"$user->id\" />";
308 echo "<input type=\"submit\" value=\"".get_string("sendmessage", "message")."\" onclick=\"return openpopup('/message/user.php?id=$user->id', 'message_$user->id', 'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500', 0);\" />";
309 echo "</form></td>";
2fc1b1fe 310 }
2fc1b1fe 311 }
7c7d9120 312 echo "<td></td>";
173dbed4 313 echo "</tr></table></div>\n";
c888501c 314
51feb9d5 315
f9903ed0 316 print_footer($course);
317
318/// Functions ///////
319
320function print_row($left, $right) {
f9a0ea69 321 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";
f9903ed0 322}
323
324?>