MDL-10110 Adding validation for multichoice option single and multianswer
[moodle.git] / user / view.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2
3// Display profile for a particular user
0be6f678 4
b0e3a925 5 require_once("../config.php");
334415e9 6 require_once($CFG->dirroot.'/user/profile/lib.php');
1e1c51a3 7 require_once($CFG->dirroot.'/tag/lib.php');
0be6f678 8
2a7fbce0 9 $id = optional_param('id', 0, PARAM_INT); // user id
10 $course = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site)
622365d2 11 $enable = optional_param('enable', 0, PARAM_BOOL); // enable email
12 $disable = optional_param('disable', 0, PARAM_BOOL); // disable email
f9903ed0 13
e41ddc4b 14 if (empty($id)) { // See your own profile by default
15 require_login();
16 $id = $USER->id;
17 }
18
ce8c75ee 19 if (! $user = $DB->get_record("user", array("id"=>$id))) {
4e244ba8 20 print_error('invaliduserid');
f9903ed0 21 }
22
ce8c75ee 23 if (! $course = $DB->get_record("course", array("id"=>$course))) {
4e244ba8 24 print_error('invalidcourseid');
f9903ed0 25 }
26
1deff123 27 // special hack for cli installer - continue to site settings
28 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
29 if ($SITE->shortname === '' and has_capability('moodle/site:config', $systemcontext)) {
30 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
31 }
32
3b00380f 33/// Set up page URL for blocks etc
34 if ($course->id == SITEID) {
35 $PAGE->set_url('user/view.php', array('id' => $user->id));
36 } else {
37 $PAGE->set_url('user/view.php', array('id' => $user->id, 'course' => $course->id));
38 }
39
bad59bc0 40/// Make sure the current user is allowed to see this user
41
42 if (empty($USER->id)) {
43 $currentuser = false;
44 } else {
45 $currentuser = ($user->id == $USER->id);
46 }
47
e020c546 48 if ($course->id == SITEID) {
1cb3da36 49 $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
e020c546 50 } else {
51 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
52 }
bad59bc0 53 $usercontext = get_context_instance(CONTEXT_USER, $user->id); // User context
0be6f678 54
3975c764 55 $PAGE->set_context($usercontext);
cb4f6179 56
7034b46c 57 if (!empty($CFG->forcelogin) || $course->id != SITEID) {
58 // do not force parents to enrol
ce8c75ee 59 if (!$DB->get_record('role_assignments', array('userid'=>$USER->id, 'contextid'=>$usercontext->id))) {
7034b46c 60 require_login($course->id);
61 }
62 }
0be6f678 63
1c2a71d3 64 if (!empty($CFG->forceloginforprofiles)) {
65 require_login();
555b8513 66 if (isguest()) {
93f66983 67 redirect(get_login_url());
555b8513 68 }
f9903ed0 69 }
70
499e78b4 71 $strpersonalprofile = get_string('personalprofile');
72 $strparticipants = get_string("participants");
73 $struser = get_string("user");
f9903ed0 74
499e78b4 75 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $coursecontext));
f1603208 76
caa8363f 77 $link = null;
2990e113 78 if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
caa8363f 79 $link = new moodle_url($CFG->wwwroot."/user/index.php", array('id'=>$course->id));
2990e113 80 }
ee8aca27 81 if ($course->id===SITEID) {
82 $PAGE->navbar->ignore_active();
83 }
91152a35 84 $PAGE->navbar->add($strparticipants, $link);
0be6f678 85
499e78b4 86/// If the user being shown is not ourselves, then make sure we are allowed to see them!
fa0626c6 87
499e78b4 88 if (!$currentuser) {
caa8363f 89
90 $PAGE->set_title("$strpersonalprofile: ");
91 $PAGE->set_heading("$strpersonalprofile: ");
92
499e78b4 93 if ($course->id == SITEID) { // Reduce possibility of "browsing" userbase at site level
0be6f678 94 if ($CFG->forceloginforprofiles and !isteacherinanycourse()
95 and !isteacherinanycourse($user->id)
96 and !has_capability('moodle/user:viewdetails', $usercontext)) { // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
97
caa8363f 98 $PAGE->navbar->add($struser);
99 echo $OUTPUT->header();
8fa89bfd 100 echo $OUTPUT->heading(get_string('usernotavailable', 'error'));
f24ca3ce 101 echo $OUTPUT->footer();
499e78b4 102 exit;
103 }
104 } else { // Normal course
8005d470 105 // check capabilities
f2f085ee 106 if (!has_capability('moodle/user:viewdetails', $coursecontext) &&
8005d470 107 !has_capability('moodle/user:viewdetails', $usercontext)) {
108 print_error('cannotviewprofile');
109 }
110
499e78b4 111 if (!has_capability('moodle/course:view', $coursecontext, $user->id, false)) {
112 if (has_capability('moodle/course:view', $coursecontext)) {
caa8363f 113 $PAGE->navbar->add($fullname);
8fa89bfd 114 echo $OUTPUT->heading(get_string('notenrolled', $fullname));
499e78b4 115 } else {
caa8363f 116 $PAGE->navbar->add($struser);
f24ca3ce 117 echo $OUTPUT->heading(get_string('notenrolledprofile'));
fa22fd5f 118 }
3aac07d8 119 echo $OUTPUT->continue_button($_SERVER['HTTP_REFERER']);
f24ca3ce 120 echo $OUTPUT->footer();
499e78b4 121 exit;
fa22fd5f 122 }
123 }
499e78b4 124
125
126 // If groups are in use, make sure we can see that group
ffc536af 127 if (groups_get_course_groupmode($course) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $coursecontext)) {
499e78b4 128 require_login();
499e78b4 129 ///this is changed because of mygroupid
5bf243d1 130 $gtrue = (bool)groups_get_all_groups($course->id, $user->id);
499e78b4 131 if (!$gtrue) {
5a2a5331 132 print_error("groupnotamember", '', "../course/view.php?id=$course->id");
499e78b4 133 }
dd780a3b 134 }
135 }
0be6f678 136
f5ecf2e9 137
bad59bc0 138/// We've established they can see the user's name at least, so what about the rest?
139
caa8363f 140 $PAGE->navbar->add($struser);
141 $PAGE->set_title("$course->fullname: $strpersonalprofile: $fullname");
142 $PAGE->set_heading($course->fullname);
143 echo $OUTPUT->header();
b1d530d2 144
1936c10e 145 if (($course->id != SITEID) and ! isguest() ) { // Need to have access to a course to see that info
7034b46c 146 if (!has_capability('moodle/course:view', $coursecontext, $user->id)) {
f24ca3ce 147 echo $OUTPUT->heading(get_string('notenrolled', '', $fullname));
148 echo $OUTPUT->footer();
b51e9913 149 die;
150 }
8a3b358b 151 }
152
bb09fb11 153 if ($user->deleted) {
f24ca3ce 154 echo $OUTPUT->heading(get_string('userdeleted'));
f5fc83e8 155 if (!has_capability('moodle/user:update', $coursecontext)) {
f24ca3ce 156 echo $OUTPUT->footer();
f5fc83e8 157 die;
158 }
bb09fb11 159 }
160
bad59bc0 161/// OK, security out the way, now we are showing the user
162
163 add_to_log($course->id, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id");
164
499e78b4 165 if ($course->id != SITEID) {
010aa4da 166 $user->lastaccess = false;
ce8c75ee 167 if ($lastaccess = $DB->get_record('user_lastaccess', array('userid'=>$user->id, 'courseid'=>$course->id))) {
499e78b4 168 $user->lastaccess = $lastaccess->timeaccess;
169 }
170 }
171
bad59bc0 172
4801fe93 173/// Get the hidden field list
174 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
175 $hiddenfields = array();
3468d58a 176 } else {
177 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
178 }
f9903ed0 179
f9a0ea69 180/// Print tabs at top
181/// This same call is made in:
182/// /user/view.php
183/// /user/edit.php
184/// /course/user.php
4801fe93 185
f9a0ea69 186 $currenttab = 'profile';
0a8a95c9 187 $showroles = 1;
f5fc83e8 188 if (!$user->deleted) {
189 include('tabs.php');
190 }
f9903ed0 191
56f52742 192 if (is_mnet_remote_user($user)) {
25202581 193 $sql = "
ce8c75ee 194 SELECT DISTINCT h.id, h.name, h.wwwroot,
195 a.name as application, a.display_name
196 FROM {mnet_host} h, {mnet_application} a
197 WHERE h.id = ? AND h.applicationid = a.id
198 ORDER BY a.display_name, h.name";
199
200 $remotehost = $DB->get_record_sql($sql, array($user->mnethostid));
0be6f678 201
ee4bd787 202 echo '<p class="errorboxcontent">'.get_string('remoteappuser', $remotehost->application)." <br />\n";
b4daa48f 203 if ($USER->id == $user->id) {
204 if ($remotehost->application =='moodle') {
205 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/user/edit.php\">{$remotehost->name}</a> ".get_string('editremoteprofile')." </p>\n";
206 } else {
207 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a> ".get_string('gotoyourserver')." </p>\n";
208 }
25202581 209 } else {
b4daa48f 210 echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a></p>\n";
25202581 211 }
56f52742 212 }
213
c1138797 214 echo '<table width="80%" class="userinfobox" summary="">';
215 echo '<tr>';
216 echo '<td class="side">';
f2f085ee 217 $userpic = moodle_user_picture::make($user, $course->id);
218 $userpic->size = 100;
219 echo $OUTPUT->user_picture($userpic);
c1138797 220 echo '</td><td class="content">';
f9903ed0 221
f9903ed0 222 // Print the description
223
3468d58a 224 if ($user->description && !isset($hiddenfields['description'])) {
35f0660a 225 $has_courseid = ($course->id != SITEID);
6eaf2e37 226 if (!$has_courseid && !empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid'=>$id))) {
35f0660a 227 echo get_string('profilenotshown', 'moodle').'<hr />';
228 } else {
229 echo format_text($user->description, FORMAT_MOODLE)."<hr />";
230 }
f9903ed0 231 }
232
f9903ed0 233 // Print all the little details in a list
234
c1138797 235 echo '<table class="list">';
f9903ed0 236
910bd9e1 237 if (! isset($hiddenfields['country']) && $user->country) {
ac382d2b 238 $countries = get_list_of_countries();
910bd9e1 239 print_row(get_string('country') . ':', $countries[$user->country]);
240 }
241
242 if (! isset($hiddenfields['city']) && $user->city) {
243 print_row(get_string('city') . ':', $user->city);
603d4c72 244 }
f9903ed0 245
4801fe93 246 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
f9903ed0 247 if ($user->address) {
fa0626c6 248 print_row(get_string("address").":", "$user->address");
f9903ed0 249 }
250 if ($user->phone1) {
fa0626c6 251 print_row(get_string("phone").":", "$user->phone1");
f9903ed0 252 }
253 if ($user->phone2) {
55ac3d6f 254 print_row(get_string("phone2").":", "$user->phone2");
f9903ed0 255 }
256 }
257
ab1324e4 258 if ($user->maildisplay == 1 or
1936c10e 259 ($user->maildisplay == 2 and ($course->id != SITEID) and !isguest()) or
37edce7b 260 has_capability('moodle/course:useremail', $coursecontext)) {
cadb96f2 261
c6c558d7 262 $emailswitch = '';
263
bad59bc0 264 if (has_capability('moodle/course:useremail', $coursecontext) or $currentuser) { /// Can use the enable/disable email stuff
8381a4e2 265 if (!empty($enable)) { /// Recieved a parameter to enable the email address
a5d424df 266 $DB->set_field('user', 'emailstop', 0, array('id'=>$user->id));
cadb96f2 267 $user->emailstop = 0;
268 }
8381a4e2 269 if (!empty($disable)) { /// Recieved a parameter to disable the email address
a5d424df 270 $DB->set_field('user', 'emailstop', 1, array('id'=>$user->id));
cadb96f2 271 $user->emailstop = 1;
272 }
c6c558d7 273 }
274
bad59bc0 275 if (has_capability('moodle/course:useremail', $coursecontext)) { /// Can use the enable/disable email stuff
cadb96f2 276 if ($user->emailstop) {
277 $switchparam = 'enable';
278 $switchtitle = get_string('emaildisable');
dee51de2 279 $switchclick = get_string('emailenableclick');
ddedf979 280 $switchpix = 't/emailno';
cadb96f2 281 } else {
282 $switchparam = 'disable';
283 $switchtitle = get_string('emailenable');
dee51de2 284 $switchclick = get_string('emaildisableclick');
ddedf979 285 $switchpix = 't/email';
cadb96f2 286 }
c0260a6f 287 $emailswitch = "&nbsp;<a title=\"$switchclick\" ".
288 "href=\"view.php?id=$user->id&amp;course=$course->id&amp;$switchparam=1\">".
8c61317a 289 "<img src=\"" . $OUTPUT->old_icon_url("$switchpix") . "\" alt=\"$switchclick\" /></a>";
c6c558d7 290
291 } else if ($currentuser) { /// Can only re-enable an email this way
292 if ($user->emailstop) { // Include link that tells how to re-enable their email
293 $switchparam = 'enable';
294 $switchtitle = get_string('emaildisable');
295 $switchclick = get_string('emailenableclick');
296
c0260a6f 297 $emailswitch = "&nbsp;(<a title=\"$switchclick\" ".
298 "href=\"view.php?id=$user->id&amp;course=$course->id&amp;enable=1\">$switchtitle</a>)";
c6c558d7 299 }
cadb96f2 300 }
301
302 print_row(get_string("email").":", obfuscate_mailto($user->email, '', $user->emailstop)."$emailswitch");
55e078c0 303 }
f9903ed0 304
3468d58a 305 if ($user->url && !isset($hiddenfields['webpage'])) {
c18a3c1f 306 $url = $user->url;
307 if (strpos($user->url, '://') === false) {
308 $url = 'http://'. $url;
309 }
310 print_row(get_string("webpage") .":", "<a href=\"$url\">$user->url</a>");
f9903ed0 311 }
312
3468d58a 313 if ($user->icq && !isset($hiddenfields['icqnumber'])) {
c1138797 314 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\" alt=\"\" /></a>");
766d2bf3 315 }
316
3468d58a 317 if ($user->skype && !isset($hiddenfields['skypeid'])) {
0be6f678 318 print_row(get_string('skypeid').':','<a href="callto:'.urlencode($user->skype).'">'.s($user->skype).
2bbaf749 319 ' <img src="http://mystatus.skype.com/smallicon/'.urlencode($user->skype).'" alt="'.get_string('status').'" '.
c1138797 320 ' /></a>');
766d2bf3 321 }
3468d58a 322 if ($user->yahoo && !isset($hiddenfields['yahooid'])) {
c1138797 323 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>");
766d2bf3 324 }
3468d58a 325 if ($user->aim && !isset($hiddenfields['aimid'])) {
772fa490 326 print_row(get_string('aimid').':', '<a href="aim:goim?screenname='.s($user->aim).'">'.s($user->aim).'</a>');
766d2bf3 327 }
3468d58a 328 if ($user->msn && !isset($hiddenfields['msnid'])) {
766d2bf3 329 print_row(get_string('msnid').':', s($user->msn));
f9903ed0 330 }
331
334415e9 332 /// Print the Custom User Fields
333 profile_display_fields($user->id);
334
335
53bd2255 336 if (!isset($hiddenfields['mycourses'])) {
337 if ($mycourses = get_my_courses($user->id, null, null, false, 21)) {
338 $shown=0;
339 $courselisting = '';
340 foreach ($mycourses as $mycourse) {
341 if ($mycourse->category) {
342 if ($mycourse->id != $course->id){
343 $class = '';
344 if ($mycourse->visible == 0) {
345 // get_my_courses will filter courses $USER cannot see
346 // if we get one with visible 0 it just means it's hidden
347 // ... but not from $USER
348 $class = 'class="dimmed"';
349 }
350 $courselisting .= "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&amp;course={$mycourse->id}\" $class >"
351 . format_string($mycourse->fullname) . "</a>, ";
352 }
353 else {
354 $courselisting .= format_string($mycourse->fullname) . ", ";
472b647a 355 }
dd5e0901 356 }
53bd2255 357 $shown++;
358 if($shown==20) {
359 $courselisting.= "...";
360 break;
9c72928d 361 }
362 }
53bd2255 363 print_row(get_string('courses').':', rtrim($courselisting,', '));
9c72928d 364 }
365 }
1263a0ff 366 if (!isset($hiddenfields['firstaccess'])) {
367 if ($user->firstaccess) {
368 $datestring = userdate($user->firstaccess)."&nbsp; (".format_time(time() - $user->firstaccess).")";
369 } else {
370 $datestring = get_string("never");
371 }
372 print_row(get_string("firstaccess").":", $datestring);
373 }
3468d58a 374 if (!isset($hiddenfields['lastaccess'])) {
375 if ($user->lastaccess) {
376 $datestring = userdate($user->lastaccess)."&nbsp; (".format_time(time() - $user->lastaccess).")";
377 } else {
378 $datestring = get_string("never");
379 }
380 print_row(get_string("lastaccess").":", $datestring);
d21fef3a 381 }
0a8a95c9 382/// printing roles
f2f085ee 383
6967ba28 384 if ($rolestring = get_user_roles_in_context($id, $coursecontext)) {
5e104d5f 385 print_row(get_string('roles').':', format_string($rolestring, false));
e82dc9bb 386 }
fa22fd5f 387
f90e9ff6 388/// Printing groups
c6b4179c 389 if (!isset($hiddenfields['groups'])) {
390 $isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $coursecontext));
391 if (!$isseparategroups){
392 if ($usergroups = groups_get_all_groups($course->id, $user->id)){
393 $groupstr = '';
394 foreach ($usergroups as $group){
395 $groupstr .= ' <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$group->id.'">'.format_string($group->name).'</a>,';
396 }
397 print_row(get_string("group").":", rtrim($groupstr, ', '));
fa22fd5f 398 }
399 }
fa22fd5f 400 }
f90e9ff6 401/// End of printing groups
fa22fd5f 402
1e1c51a3 403/// Printing Interests
404 if( !empty($CFG->usetags)) {
f2f085ee 405 if ( $interests = tag_get_tags_csv('user', $user->id) ) {
3d535996 406 print_row(get_string('interests') .": ", $interests);
1e1c51a3 407 }
408 }
0be6f678 409/// End of Printing Interests
1e1c51a3 410
1b6a4b1d 411 echo "</table>";
f9903ed0 412
1b6a4b1d 413 echo "</td></tr></table>";
f9903ed0 414
56f52742 415 $userauth = get_auth_plugin($user->auth);
210560e3 416
417 $passwordchangeurl = false;
1cb3da36 418 if ($currentuser and $userauth->can_change_password() and !isguestuser() and has_capability('moodle/user:changeownpassword', $systemcontext)) {
419 if (!$passwordchangeurl = $userauth->change_password_url()) {
210560e3 420 if (empty($CFG->loginhttps)) {
421 $passwordchangeurl = "$CFG->wwwroot/login/change_password.php";
422 } else {
423 $passwordchangeurl = str_replace('http:', 'https:', $CFG->wwwroot.'/login/change_password.php');
424 }
ab1324e4 425 }
3086f3f6 426 }
427
c888501c 428// Print other functions
c1138797 429 echo '<div class="buttons">';
b506bb51 430
80274abf 431 if ($passwordchangeurl) {
65acd2bb 432 $params = array('id'=>$course->id);
433
b7b64ff2 434 if (session_is_loggedinas()) {
80274abf 435 $passwordchangeurl = ''; // do not use actual change password url - might contain sensitive data
65acd2bb 436 } else {
437 $parts = explode('?', $passwordchangeurl);
438 $passwordchangeurl = reset($parts);
439 $after = next($parts);
440 preg_match_all('/([^&=]+)=([^&=]+)/', $after, $matches);
441 if (count($matches)) {
442 foreach($matches[0] as $key=>$match) {
443 $params[$matches[1][$key]] = $matches[2][$key];
444 }
445 }
80274abf 446 }
210560e3 447 echo "<form action=\"$passwordchangeurl\" method=\"get\">";
4e7b349e 448 echo "<div>";
65acd2bb 449 foreach($params as $key=>$value) {
450 echo '<input type="hidden" name="'.$key.'" value="'.s($value).'" />';
451 }
b7b64ff2 452 if (session_is_loggedinas()) {
210560e3 453 // changing of password when "Logged in as" is not allowed
454 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" disabled=\"disabled\" />";
455 } else {
031c49fa 456 echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />";
3086f3f6 457 }
4e7b349e 458 echo "</div>";
210560e3 459 echo "</form>";
e1ac4272 460 }
4801fe93 461
462 if ($course->id != SITEID && empty($course->metacourse)) { // Mostly only useful at course level
463
76b570d6 464 $canunenrol = false;
465
466 if ($user->id == $USER->id) { // Myself
467 $canunenrol = has_capability('moodle/course:view', $coursecontext, NULL) && // Course participant
468 has_capability('moodle/role:unassignself', $coursecontext, NULL, false) && // Can unassign myself
469 get_user_roles($coursecontext, $user->id, false); // Must have role in course
470
471 } else if (has_capability('moodle/role:assign', $coursecontext, NULL)) { // I can assign roles
472 if ($roles = get_user_roles($coursecontext, $user->id, false)) {
473 $canunenrol = true;
474 foreach($roles as $role) {
475 if (!user_can_assign($coursecontext, $role->roleid)) {
476 $canunenrol = false; // I can not unassign all roles in this course :-(
477 break;
478 }
479 }
480 }
481 }
482
483 if ($canunenrol) {
484 echo '<form action="'.$CFG->wwwroot.'/course/unenrol.php" method="get">';
485 echo '<div>';
4801fe93 486 echo '<input type="hidden" name="id" value="'.$course->id.'" />';
487 echo '<input type="hidden" name="user" value="'.$user->id.'" />';
76b570d6 488 echo '<input type="submit" value="'.s(get_string('unenrolme', '', $course->shortname)).'" />';
489 echo '</div>';
c1138797 490 echo '</form>';
4801fe93 491 }
8f850172 492 }
4801fe93 493
b7b64ff2 494 if (!$user->deleted and $USER->id != $user->id && !session_is_loggedinas() && has_capability('moodle/user:loginas', $coursecontext) &&
42044d09 495 ! has_capability('moodle/site:doanything', $coursecontext, $user->id, false)) {
c1138797 496 echo '<form action="'.$CFG->wwwroot.'/course/loginas.php" method="get">';
76b570d6 497 echo '<div>';
4801fe93 498 echo '<input type="hidden" name="id" value="'.$course->id.'" />';
499 echo '<input type="hidden" name="user" value="'.$user->id.'" />';
f6f66b03 500 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
4801fe93 501 echo '<input type="submit" value="'.get_string('loginas').'" />';
76b570d6 502 echo '</div>';
c1138797 503 echo '</form>';
803b2c76 504 }
bad59bc0 505
f5fc83e8 506 if (!$user->deleted and !empty($CFG->messaging) and !isguest() and has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTEM))) {
f9a0ea69 507 if (!empty($USER->id) and ($USER->id == $user->id)) {
c7da4357 508 if ($countmessages = $DB->count_records('message', array('useridto'=>$user->id))) {
cdf39255 509 $messagebuttonname = get_string("messages", "message")."($countmessages)";
510 } else {
511 $messagebuttonname = get_string("messages", "message");
512 }
c1138797 513 echo "<form onclick=\"this.target='message'\" action=\"../message/index.php\" method=\"get\">";
4e7b349e 514 echo "<div>";
cdf39255 515 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);\" />";
4e7b349e 516 echo "</div>";
c1138797 517 echo "</form>";
2fc1b1fe 518 } else {
c1138797 519 echo "<form onclick=\"this.target='message$user->id'\" action=\"../message/discussion.php\" method=\"get\">";
4e7b349e 520 echo "<div>";
cdf39255 521 echo "<input type=\"hidden\" name=\"id\" value=\"$user->id\" />";
89286e24 522 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 523 echo "</div>";
c1138797 524 echo "</form>";
2fc1b1fe 525 }
2fc1b1fe 526 }
17eef684 527 // Authorize.net: User Payments
96a7973e 528 if ($course->enrol == 'authorize' || (empty($course->enrol) && $CFG->enrol == 'authorize')) {
c1138797 529 echo "<form action=\"../enrol/authorize/index.php\" method=\"get\">";
4e7b349e 530 echo "<div>";
17eef684 531 echo "<input type=\"hidden\" name=\"course\" value=\"$course->id\" />";
96a7973e 532 echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";
533 echo "<input type=\"submit\" value=\"".get_string('payments')."\" />";
4e7b349e 534 echo "</div>";
c1138797 535 echo "</form>";
96a7973e 536 }
c1138797 537 echo "</div>\n";
3de34ccf 538
539 if ($CFG->debugdisplay && debugging('', DEBUG_DEVELOPER) && $USER->id == $user->id) { // Show user object
e82dc9bb 540 echo '<hr />';
f24ca3ce 541 echo $OUTPUT->heading('DEBUG MODE: User session variables');
e82dc9bb 542 print_object($USER);
543 }
3de34ccf 544
f24ca3ce 545 echo $OUTPUT->footer();
f9903ed0 546
547/// Functions ///////
548
549function print_row($left, $right) {
c1138797 550 echo "\n<tr><td class=\"label c0\">$left</td><td class=\"info c1\">$right</td></tr>\n";
f9903ed0 551}
552
553?>