|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00037 require_once(dirname(__FILE__) . '/../config.php'); 00038 require_once($CFG->dirroot . '/my/lib.php'); 00039 require_once($CFG->dirroot . '/tag/lib.php'); 00040 require_once($CFG->dirroot . '/user/profile/lib.php'); 00041 require_once($CFG->libdir.'/filelib.php'); 00042 00043 $userid = optional_param('id', 0, PARAM_INT); 00044 $edit = optional_param('edit', null, PARAM_BOOL); // Turn editing on and off 00045 00046 $PAGE->set_url('/user/profile.php', array('id'=>$userid)); 00047 00048 if (!empty($CFG->forceloginforprofiles)) { 00049 require_login(); 00050 if (isguestuser()) { 00051 $SESSION->wantsurl = $PAGE->url->out(false); 00052 redirect(get_login_url()); 00053 } 00054 } else if (!empty($CFG->forcelogin)) { 00055 require_login(); 00056 } 00057 00058 $userid = $userid ? $userid : $USER->id; // Owner of the page 00059 $user = $DB->get_record('user', array('id' => $userid)); 00060 00061 if ($user->deleted) { 00062 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); 00063 echo $OUTPUT->header(); 00064 echo $OUTPUT->heading(get_string('userdeleted')); 00065 echo $OUTPUT->footer(); 00066 die; 00067 } 00068 00069 $currentuser = ($user->id == $USER->id); 00070 $context = $usercontext = get_context_instance(CONTEXT_USER, $userid, MUST_EXIST); 00071 00072 if (!$currentuser && 00073 !empty($CFG->forceloginforprofiles) && 00074 !has_capability('moodle/user:viewdetails', $context) && 00075 !has_coursecontact_role($userid)) { 00076 00077 // Course managers can be browsed at site level. If not forceloginforprofiles, allow access (bug #4366) 00078 $struser = get_string('user'); 00079 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); 00080 $PAGE->set_title("$SITE->shortname: $struser"); // Do not leak the name 00081 $PAGE->set_heading("$SITE->shortname: $struser"); 00082 $PAGE->set_url('/user/profile.php', array('id'=>$userid)); 00083 $PAGE->navbar->add($struser); 00084 echo $OUTPUT->header(); 00085 echo $OUTPUT->heading(get_string('usernotavailable', 'error')); 00086 echo $OUTPUT->footer(); 00087 exit; 00088 } 00089 00090 // Get the profile page. Should always return something unless the database is broken. 00091 if (!$currentpage = my_get_page($userid, MY_PAGE_PUBLIC)) { 00092 print_error('mymoodlesetup'); 00093 } 00094 00095 if (!$currentpage->userid) { 00096 $context = get_context_instance(CONTEXT_SYSTEM); // A trick so that we even see non-sticky blocks 00097 } 00098 00099 $PAGE->set_context($context); 00100 $PAGE->set_pagelayout('mydashboard'); 00101 $PAGE->set_pagetype('user-profile'); 00102 00103 // Set up block editing capabilities 00104 if (isguestuser()) { // Guests can never edit their profile 00105 $USER->editing = $edit = 0; // Just in case 00106 $PAGE->set_blocks_editing_capability('moodle/my:configsyspages'); // unlikely :) 00107 } else { 00108 if ($currentuser) { 00109 $PAGE->set_blocks_editing_capability('moodle/user:manageownblocks'); 00110 } else { 00111 $PAGE->set_blocks_editing_capability('moodle/user:manageblocks'); 00112 } 00113 } 00114 00115 if (has_capability('moodle/user:viewhiddendetails', $context)) { 00116 $hiddenfields = array(); 00117 } else { 00118 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields)); 00119 } 00120 00121 // Start setting up the page 00122 $strpublicprofile = get_string('publicprofile'); 00123 00124 $PAGE->blocks->add_region('content'); 00125 $PAGE->set_subpage($currentpage->id); 00126 $PAGE->set_title(fullname($user).": $strpublicprofile"); 00127 $PAGE->set_heading(fullname($user).": $strpublicprofile"); 00128 00129 if (!$currentuser) { 00130 $PAGE->navigation->extend_for_user($user); 00131 if ($node = $PAGE->settingsnav->get('userviewingsettings'.$user->id)) { 00132 $node->forceopen = true; 00133 } 00134 } else if ($node = $PAGE->settingsnav->get('usercurrentsettings', navigation_node::TYPE_CONTAINER)) { 00135 $node->forceopen = true; 00136 } 00137 if ($node = $PAGE->settingsnav->get('root')) { 00138 $node->forceopen = false; 00139 } 00140 00141 00142 // Toggle the editing state and switches 00143 if ($PAGE->user_allowed_editing()) { 00144 if ($edit !== null) { // Editing state was specified 00145 $USER->editing = $edit; // Change editing state 00146 if (!$currentpage->userid && $edit) { 00147 // If we are viewing a system page as ordinary user, and the user turns 00148 // editing on, copy the system pages as new user pages, and get the 00149 // new page record 00150 if (!$currentpage = my_copy_page($USER->id, MY_PAGE_PUBLIC, 'user-profile')) { 00151 print_error('mymoodlesetup'); 00152 } 00153 $PAGE->set_context($usercontext); 00154 $PAGE->set_subpage($currentpage->id); 00155 } 00156 } else { // Editing state is in session 00157 if ($currentpage->userid) { // It's a page we can edit, so load from session 00158 if (!empty($USER->editing)) { 00159 $edit = 1; 00160 } else { 00161 $edit = 0; 00162 } 00163 } else { // It's a system page and they are not allowed to edit system pages 00164 $USER->editing = $edit = 0; // Disable editing completely, just to be safe 00165 } 00166 } 00167 00168 // Add button for editing page 00169 $params = array('edit' => !$edit); 00170 00171 if (!$currentpage->userid) { 00172 // viewing a system page -- let the user customise it 00173 $editstring = get_string('updatemymoodleon'); 00174 $params['edit'] = 1; 00175 } else if (empty($edit)) { 00176 $editstring = get_string('updatemymoodleon'); 00177 } else { 00178 $editstring = get_string('updatemymoodleoff'); 00179 } 00180 00181 $url = new moodle_url("$CFG->wwwroot/user/profile.php", $params); 00182 $button = $OUTPUT->single_button($url, $editstring); 00183 $PAGE->set_button($button); 00184 00185 } else { 00186 $USER->editing = $edit = 0; 00187 } 00188 00189 // HACK WARNING! This loads up all this page's blocks in the system context 00190 if ($currentpage->userid == 0) { 00191 $CFG->blockmanagerclass = 'my_syspage_block_manager'; 00192 } 00193 00194 // TODO WORK OUT WHERE THE NAV BAR IS! 00195 00196 echo $OUTPUT->header(); 00197 echo '<div class="userprofile">'; 00198 00199 00200 // Print the standard content of this page, the basic profile info 00201 00202 echo $OUTPUT->heading(fullname($user)); 00203 00204 if (is_mnet_remote_user($user)) { 00205 $sql = "SELECT h.id, h.name, h.wwwroot, 00206 a.name as application, a.display_name 00207 FROM {mnet_host} h, {mnet_application} a 00208 WHERE h.id = ? AND h.applicationid = a.id"; 00209 00210 $remotehost = $DB->get_record_sql($sql, array($user->mnethostid)); 00211 $a = new stdclass(); 00212 $a->remotetype = $remotehost->display_name; 00213 $a->remotename = $remotehost->name; 00214 $a->remoteurl = $remotehost->wwwroot; 00215 00216 echo $OUTPUT->box(get_string('remoteuserinfo', 'mnet', $a), 'remoteuserinfo'); 00217 } 00218 00219 echo '<div class="userprofilebox clearfix"><div class="profilepicture">'; 00220 echo $OUTPUT->user_picture($user, array('size'=>100)); 00221 echo '</div>'; 00222 00223 echo '<div class="descriptionbox"><div class="description">'; 00224 // Print the description 00225 00226 if ($user->description && !isset($hiddenfields['description'])) { 00227 if (!empty($CFG->profilesforenrolledusersonly) && !$currentuser && !$DB->record_exists('role_assignments', array('userid'=>$user->id))) { 00228 echo get_string('profilenotshown', 'moodle'); 00229 } else { 00230 $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $usercontext->id, 'user', 'profile', null); 00231 $options = array('overflowdiv'=>true); 00232 echo format_text($user->description, $user->descriptionformat, $options); 00233 } 00234 } 00235 echo '</div>'; 00236 00237 00238 // Print all the little details in a list 00239 00240 echo '<table class="list" summary="">'; 00241 00242 if (! isset($hiddenfields['country']) && $user->country) { 00243 print_row(get_string('country') . ':', get_string($user->country, 'countries')); 00244 } 00245 00246 if (! isset($hiddenfields['city']) && $user->city) { 00247 print_row(get_string('city') . ':', $user->city); 00248 } 00249 00250 if (has_capability('moodle/user:viewhiddendetails', $context)) { 00251 if ($user->address) { 00252 print_row(get_string("address").":", "$user->address"); 00253 } 00254 if ($user->phone1) { 00255 print_row(get_string("phone").":", "$user->phone1"); 00256 } 00257 if ($user->phone2) { 00258 print_row(get_string("phone2").":", "$user->phone2"); 00259 } 00260 } 00261 00262 if ($currentuser 00263 or $user->maildisplay == 1 00264 or has_capability('moodle/course:useremail', $context) 00265 or ($user->maildisplay == 2 and enrol_sharing_course($user, $USER))) { 00266 00267 print_row(get_string("email").":", obfuscate_mailto($user->email, '')); 00268 } 00269 00270 if ($user->url && !isset($hiddenfields['webpage'])) { 00271 $url = $user->url; 00272 if (strpos($user->url, '://') === false) { 00273 $url = 'http://'. $url; 00274 } 00275 print_row(get_string("webpage") .":", '<a href="'.s($url).'">'.s($user->url).'</a>'); 00276 } 00277 00278 if ($user->icq && !isset($hiddenfields['icqnumber'])) { 00279 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)."&img=5\" alt=\"\" /></a>"); 00280 } 00281 00282 if ($user->skype && !isset($hiddenfields['skypeid'])) { 00283 print_row(get_string('skypeid').':','<a href="callto:'.urlencode($user->skype).'">'.s($user->skype). 00284 ' <img src="http://mystatus.skype.com/smallicon/'.urlencode($user->skype).'" alt="'.get_string('status').'" '. 00285 ' /></a>'); 00286 } 00287 if ($user->yahoo && !isset($hiddenfields['yahooid'])) { 00288 print_row(get_string('yahooid').':', '<a href="http://edit.yahoo.com/config/send_webmesg?.target='.urlencode($user->yahoo).'&.src=pg">'.s($user->yahoo)." <img src=\"http://opi.yahoo.com/online?u=".urlencode($user->yahoo)."&m=g&t=0\" alt=\"\"></a>"); 00289 } 00290 if ($user->aim && !isset($hiddenfields['aimid'])) { 00291 print_row(get_string('aimid').':', '<a href="aim:goim?screenname='.urlencode($user->aim).'">'.s($user->aim).'</a>'); 00292 } 00293 if ($user->msn && !isset($hiddenfields['msnid'])) { 00294 print_row(get_string('msnid').':', s($user->msn)); 00295 } 00296 00298 profile_display_fields($user->id); 00299 00300 00301 if (!isset($hiddenfields['mycourses'])) { 00302 if ($mycourses = enrol_get_users_courses($user->id, true, NULL, 'visible DESC,sortorder ASC')) { 00303 $shown=0; 00304 $courselisting = ''; 00305 foreach ($mycourses as $mycourse) { 00306 if ($mycourse->category) { 00307 $class = ''; 00308 if ($mycourse->visible == 0) { 00309 $ccontext = get_context_instance(CONTEXT_COURSE, $mycourse->id); 00310 if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) { 00311 continue; 00312 } 00313 $class = 'class="dimmed"'; 00314 } 00315 $courselisting .= "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&course={$mycourse->id}\" $class >" . format_string($mycourse->fullname) . "</a>, "; 00316 } 00317 $shown++; 00318 if($shown==20) { 00319 $courselisting.= "..."; 00320 break; 00321 } 00322 } 00323 print_row(get_string('courseprofiles').':', rtrim($courselisting,', ')); 00324 } 00325 } 00326 if (!isset($hiddenfields['firstaccess'])) { 00327 if ($user->firstaccess) { 00328 $datestring = userdate($user->firstaccess)." (".format_time(time() - $user->firstaccess).")"; 00329 } else { 00330 $datestring = get_string("never"); 00331 } 00332 print_row(get_string("firstaccess").":", $datestring); 00333 } 00334 if (!isset($hiddenfields['lastaccess'])) { 00335 if ($user->lastaccess) { 00336 $datestring = userdate($user->lastaccess)." (".format_time(time() - $user->lastaccess).")"; 00337 } else { 00338 $datestring = get_string("never"); 00339 } 00340 print_row(get_string("lastaccess").":", $datestring); 00341 } 00342 00344 if (!empty($CFG->usetags)) { 00345 if ($interests = tag_get_tags_csv('user', $user->id) ) { 00346 print_row(get_string('interests') .": ", $interests); 00347 } 00348 } 00349 00350 if (!isset($hiddenfields['suspended'])) { 00351 if ($user->suspended) { 00352 print_row('', get_string('suspended', 'auth')); 00353 } 00354 } 00355 00356 echo "</table></div></div>"; 00357 00358 00359 echo $OUTPUT->blocks_for_region('content'); 00360 00361 // Print messaging link if allowed 00362 if (isloggedin() && has_capability('moodle/site:sendmessage', $context) 00363 && !empty($CFG->messaging) && !isguestuser() && !isguestuser($user) && ($USER->id != $user->id)) { 00364 echo '<div class="messagebox">'; 00365 echo '<a href="'.$CFG->wwwroot.'/message/index.php?id='.$user->id.'">'.get_string('messageselectadd').'</a>'; 00366 echo '</div>'; 00367 } 00368 00369 if ($CFG->debugdisplay && debugging('', DEBUG_DEVELOPER) && $currentuser) { // Show user object 00370 echo '<br /><br /><hr />'; 00371 echo $OUTPUT->heading('DEBUG MODE: User session variables'); 00372 print_object($USER); 00373 } 00374 00375 echo '</div>'; // userprofile class 00376 echo $OUTPUT->footer(); 00377 00378 00379 function print_row($left, $right) { 00380 echo "\n<tr><td class=\"label c0\">$left</td><td class=\"info c1\">$right</td></tr>\n"; 00381 }