*** empty log message ***
[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
8 require_variable($id);
9 require_variable($course);
10
11
12 if (! $user = get_record("user", "id", $id) ) {
13 error("No such user in this course");
14 }
15
16 if (! $course = get_record("course", "id", $course) ) {
17 error("No such course id");
18 }
19
20 if ($course->category) {
21 require_login($course->id);
22 }
23
da3a08d7 24 add_to_log($course->id, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
f9903ed0 25
f1603208 26 if ($student = get_record("user_students", "userid", $user->id, "course", $course->id)) {
27 $user->lastaccess = $student->timeaccess;
28 } else if ($teacher = get_record("user_teachers", "userid", $user->id, "course", $course->id)) {
29 $user->lastaccess = $teacher->timeaccess;
30 }
31
5fde0ca6 32 $fullname = fullname($user, isteacher($course->id));
fa0626c6 33 $personalprofile = get_string("personalprofile");
34 $participants = get_string("participants");
35
f9903ed0 36 if ($course->category) {
fa0626c6 37 print_header("$personalprofile: $fullname", "$personalprofile: $fullname",
1b6a4b1d 38 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
39 <a href=\"index.php?id=$course->id\">$participants</a> -> $fullname",
951b22a8 40 "", "", true, "&nbsp;", navmenu($course));
f9903ed0 41 } else {
02e44e7c 42 print_header("$course->fullname: $personalprofile: $fullname", "$course->fullname",
951b22a8 43 "$fullname", "", "", true, "&nbsp;", navmenu($course));
f9903ed0 44 }
45
603d4c72 46 if ($course->category and ! isguest() ) {
b51e9913 47 if (!isstudent($course->id, $user->id) && !isteacher($course->id, $user->id)) {
fa0626c6 48 print_heading(get_string("notenrolled", "", $fullname));
b51e9913 49 print_footer($course);
50 die;
51 }
8a3b358b 52 }
53
bb09fb11 54 if ($user->deleted) {
55 print_heading(get_string("userdeleted"));
56 }
57
1b6a4b1d 58 echo "<table width=\"80%\" align=\"center\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" class=\"userinfobox\">";
59 echo "<tr>";
60 echo "<td width=\"100\" valign=\"top\" class=\"userinfoboxside\">";
15e4b2ec 61 print_user_picture($user->id, $course->id, $user->picture, true, false, false);
1b6a4b1d 62 echo "</td><td width=\"100%\" bgcolor=\"$THEME->cellcontent\" class=\"userinfoboxcontent\">";
f9903ed0 63
64
65 // Print name and edit button across top
66
1b6a4b1d 67 echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td nowrap>";
68 echo "<h3>$fullname</h3>";
69 echo "</td><td align=\"right\">";
61e96406 70 if (empty($USER->id)) {
71 $currentuser = false;
72 } else {
73 $currentuser = ($user->id == $USER->id);
74 }
75 if (($currentuser and !isguest()) or isadmin()) {
1b6a4b1d 76 echo "<p><form action=edit.php method=get>";
77 echo "<input type=hidden name=id value=\"$id\">";
78 echo "<input type=hidden name=course value=\"$course->id\">";
79 echo "<input type=submit value=\"".get_string("editmyprofile")."\">";
80 echo "</form></p>";
f9903ed0 81 }
1b6a4b1d 82 echo "</td></tr></table>";
f9903ed0 83
84
f9903ed0 85 // Print the description
86
87 if ($user->description) {
d7df380b 88 echo "<p>".format_text(clean_text($user->description, FORMAT_MOODLE))."</p><hr>";
f9903ed0 89 }
90
f9903ed0 91 // Print all the little details in a list
92
1b6a4b1d 93 echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\"";
f9903ed0 94
603d4c72 95 if ($user->city or $user->country) {
f1603208 96 $countries = get_list_of_countries();
5833a6c8 97 print_row(get_string("location").":", "$user->city, ".$countries["$user->country"]);
603d4c72 98 }
f9903ed0 99
100 if (isteacher($course->id)) {
101 if ($user->address) {
fa0626c6 102 print_row(get_string("address").":", "$user->address");
f9903ed0 103 }
104 if ($user->phone1) {
fa0626c6 105 print_row(get_string("phone").":", "$user->phone1");
f9903ed0 106 }
107 if ($user->phone2) {
fa0626c6 108 print_row(get_string("phone").":", "$user->phone2");
f9903ed0 109 }
110 }
111
55e078c0 112 if ($user->maildisplay == 1 or ($user->maildisplay == 2 and $course->category) or isteacher($course->id)) {
43373804 113 print_row(get_string("email").":", obfuscate_mailto($user->email));
55e078c0 114 }
f9903ed0 115
116 if ($user->url) {
1b6a4b1d 117 print_row(get_string("webpage").":", "<a href=\"$user->url\">$user->url</a>");
f9903ed0 118 }
119
120 if ($user->icq) {
088cbaab 121 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></a>");
f9903ed0 122 }
123
9c72928d 124 if (isteacher($course->id)) {
125 if ($mycourses = get_my_courses($user->id)) {
126 $courselisting = '';
127 foreach ($mycourses as $mycourse) {
128 if ($mycourse->visible) {
129 $courselisting .= "<a href=\"$CFG->wwwroot/course/view.php?id=$mycourse->id\">$mycourse->fullname</a>, ";
130 }
131 }
132 print_row(get_string('courses').':', rtrim($courselisting,', '));
133 }
134 }
135
d21fef3a 136 if ($user->lastaccess) {
137 $datestring = userdate($user->lastaccess)."&nbsp (".format_time(time() - $user->lastaccess).")";
138 } else {
97ac9019 139 $datestring = get_string("never");
d21fef3a 140 }
fa0626c6 141 print_row(get_string("lastaccess").":", $datestring);
f9903ed0 142
1b6a4b1d 143 echo "</table>";
f9903ed0 144
1b6a4b1d 145 echo "</td></tr></table>";
f9903ed0 146
3086f3f6 147 $internalpassword = false;
ecac660c 148 if (is_internal_auth()) {
3086f3f6 149 $internalpassword = "$CFG->wwwroot/login/change_password.php";
150 }
151
c888501c 152// Print other functions
1b6a4b1d 153 echo "<center><table align=center><tr>";
61e96406 154 if ($currentuser and !isguest()) {
35d01c7f 155 if ($internalpassword) {
1b6a4b1d 156 echo "<td nowrap><p><form action=\"$internalpassword\" method=get>";
157 echo "<input type=hidden name=id value=\"$course->id\">";
158 echo "<input type=submit value=\"".get_string("changepassword")."\">";
159 echo "</form></p></td>";
61a5e1e9 160 } else if (strlen($CFG->changepassword) > 1) {
1b6a4b1d 161 echo "<td nowrap><p><form action=\"$CFG->changepassword\" method=get>";
162 echo "<input type=submit value=\"".get_string("changepassword")."\">";
163 echo "</form></p></td>";
3086f3f6 164 }
e1ac4272 165 }
ebc3bd2b 166 if ($course->category and
5204d831 167 ((isstudent($course->id) and ($user->id == $USER->id) and !isguest() and $CFG->allowunenroll) or
ebc3bd2b 168 (isteacher($course->id) and isstudent($course->id, $user->id))) ) {
1b6a4b1d 169 echo "<td nowrap><p><form action=\"../course/unenrol.php\" method=get>";
170 echo "<input type=hidden name=id value=\"$course->id\">";
171 echo "<input type=hidden name=user value=\"$user->id\">";
172 echo "<input type=submit value=\"".get_string("unenrolme", "", $course->shortname)."\">";
173 echo "</form></p></td>";
18798c6f 174 }
8f850172 175 if (isteacher($course->id) or ($course->showreports and $USER->id == $user->id)) {
1b6a4b1d 176 echo "<td nowrap><p><form action=\"../course/user.php\" method=get>";
177 echo "<input type=hidden name=id value=\"$course->id\">";
178 echo "<input type=hidden name=user value=\"$user->id\">";
179 echo "<input type=submit value=\"".get_string("activityreport")."\">";
180 echo "</form></p></td>";
8f850172 181 }
6a7585f2 182 if (isteacher($course->id) and ($USER->id != $user->id) and !iscreator($user->id)) {
8f850172 183 echo "<td nowrap><p><form action=\"../course/loginas.php\" method=get>";
184 echo "<input type=hidden name=id value=\"$course->id\">";
185 echo "<input type=hidden name=user value=\"$user->id\">";
186 echo "<input type=submit value=\"".get_string("loginas")."\">";
187 echo "</form></p></td>";
803b2c76 188 }
1b6a4b1d 189 echo "</tr></table></center>\n";
c888501c 190
11b0c469 191 forum_print_user_discussions($course->id, $user->id);
51feb9d5 192
f9903ed0 193 print_footer($course);
194
195/// Functions ///////
196
197function print_row($left, $right) {
8c8c9baf 198 echo "<tr><td nowrap align=right valign=top><p>$left</td><td align=left valign=top><p>$right</p></td></tr>";
f9903ed0 199}
200
201?>