MDL-22061 get_mimetype_description() does not rely on get_string() returning square...
[moodle.git] / user / view.php
CommitLineData
ce221eb5 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * Display profile for a particular user
20 *
21 * @copyright 1999 Martin Dougiamas http://dougiamas.com
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @package user
24 */
25
26require_once("../config.php");
27require_once($CFG->dirroot.'/user/profile/lib.php');
28require_once($CFG->dirroot.'/tag/lib.php');
29
4f0c2d00
PS
30$id = optional_param('id', 0, PARAM_INT); // user id
31$courseid = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site)
32$enable = optional_param('enable', 0, PARAM_BOOL); // enable email
33$disable = optional_param('disable', 0, PARAM_BOOL); // disable email
ce221eb5 34
35if (empty($id)) { // See your own profile by default
36 require_login();
37 $id = $USER->id;
38}
f9903ed0 39
a6855934 40$url = new moodle_url('/user/view.php', array('id'=>$id));
4f0c2d00
PS
41if ($courseid != SITEID) {
42 $url->param('course', $courseid);
ce221eb5 43}
44$PAGE->set_url($url);
e41ddc4b 45
4f0c2d00
PS
46$user = $DB->get_record('user', array('id'=>$id), '*', MUST_EXIST);
47$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
f9903ed0 48
ce221eb5 49$systemcontext = get_context_instance(CONTEXT_SYSTEM);
4f0c2d00 50$usercontext = get_context_instance(CONTEXT_USER, $user->id, MUST_EXIST);
1deff123 51
4f0c2d00
PS
52// Require login first
53if (isguestuser($user)) {
54 // can not view profile of guest - thre is nothing to see there
55 print_error('invaliduserid');
ce221eb5 56}
bad59bc0 57
4f0c2d00
PS
58$currentuser = ($user->id == $USER->id);
59
ce221eb5 60if ($course->id == SITEID) {
4f0c2d00
PS
61 $isfrontpage = true;
62 // do not use frontpage course context because there is no frontpage profile, instead it is the site profile
63 $coursecontext = $systemcontext;
ce221eb5 64} else {
4f0c2d00
PS
65 $isfrontpage = false;
66 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
ce221eb5 67}
0be6f678 68
ce221eb5 69$PAGE->set_context($usercontext);
cb4f6179 70
4f0c2d00
PS
71$isparent = false;
72if ($isfrontpage) {
73 if (!empty($CFG->forceloginforprofiles)) {
74 require_login();
75 if (isguestuser()) {
76 redirect(get_login_url());
77 }
78 } else if (!empty($CFG->forcelogin)) {
79 require_login();
7034b46c 80 }
0be6f678 81
4f0c2d00
PS
82} else if (!$currentuser
83 and $DB->record_exists('role_assignments', array('userid'=>$USER->id, 'contextid'=>$usercontext->id))
84 and has_capability('moodle/user:viewdetails', $usercontext)) {
85 // TODO: very ugly hack - do not force "parents" to enrol into course their child is enrolled in,
86 // this way they may access the profile where they get overview of grades and child activity in course,
87 // please note this is just a guess!
ce221eb5 88 require_login();
4f0c2d00
PS
89 $isparent = true;
90
91} else {
92 // normal course
93 require_login($course);
94 // what to do with users temporary accessing this course? shoudl they see the details?
ce221eb5 95}
f9903ed0 96
4f0c2d00 97
ce221eb5 98$strpersonalprofile = get_string('personalprofile');
99$strparticipants = get_string("participants");
100$struser = get_string("user");
f9903ed0 101
ce221eb5 102$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $coursecontext));
f1603208 103
4f0c2d00
PS
104/// Now test the actual capabilities and enrolment in course
105if ($currentuser) {
106 // me
107 if (!$isfrontpage and !is_enrolled($coursecontext) and !is_viewing($coursecontext)) { // Need to have full access to a course to see the rest of own info
108 echo $OUTPUT->header();
109 echo $OUTPUT->heading(get_string('notenrolled', '', $fullname));
110 if (!empty($_SERVER['HTTP_REFERER'])) {
111 echo $OUTPUT->continue_button($_SERVER['HTTP_REFERER']);
112 }
113 echo $OUTPUT->footer();
114 die;
115 }
caa8363f 116
4f0c2d00
PS
117} else {
118 // somebody else
ce221eb5 119 $PAGE->set_title("$strpersonalprofile: ");
120 $PAGE->set_heading("$strpersonalprofile: ");
caa8363f 121
4f0c2d00
PS
122 if ($isfrontpage) {
123 // Reduce possibility of "browsing" userbase at site level
124 if (!empty($CFG->forceloginforprofiles) and !has_capability('moodle/user:viewdetails', $usercontext) and !has_coursemanager_role($user->id)) {
125 // Course managers can be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
ce221eb5 126 $PAGE->navbar->add($struser);
127 echo $OUTPUT->header();
128 echo $OUTPUT->heading(get_string('usernotavailable', 'error'));
129 echo $OUTPUT->footer();
130 exit;
131 }
4f0c2d00
PS
132
133 } else {
134 // check course level capabilities
135 if (!has_capability('moodle/user:viewdetails', $coursecontext) && // normal enrolled user or mnager
136 !has_capability('moodle/user:viewdetails', $usercontext)) { // usually parent
ce221eb5 137 print_error('cannotviewprofile');
138 }
8005d470 139
4f0c2d00
PS
140 if (!is_enrolled($coursecontext, $user->id)) {
141 // TODO: the only potential problem is that managers and inspectors might post in forum, but the link
142 // to profile would not work - maybe a new capability - moodle/user:freely_acessile_profile_for_anybody
143 // or test for course:inspect capability
871e5728 144 if (has_capability('moodle/role:assign', $coursecontext)) {
ce221eb5 145 $PAGE->navbar->add($fullname);
4f0c2d00
PS
146 echo $OUTPUT->header();
147 echo $OUTPUT->heading(get_string('notenrolled', '', $fullname));
ce221eb5 148 } else {
4f0c2d00 149 echo $OUTPUT->header();
ce221eb5 150 $PAGE->navbar->add($struser);
151 echo $OUTPUT->heading(get_string('notenrolledprofile'));
fa22fd5f 152 }
4f0c2d00
PS
153 if (!empty($_SERVER['HTTP_REFERER'])) {
154 echo $OUTPUT->continue_button($_SERVER['HTTP_REFERER']);
155 }
ce221eb5 156 echo $OUTPUT->footer();
157 exit;
fa22fd5f 158 }
ce221eb5 159 }
499e78b4 160
4f0c2d00
PS
161 // If groups are in use and enforced throughout the course, then make sure we can meet in at least one course level group
162 if (groups_get_course_groupmode($course) == SEPARATEGROUPS and $course->groupmodeforce
163 and !has_capability('moodle/site:accessallgroups', $coursecontext) and !has_capability('moodle/site:accessallgroups', $coursecontext, $user->id)) {
164 if (!isloggedin() or isguestuser()) {
165 // do not use require_login() here because we might have already used require_login($course)
166 redirect(get_login_url());
167 }
168 $mygroups = array_keys(groups_get_all_groups($course->id, $USER->id, $course->defaultgroupingid, 'g.id, g.name'));
169 $usergroups = array_keys(groups_get_all_groups($course->id, $user->id, $course->defaultgroupingid, 'g.id, g.name'));
170 if (!array_intersect($mygroups, $usergroups)) {
ce221eb5 171 print_error("groupnotamember", '', "../course/view.php?id=$course->id");
dd780a3b 172 }
173 }
ce221eb5 174}
0be6f678 175
f5ecf2e9 176
bad59bc0 177/// We've established they can see the user's name at least, so what about the rest?
178
7a7e209d 179$PAGE->navigation->extend_for_user($user);
ce221eb5 180$PAGE->set_title("$course->fullname: $strpersonalprofile: $fullname");
181$PAGE->set_heading($course->fullname);
ad1e8f13 182$PAGE->set_pagelayout('standard');
ce221eb5 183echo $OUTPUT->header();
b1d530d2 184
ce221eb5 185if ($user->deleted) {
186 echo $OUTPUT->heading(get_string('userdeleted'));
187 if (!has_capability('moodle/user:update', $coursecontext)) {
188 echo $OUTPUT->footer();
189 die;
bb09fb11 190 }
ce221eb5 191}
bb09fb11 192
bad59bc0 193/// OK, security out the way, now we are showing the user
194
ce221eb5 195add_to_log($course->id, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
bad59bc0 196
4f0c2d00 197if (!$isfrontpage) {
ce221eb5 198 $user->lastaccess = false;
199 if ($lastaccess = $DB->get_record('user_lastaccess', array('userid'=>$user->id, 'courseid'=>$course->id))) {
200 $user->lastaccess = $lastaccess->timeaccess;
499e78b4 201 }
ce221eb5 202}
499e78b4 203
bad59bc0 204
4801fe93 205/// Get the hidden field list
ce221eb5 206if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
207 $hiddenfields = array();
208} else {
209 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
210}
f9903ed0 211
f9a0ea69 212/// Print tabs at top
213/// This same call is made in:
214/// /user/view.php
215/// /user/edit.php
216/// /course/user.php
4801fe93 217
ce221eb5 218$currenttab = 'profile';
219$showroles = 1;
220if (!$user->deleted) {
221 include('tabs.php');
222}
f9903ed0 223
ce221eb5 224if (is_mnet_remote_user($user)) {
225 $sql = "
226 SELECT DISTINCT h.id, h.name, h.wwwroot,
4f0c2d00 227 a.name as application, a.display_name
ce221eb5 228 FROM {mnet_host} h, {mnet_application} a
229 WHERE h.id = ? AND h.applicationid = a.id
230 ORDER BY a.display_name, h.name";
ce8c75ee 231
ce221eb5 232 $remotehost = $DB->get_record_sql($sql, array($user->mnethostid));
0be6f678 233
ce221eb5 234 echo '<p class="errorboxcontent">'.get_string('remoteappuser', $remotehost->application)." <br />\n";
4f0c2d00 235 if ($currentuser) {
ce221eb5 236 if ($remotehost->application =='moodle') {
237 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/user/edit.php\">{$remotehost->name}</a> ".get_string('editremoteprofile')." </p>\n";
25202581 238 } else {
ce221eb5 239 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a> ".get_string('gotoyourserver')." </p>\n";
25202581 240 }
ce221eb5 241 } else {
242 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a></p>\n";
56f52742 243 }
ce221eb5 244}
56f52742 245
90723839 246echo '<table class="userinfobox" summary="">';
ce221eb5 247echo '<tr>';
248echo '<td class="side">';
812dbaf7 249echo $OUTPUT->user_picture($user, array('courseid'=>$course->id, 'size'=>100));
ce221eb5 250echo '</td><td class="content">';
f9903ed0 251
ce221eb5 252// Print the description
f9903ed0 253
ce221eb5 254if ($user->description && !isset($hiddenfields['description'])) {
4f0c2d00 255 if (!$isfrontpage && !empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid'=>$id))) {
ce221eb5 256 echo get_string('profilenotshown', 'moodle').'<hr />';
257 } else {
8bdc9cac
SH
258 $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $usercontext->id, 'user_profile', $id);
259 echo format_text($user->description, $user->descriptionformat)."<hr />";
f9903ed0 260 }
ce221eb5 261}
f9903ed0 262
ce221eb5 263// Print all the little details in a list
f9903ed0 264
ce221eb5 265echo '<table class="list">';
f9903ed0 266
ce221eb5 267if (! isset($hiddenfields['country']) && $user->country) {
0aa759b0 268 $countries = get_string_manager()->get_list_of_countries();
ce221eb5 269 print_row(get_string('country') . ':', $countries[$user->country]);
270}
910bd9e1 271
ce221eb5 272if (! isset($hiddenfields['city']) && $user->city) {
273 print_row(get_string('city') . ':', $user->city);
274}
f9903ed0 275
ce221eb5 276if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
277 if ($user->address) {
278 print_row(get_string("address").":", "$user->address");
279 }
280 if ($user->phone1) {
281 print_row(get_string("phone").":", "$user->phone1");
282 }
283 if ($user->phone2) {
284 print_row(get_string("phone2").":", "$user->phone2");
f9903ed0 285 }
ce221eb5 286}
f9903ed0 287
4f0c2d00
PS
288if ($user->maildisplay == 1
289 or ($user->maildisplay == 2 and !$isfrontpage and !isguestuser())
290 or has_capability('moodle/course:useremail', $coursecontext)) {
cadb96f2 291
ce221eb5 292 $emailswitch = '';
c6c558d7 293
4f0c2d00 294 if ($currentuser or has_capability('moodle/course:useremail', $coursecontext)) { /// Can use the enable/disable email stuff
deaa8a19 295 if (!empty($enable) and confirm_sesskey()) { /// Recieved a parameter to enable the email address
ce221eb5 296 $DB->set_field('user', 'emailstop', 0, array('id'=>$user->id));
297 $user->emailstop = 0;
c6c558d7 298 }
deaa8a19 299 if (!empty($disable) and confirm_sesskey()) { /// Recieved a parameter to disable the email address
ce221eb5 300 $DB->set_field('user', 'emailstop', 1, array('id'=>$user->id));
301 $user->emailstop = 1;
cadb96f2 302 }
55e078c0 303 }
f9903ed0 304
ce221eb5 305 if (has_capability('moodle/course:useremail', $coursecontext)) { /// Can use the enable/disable email stuff
306 if ($user->emailstop) {
307 $switchparam = 'enable';
308 $switchtitle = get_string('emaildisable');
309 $switchclick = get_string('emailenableclick');
310 $switchpix = 't/emailno';
311 } else {
312 $switchparam = 'disable';
313 $switchtitle = get_string('emailenable');
314 $switchclick = get_string('emaildisableclick');
315 $switchpix = 't/email';
316 }
317 $emailswitch = "&nbsp;<a title=\"$switchclick\" ".
deaa8a19 318 "href=\"view.php?id=$user->id&amp;course=$course->id&amp;$switchparam=1&amp;sesskey=".sesskey()."\">".
b5d0cafc 319 "<img src=\"" . $OUTPUT->pix_url("$switchpix") . "\" alt=\"$switchclick\" /></a>";
ce221eb5 320
321 } else if ($currentuser) { /// Can only re-enable an email this way
322 if ($user->emailstop) { // Include link that tells how to re-enable their email
323 $switchparam = 'enable';
324 $switchtitle = get_string('emaildisable');
325 $switchclick = get_string('emailenableclick');
326
327 $emailswitch = "&nbsp;(<a title=\"$switchclick\" ".
deaa8a19 328 "href=\"view.php?id=$user->id&amp;course=$course->id&amp;enable=1&amp;sesskey=".sesskey()."\">$switchtitle</a>)";
c18a3c1f 329 }
f9903ed0 330 }
331
ce221eb5 332 print_row(get_string("email").":", obfuscate_mailto($user->email, '', $user->emailstop)."$emailswitch");
333}
766d2bf3 334
ce221eb5 335if ($user->url && !isset($hiddenfields['webpage'])) {
336 $url = $user->url;
337 if (strpos($user->url, '://') === false) {
338 $url = 'http://'. $url;
f9903ed0 339 }
4f0c2d00 340 print_row(get_string("webpage") .":", '<a href="'.s($url).'">'.s($user->url).'</a>');
ce221eb5 341}
f9903ed0 342
ce221eb5 343if ($user->icq && !isset($hiddenfields['icqnumber'])) {
4f0c2d00 344 print_row(get_string('icqnumber').':',"<a href=\"http://web.icq.com/wwp?uin=".urlencode($user->icq)."\">".s($user->icq)." <img src=\"http://web.icq.com/whitepages/online?icq=".urlencode($user->icq)."&amp;img=5\" alt=\"\" /></a>");
ce221eb5 345}
346
347if ($user->skype && !isset($hiddenfields['skypeid'])) {
348 print_row(get_string('skypeid').':','<a href="callto:'.urlencode($user->skype).'">'.s($user->skype).
349 ' <img src="http://mystatus.skype.com/smallicon/'.urlencode($user->skype).'" alt="'.get_string('status').'" '.
350 ' /></a>');
351}
352if ($user->yahoo && !isset($hiddenfields['yahooid'])) {
353 print_row(get_string('yahooid').':', '<a href="http://edit.yahoo.com/config/send_webmesg?.target='.urlencode($user->yahoo).'&amp;.src=pg">'.s($user->yahoo)." <img src=\"http://opi.yahoo.com/online?u=".urlencode($user->yahoo)."&m=g&t=0\" alt=\"\"></a>");
354}
355if ($user->aim && !isset($hiddenfields['aimid'])) {
4f0c2d00 356 print_row(get_string('aimid').':', '<a href="aim:goim?screenname='.urlencode($user->aim).'">'.s($user->aim).'</a>');
ce221eb5 357}
358if ($user->msn && !isset($hiddenfields['msnid'])) {
359 print_row(get_string('msnid').':', s($user->msn));
360}
361
362/// Print the Custom User Fields
363profile_display_fields($user->id);
364
365
366if (!isset($hiddenfields['mycourses'])) {
183ea489 367 if ($mycourses = get_my_courses($user->id, 'visible DESC,sortorder ASC', null, false, 21)) {
ce221eb5 368 $shown=0;
369 $courselisting = '';
370 foreach ($mycourses as $mycourse) {
371 if ($mycourse->category) {
372 if ($mycourse->id != $course->id){
373 $class = '';
374 if ($mycourse->visible == 0) {
375 // get_my_courses will filter courses $USER cannot see
376 // if we get one with visible 0 it just means it's hidden
377 // ... but not from $USER
378 $class = 'class="dimmed"';
472b647a 379 }
ce221eb5 380 $courselisting .= "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&amp;course={$mycourse->id}\" $class >"
381 . format_string($mycourse->fullname) . "</a>, ";
dd5e0901 382 }
ce221eb5 383 else {
384 $courselisting .= format_string($mycourse->fullname) . ", ";
9c72928d 385 }
386 }
ce221eb5 387 $shown++;
388 if($shown==20) {
389 $courselisting.= "...";
390 break;
391 }
9c72928d 392 }
ce221eb5 393 print_row(get_string('courses').':', rtrim($courselisting,', '));
9c72928d 394 }
ce221eb5 395}
396if (!isset($hiddenfields['firstaccess'])) {
397 if ($user->firstaccess) {
398 $datestring = userdate($user->firstaccess)."&nbsp; (".format_time(time() - $user->firstaccess).")";
399 } else {
400 $datestring = get_string("never");
1263a0ff 401 }
ce221eb5 402 print_row(get_string("firstaccess").":", $datestring);
403}
404if (!isset($hiddenfields['lastaccess'])) {
405 if ($user->lastaccess) {
406 $datestring = userdate($user->lastaccess)."&nbsp; (".format_time(time() - $user->lastaccess).")";
407 } else {
408 $datestring = get_string("never");
d21fef3a 409 }
ce221eb5 410 print_row(get_string("lastaccess").":", $datestring);
411}
0a8a95c9 412/// printing roles
f2f085ee 413
4f0c2d00
PS
414if ($rolestring = get_user_roles_in_course($id, $course->id)) {
415 print_row(get_string('roles').':', $rolestring);
ce221eb5 416}
fa22fd5f 417
f90e9ff6 418/// Printing groups
ce221eb5 419if (!isset($hiddenfields['groups'])) {
4f0c2d00
PS
420 if ($course->groupmode != SEPARATEGROUPS or has_capability('moodle/site:accessallgroups', $coursecontext)) {
421 if ($usergroups = groups_get_all_groups($course->id, $user->id)) {
ce221eb5 422 $groupstr = '';
423 foreach ($usergroups as $group){
424 $groupstr .= ' <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$group->id.'">'.format_string($group->name).'</a>,';
fa22fd5f 425 }
ce221eb5 426 print_row(get_string("group").":", rtrim($groupstr, ', '));
fa22fd5f 427 }
fa22fd5f 428 }
ce221eb5 429}
f90e9ff6 430/// End of printing groups
fa22fd5f 431
1e1c51a3 432/// Printing Interests
ce221eb5 433 if( !empty($CFG->usetags)) {
434 if ( $interests = tag_get_tags_csv('user', $user->id) ) {
435 print_row(get_string('interests') .": ", $interests);
1e1c51a3 436 }
ce221eb5 437}
0be6f678 438/// End of Printing Interests
1e1c51a3 439
ce221eb5 440echo "</table>";
f9903ed0 441
ce221eb5 442echo "</td></tr></table>";
f9903ed0 443
ce221eb5 444$userauth = get_auth_plugin($user->auth);
210560e3 445
ce221eb5 446$passwordchangeurl = false;
447if ($currentuser and $userauth->can_change_password() and !isguestuser() and has_capability('moodle/user:changeownpassword', $systemcontext)) {
448 if (!$passwordchangeurl = $userauth->change_password_url()) {
449 if (empty($CFG->loginhttps)) {
450 $passwordchangeurl = "$CFG->wwwroot/login/change_password.php";
451 } else {
452 $passwordchangeurl = str_replace('http:', 'https:', $CFG->wwwroot.'/login/change_password.php');
ab1324e4 453 }
3086f3f6 454 }
ce221eb5 455}
3086f3f6 456
c888501c 457// Print other functions
e08fbd19 458echo '<div class="buttons clearfix">';
b506bb51 459
ce221eb5 460if ($passwordchangeurl) {
461 $params = array('id'=>$course->id);
65acd2bb 462
ce221eb5 463 if (session_is_loggedinas()) {
464 $passwordchangeurl = ''; // do not use actual change password url - might contain sensitive data
465 } else {
466 $parts = explode('?', $passwordchangeurl);
467 $passwordchangeurl = reset($parts);
468 $after = next($parts);
469 preg_match_all('/([^&=]+)=([^&=]+)/', $after, $matches);
470 if (count($matches)) {
471 foreach($matches[0] as $key=>$match) {
472 $params[$matches[1][$key]] = $matches[2][$key];
65acd2bb 473 }
80274abf 474 }
e1ac4272 475 }
ce221eb5 476 echo "<form action=\"$passwordchangeurl\" method=\"get\">";
477 echo "<div>";
478 foreach($params as $key=>$value) {
479 echo '<input type="hidden" name="'.$key.'" value="'.s($value).'" />';
480 }
481 if (session_is_loggedinas()) {
482 // changing of password when "Logged in as" is not allowed
483 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" disabled=\"disabled\" />";
484 } else {
485 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
486 }
487 echo "</div>";
488 echo "</form>";
489}
4801fe93 490
4f0c2d00 491if (!$isfrontpage && empty($course->metacourse)) { // Mostly only useful at course level
4801fe93 492
4f0c2d00
PS
493 if ($currentuser) {
494 if (is_enrolled($coursecontext, NULL, 'moodle/role:unassignself')) {
495 echo '<form action="'.$CFG->wwwroot.'/course/unenrol.php" method="get">';
496 echo '<div>';
497 echo '<input type="hidden" name="id" value="'.$course->id.'" />';
498 echo '<input type="hidden" name="user" value="'.$user->id.'" />';
499 echo '<input type="submit" value="'.s(get_string('unenrolme', '', $course->shortname)).'" />';
500 echo '</div>';
501 echo '</form>';
502 }
503 } else {
504 if (is_enrolled($coursecontext, $user->id, 'moodle/role:assign')) { // I can unassign roles
505 // add some button to unenroll user
76b570d6 506 }
803b2c76 507 }
ce221eb5 508}
bad59bc0 509
4f0c2d00 510if (!$user->deleted and !$currentuser && !session_is_loggedinas() && has_capability('moodle/user:loginas', $coursecontext) && !is_siteadmin($user->id)) {
ce221eb5 511 echo '<form action="'.$CFG->wwwroot.'/course/loginas.php" method="get">';
512 echo '<div>';
513 echo '<input type="hidden" name="id" value="'.$course->id.'" />';
514 echo '<input type="hidden" name="user" value="'.$user->id.'" />';
515 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
516 echo '<input type="submit" value="'.get_string('loginas').'" />';
517 echo '</div>';
518 echo '</form>';
519}
520
474f6bfe 521if (!$user->deleted and !empty($CFG->messaging) and !isguestuser() and has_capability('moodle/site:sendmessage', $systemcontext)) {
4f0c2d00 522 if (isloggedin() and $currentuser) {
ce221eb5 523 if ($countmessages = $DB->count_records('message', array('useridto'=>$user->id))) {
524 $messagebuttonname = get_string("messages", "message")."($countmessages)";
2fc1b1fe 525 } else {
ce221eb5 526 $messagebuttonname = get_string("messages", "message");
2fc1b1fe 527 }
ce221eb5 528 echo "<form onclick=\"this.target='message'\" action=\"../message/index.php\" method=\"get\">";
529 echo "<div>";
530 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);\" />";
531 echo "</div>";
532 echo "</form>";
533 } else {
534 echo "<form onclick=\"this.target='message$user->id'\" action=\"../message/discussion.php\" method=\"get\">";
4e7b349e 535 echo "<div>";
ce221eb5 536 echo "<input type=\"hidden\" name=\"id\" value=\"$user->id\" />";
537 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);\" />";
4e7b349e 538 echo "</div>";
c1138797 539 echo "</form>";
96a7973e 540 }
ce221eb5 541}
4f0c2d00 542
ce221eb5 543// Authorize.net: User Payments
4f0c2d00 544// TODO: replace this hack with proper callback into all plugins
ce221eb5 545if ($course->enrol == 'authorize' || (empty($course->enrol) && $CFG->enrol == 'authorize')) {
546 echo "<form action=\"../enrol/authorize/index.php\" method=\"get\">";
547 echo "<div>";
548 echo "<input type=\"hidden\" name=\"course\" value=\"$course->id\" />";
549 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
550 echo "<input type=\"submit\" value=\"".get_string('payments')."\" />";
551 echo "</div>";
552 echo "</form>";
553}
554echo "</div>\n";
3de34ccf 555
4f0c2d00 556if ($CFG->debugdisplay && debugging('', DEBUG_DEVELOPER) && $currentuser) { // Show user object
ce221eb5 557 echo '<hr />';
558 echo $OUTPUT->heading('DEBUG MODE: User session variables');
559 print_object($USER);
560}
3de34ccf 561
ce221eb5 562echo $OUTPUT->footer();
f9903ed0 563
564/// Functions ///////
565
566function print_row($left, $right) {
c1138797 567 echo "\n<tr><td class=\"label c0\">$left</td><td class=\"info c1\">$right</td></tr>\n";
f9903ed0 568}
569
aa6c1ced 570