[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Display profile for a particular user 19 * 20 * @package core_user 21 * @copyright 1999 Martin Dougiamas http://dougiamas.com 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 require_once("../config.php"); 26 require_once($CFG->dirroot.'/user/profile/lib.php'); 27 require_once($CFG->dirroot.'/tag/lib.php'); 28 require_once($CFG->libdir . '/filelib.php'); 29 require_once($CFG->libdir . '/badgeslib.php'); 30 31 $id = optional_param('id', 0, PARAM_INT); // User id. 32 $courseid = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site). 33 $showallcourses = optional_param('showallcourses', 0, PARAM_INT); 34 35 // See your own profile by default. 36 if (empty($id)) { 37 require_login(); 38 $id = $USER->id; 39 } 40 41 if ($courseid == SITEID) { // Since Moodle 2.0 all site-level profiles are shown by profile.php. 42 redirect($CFG->wwwroot.'/user/profile.php?id='.$id); // Immediate redirect. 43 } 44 45 $PAGE->set_url('/user/view.php', array('id' => $id, 'course' => $courseid)); 46 47 $user = $DB->get_record('user', array('id' => $id), '*', MUST_EXIST); 48 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); 49 $currentuser = ($user->id == $USER->id); 50 51 $systemcontext = context_system::instance(); 52 $coursecontext = context_course::instance($course->id); 53 $usercontext = context_user::instance($user->id, IGNORE_MISSING); 54 55 // Require login first. 56 if (isguestuser($user)) { 57 // Can not view profile of guest - thre is nothing to see there. 58 print_error('invaliduserid'); 59 } 60 61 if (!empty($CFG->forceloginforprofiles)) { 62 require_login(); // We can not log in to course due to the parent hack below. 63 64 // Guests do not have permissions to view anyone's profile if forceloginforprofiles is set. 65 if (isguestuser()) { 66 $SESSION->wantsurl = $PAGE->url->out(false); 67 redirect(get_login_url()); 68 } 69 } 70 71 $PAGE->set_context($coursecontext); 72 $PAGE->set_course($course); 73 $PAGE->set_pagetype('course-view-' . $course->format); // To get the blocks exactly like the course. 74 $PAGE->add_body_class('path-user'); // So we can style it independently. 75 $PAGE->set_other_editing_capability('moodle/course:manageactivities'); 76 77 $isparent = false; 78 79 if (!$currentuser and !$user->deleted 80 and $DB->record_exists('role_assignments', array('userid' => $USER->id, 'contextid' => $usercontext->id)) 81 and has_capability('moodle/user:viewdetails', $usercontext)) { 82 // TODO: very ugly hack - do not force "parents" to enrol into course their child is enrolled in, 83 // this way they may access the profile where they get overview of grades and child activity in course, 84 // please note this is just a guess! 85 require_login(); 86 $isparent = true; 87 $PAGE->navigation->set_userid_for_parent_checks($id); 88 } else { 89 // Normal course. 90 require_login($course); 91 // What to do with users temporary accessing this course? should they see the details? 92 } 93 94 $strpersonalprofile = get_string('personalprofile'); 95 $strparticipants = get_string("participants"); 96 $struser = get_string("user"); 97 98 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $coursecontext)); 99 100 // Now test the actual capabilities and enrolment in course. 101 if ($currentuser) { 102 if (!is_viewing($coursecontext) && !is_enrolled($coursecontext)) { 103 // Need to have full access to a course to see the rest of own info. 104 echo $OUTPUT->header(); 105 echo $OUTPUT->heading(get_string('notenrolled', '', $fullname)); 106 if (!empty($_SERVER['HTTP_REFERER'])) { 107 echo $OUTPUT->continue_button($_SERVER['HTTP_REFERER']); 108 } 109 echo $OUTPUT->footer(); 110 die; 111 } 112 113 } else { 114 // Somebody else. 115 $PAGE->set_title("$strpersonalprofile: "); 116 $PAGE->set_heading("$strpersonalprofile: "); 117 118 // Check course level capabilities. 119 if (!has_capability('moodle/user:viewdetails', $coursecontext) && // Normal enrolled user or mnager. 120 ($user->deleted or !has_capability('moodle/user:viewdetails', $usercontext))) { // Usually parent. 121 print_error('cannotviewprofile'); 122 } 123 124 if (!is_enrolled($coursecontext, $user->id)) { 125 // TODO: the only potential problem is that managers and inspectors might post in forum, but the link 126 // to profile would not work - maybe a new capability - moodle/user:freely_acessile_profile_for_anybody 127 // or test for course:inspect capability. 128 if (has_capability('moodle/role:assign', $coursecontext)) { 129 $PAGE->navbar->add($fullname); 130 echo $OUTPUT->header(); 131 echo $OUTPUT->heading(get_string('notenrolled', '', $fullname)); 132 } else { 133 echo $OUTPUT->header(); 134 $PAGE->navbar->add($struser); 135 echo $OUTPUT->heading(get_string('notenrolledprofile')); 136 } 137 if (!empty($_SERVER['HTTP_REFERER'])) { 138 echo $OUTPUT->continue_button($_SERVER['HTTP_REFERER']); 139 } 140 echo $OUTPUT->footer(); 141 exit; 142 } 143 144 // If groups are in use and enforced throughout the course, then make sure we can meet in at least one course level group. 145 if (groups_get_course_groupmode($course) == SEPARATEGROUPS and $course->groupmodeforce 146 and !has_capability('moodle/site:accessallgroups', $coursecontext) and !has_capability('moodle/site:accessallgroups', $coursecontext, $user->id)) { 147 if (!isloggedin() or isguestuser()) { 148 // Do not use require_login() here because we might have already used require_login($course). 149 redirect(get_login_url()); 150 } 151 $mygroups = array_keys(groups_get_all_groups($course->id, $USER->id, $course->defaultgroupingid, 'g.id, g.name')); 152 $usergroups = array_keys(groups_get_all_groups($course->id, $user->id, $course->defaultgroupingid, 'g.id, g.name')); 153 if (!array_intersect($mygroups, $usergroups)) { 154 print_error("groupnotamember", '', "../course/view.php?id=$course->id"); 155 } 156 } 157 } 158 159 $PAGE->set_title("$course->fullname: $strpersonalprofile: $fullname"); 160 $PAGE->set_heading($course->fullname); 161 $PAGE->set_pagelayout('standard'); 162 163 // Locate the users settings in the settings navigation and force it open. 164 // This MUST be done after we've set up the page as it is going to cause theme and output to initialise. 165 if (!$currentuser) { 166 $PAGE->navigation->extend_for_user($user); 167 if ($node = $PAGE->settingsnav->get('userviewingsettings'.$user->id)) { 168 $node->forceopen = true; 169 } 170 } else if ($node = $PAGE->settingsnav->get('usercurrentsettings', navigation_node::TYPE_CONTAINER)) { 171 $node->forceopen = true; 172 } 173 if ($node = $PAGE->settingsnav->get('courseadmin')) { 174 $node->forceopen = false; 175 } 176 177 echo $OUTPUT->header(); 178 179 echo '<div class="userprofile">'; 180 181 echo $OUTPUT->heading(fullname($user).' ('.format_string($course->shortname, true, array('context' => $coursecontext)).')'); 182 183 if ($user->deleted) { 184 echo $OUTPUT->heading(get_string('userdeleted')); 185 if (!has_capability('moodle/user:update', $coursecontext)) { 186 echo $OUTPUT->footer(); 187 die; 188 } 189 } 190 191 // OK, security out the way, now we are showing the user. 192 // Trigger a user profile viewed event. 193 $event = \core\event\user_profile_viewed::create(array( 194 'objectid' => $user->id, 195 'relateduserid' => $user->id, 196 'courseid' => $course->id, 197 'context' => $coursecontext, 198 'other' => array( 199 'courseid' => $course->id, 200 'courseshortname' => $course->shortname, 201 'coursefullname' => $course->fullname 202 ) 203 )); 204 $event->add_record_snapshot('user', $user); 205 $event->trigger(); 206 207 // Get the hidden field list. 208 if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) { 209 $hiddenfields = array(); 210 } else { 211 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields)); 212 } 213 214 if (is_mnet_remote_user($user)) { 215 $sql = "SELECT h.id, h.name, h.wwwroot, 216 a.name as application, a.display_name 217 FROM {mnet_host} h, {mnet_application} a 218 WHERE h.id = ? AND h.applicationid = a.id"; 219 220 $remotehost = $DB->get_record_sql($sql, array($user->mnethostid)); 221 $a = new stdclass(); 222 $a->remotetype = $remotehost->display_name; 223 $a->remotename = $remotehost->name; 224 $a->remoteurl = $remotehost->wwwroot; 225 226 echo $OUTPUT->box(get_string('remoteuserinfo', 'mnet', $a), 'remoteuserinfo'); 227 } 228 229 echo '<div class="userprofilebox clearfix"><div class="profilepicture">'; 230 echo $OUTPUT->user_picture($user, array('size' => 100)); 231 echo '</div>'; 232 233 // Print the description. 234 echo '<div class="descriptionbox"><div class="description">'; 235 if ($user->description && !isset($hiddenfields['description'])) { 236 if (!empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid' => $id))) { 237 echo get_string('profilenotshown', 'moodle'); 238 } else { 239 if ($courseid == SITEID) { 240 $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $usercontext->id, 'user', 'profile', null); 241 } else { 242 // We have to make a little detour thought the course context to verify the access control for course profile. 243 $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $coursecontext->id, 'user', 'profile', $user->id); 244 } 245 $options = array('overflowdiv' => true); 246 echo format_text($user->description, $user->descriptionformat, $options); 247 } 248 } 249 echo '</div>'; 250 251 252 // Print all the little details in a list. 253 254 echo html_writer::start_tag('dl', array('class' => 'list')); 255 // Show email if any of the following conditions match. 256 // 1. User is viewing his own profile. 257 // 2. Has allowed everyone to see email 258 // 3. User has allowed course members to can see email and current user is in same course 259 // 4. Has either course:viewhiddenuserfields or site:viewuseridentity capability. 260 if ($currentuser 261 or $user->maildisplay == 1 262 or ($user->maildisplay == 2 && is_enrolled($coursecontext, $USER)) 263 or has_capability('moodle/course:viewhiddenuserfields', $coursecontext) 264 or has_capability('moodle/site:viewuseridentity', $coursecontext)) { 265 echo html_writer::tag('dt', get_string('email')); 266 echo html_writer::tag('dd', obfuscate_mailto($user->email, '')); 267 } 268 269 // Show last time this user accessed this course. 270 if (!isset($hiddenfields['lastaccess'])) { 271 if ($lastaccess = $DB->get_record('user_lastaccess', array('userid' => $user->id, 'courseid' => $course->id))) { 272 $datestring = userdate($lastaccess->timeaccess)." (".format_time(time() - $lastaccess->timeaccess).")"; 273 } else { 274 $datestring = get_string("never"); 275 } 276 echo html_writer::tag('dt', get_string('lastcourseaccess')); 277 echo html_writer::tag('dd', $datestring); 278 } 279 280 // Show roles in this course. 281 if ($rolestring = get_user_roles_in_course($id, $course->id)) { 282 echo html_writer::tag('dt', get_string('roles')); 283 echo html_writer::tag('dd', $rolestring); 284 } 285 286 // Show groups this user is in. 287 if (!isset($hiddenfields['groups'])) { 288 $accessallgroups = has_capability('moodle/site:accessallgroups', $coursecontext); 289 if ($usergroups = groups_get_all_groups($course->id, $user->id)) { 290 $groupstr = ''; 291 foreach ($usergroups as $group) { 292 if ($course->groupmode == SEPARATEGROUPS and !$accessallgroups and $user->id != $USER->id) { 293 if (!groups_is_member($group->id, $user->id)) { 294 continue; 295 } 296 } 297 298 if ($course->groupmode != NOGROUPS) { 299 $groupstr .= ' <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&group='.$group->id.'">'.format_string($group->name).'</a>,'; 300 } else { 301 $groupstr .= ' '.format_string($group->name); // The user/index.php shows groups only when course in group mode. 302 } 303 } 304 if ($groupstr !== '') { 305 echo html_writer::tag('dt', get_string('group')); 306 echo html_writer::tag('dd', rtrim($groupstr, ', ')); 307 } 308 } 309 } 310 311 // Show other courses they may be in. 312 if (!isset($hiddenfields['mycourses'])) { 313 if ($mycourses = enrol_get_all_users_courses($user->id, true, null, 'visible DESC,sortorder ASC')) { 314 $shown = 0; 315 $courselisting = ''; 316 foreach ($mycourses as $mycourse) { 317 if ($mycourse->category) { 318 context_helper::preload_from_record($mycourse); 319 $ccontext = context_course::instance($mycourse->id); 320 $cfullname = $ccontext->get_context_name(false); 321 if ($mycourse->id != $course->id) { 322 $linkattributes = null; 323 if ($mycourse->visible == 0) { 324 if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) { 325 continue; 326 } 327 $linkattributes['class'] = 'dimmed'; 328 } 329 $params = array('id' => $user->id, 'course' => $mycourse->id); 330 if ($showallcourses) { 331 $params['showallcourses'] = 1; 332 } 333 $url = new moodle_url('/user/view.php', $params); 334 $courselisting .= html_writer::link($url, $ccontext->get_context_name(false), $linkattributes); 335 $courselisting .= ', '; 336 } else { 337 $courselisting .= $cfullname . ", "; 338 $PAGE->navbar->add($cfullname); 339 } 340 } 341 $shown++; 342 if (!$showallcourses && $shown >= 20) { 343 $url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $courseid, 'showallcourses' => 1)); 344 $courselisting .= html_writer::link($url, '...', array('title' => get_string('viewmore'))); 345 break; 346 } 347 } 348 echo html_writer::tag('dt', get_string('courseprofiles')); 349 echo html_writer::tag('dd', rtrim($courselisting, ', ')); 350 } 351 } 352 353 if (!empty($CFG->enablebadges) && !empty($CFG->badges_allowcoursebadges)) { 354 profile_display_badges($user->id, $courseid); 355 } 356 357 if (!isset($hiddenfields['suspended'])) { 358 if ($user->suspended) { 359 echo html_writer::tag('dt', " "); 360 echo html_writer::tag('dd', get_string('suspended', 'auth')); 361 } 362 } 363 364 if (has_capability('moodle/user:viewlastip', $usercontext) && !isset($hiddenfields['lastip'])) { 365 if ($user->lastip) { 366 $iplookupurl = new moodle_url('/iplookup/index.php', array('ip' => $user->lastip, 'user' => $USER->id)); 367 $ipstring = html_writer::link($iplookupurl, $user->lastip); 368 } else { 369 $ipstring = get_string("none"); 370 } 371 echo html_writer::tag('dt', get_string('lastip')); 372 echo html_writer::tag('dd', $ipstring); 373 } 374 echo html_writer::end_tag('dl'); 375 echo "</div></div>"; // Closing desriptionbox and userprofilebox. 376 // Print messaging link if allowed. 377 if (isloggedin() && has_capability('moodle/site:sendmessage', $usercontext) 378 && !empty($CFG->messaging) && !isguestuser() && !isguestuser($user) && ($USER->id != $user->id)) { 379 echo '<div class="messagebox">'; 380 $sendmessageurl = new moodle_url('/message/index.php', array('id' => $user->id)); 381 if ($courseid) { 382 $sendmessageurl->param('viewing', MESSAGE_VIEW_COURSE. $courseid); 383 } 384 echo html_writer::link($sendmessageurl, get_string('messageselectadd')); 385 echo '</div>'; 386 } 387 388 if ($currentuser || has_capability('moodle/user:viewdetails', $usercontext) || has_coursecontact_role($id)) { 389 echo '<div class="fullprofilelink">'; 390 echo html_writer::link($CFG->wwwroot.'/user/profile.php?id='.$id, get_string('fullprofile')); 391 echo '</div>'; 392 } 393 394 // TODO Add more useful overview info for teachers here, see below. 395 // Show links to notes made about this student (must click to display, for privacy). 396 // Recent comments made in this course. 397 // Recent blogs associated with this course and items in it. 398 399 400 401 echo '</div>'; // Userprofile class. 402 403 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |