Automatic installer lang files (20100928)
[moodle.git] / user / profile.php
blobbddcac941e10d470c4b3a1acfca0437698de6dd3
1 <?php
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.
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/>.
18 /**
19 * Public Profile -- a user's public profile page
21 * - each user can currently have their own page (cloned from system and then customised)
22 * - users can add any blocks they want
23 * - the administrators can define a default site public profile for users who have
24 * not created their own public profile
26 * This script implements the user's view of the public profile, and allows editing
27 * of the public profile.
29 * @package moodlecore
30 * @subpackage my
31 * @copyright 2010 Remote-Learner.net
32 * @author Hubert Chathi <hubert@remote-learner.net>
33 * @author Olav Jordan <olav.jordan@remote-learner.net>
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 require_once(dirname(__FILE__) . '/../config.php');
38 require_once($CFG->dirroot . '/my/lib.php');
39 require_once($CFG->dirroot . '/user/profile/lib.php');
41 $userid = optional_param('id', 0, PARAM_INT);
42 $edit = optional_param('edit', null, PARAM_BOOL); // Turn editing on and off
44 if (!empty($CFG->forceloginforprofiles)) {
45 require_login();
46 if (isguestuser()) {
47 redirect(get_login_url());
49 } else if (!empty($CFG->forcelogin)) {
50 require_login();
53 $userid = $userid ? $userid : $USER->id; // Owner of the page
54 $user = $DB->get_record('user', array('id' => $userid));
55 $currentuser = ($user->id == $USER->id);
56 $context = $usercontext = get_context_instance(CONTEXT_USER, $userid, MUST_EXIST);
58 if (!$currentuser &&
59 !empty($CFG->forceloginforprofiles) &&
60 !has_capability('moodle/user:viewdetails', $context) &&
61 !has_coursecontact_role($userid)) {
62 // Course managers can be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
63 $struser = get_string('user');
64 $PAGE->set_title("$SITE->shortname: $struser"); // Do not leak the name
65 $PAGE->set_heading("$SITE->shortname: $struser");
66 $PAGE->set_url('/user/profile.php', array('id'=>$userid));
67 $PAGE->navbar->add($struser);
68 echo $OUTPUT->header();
69 echo $OUTPUT->heading(get_string('usernotavailable', 'error'));
70 echo $OUTPUT->footer();
71 exit;
74 // Get the profile page. Should always return something unless the database is broken.
75 if (!$currentpage = my_get_page($userid, MY_PAGE_PUBLIC)) {
76 print_error('mymoodlesetup');
79 if (!$currentpage->userid) {
80 $context = get_context_instance(CONTEXT_SYSTEM); // A trick so that we even see non-sticky blocks
83 $PAGE->set_context($context);
84 $PAGE->set_pagelayout('mydashboard');
85 $PAGE->set_pagetype('user-profile');
87 // Set up block editing capabilities
88 if (isguestuser()) { // Guests can never edit their profile
89 $USER->editing = $edit = 0; // Just in case
90 $PAGE->set_blocks_editing_capability('moodle/my:configsyspages'); // unlikely :)
91 } else {
92 if ($currentuser) {
93 $PAGE->set_blocks_editing_capability('moodle/user:manageownblocks');
94 } else {
95 $PAGE->set_blocks_editing_capability('moodle/user:manageblocks');
99 if (has_capability('moodle/user:viewhiddendetails', $context)) {
100 $hiddenfields = array();
101 } else {
102 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
105 // Start setting up the page
106 $strpublicprofile = get_string('publicprofile');
108 $params = array('id'=>$userid);
109 $PAGE->set_url('/user/profile.php', $params);
110 $PAGE->blocks->add_region('content');
111 $PAGE->set_subpage($currentpage->id);
112 $PAGE->set_title(fullname($user).": $strpublicprofile");
113 $PAGE->set_heading(fullname($user).": $strpublicprofile");
115 if (!$currentuser) {
116 $PAGE->navigation->extend_for_user($user);
117 if ($node = $PAGE->settingsnav->get('userviewingsettings'.$user->id)) {
118 $node->forceopen = true;
120 } else if ($node = $PAGE->settingsnav->get('usercurrentsettings', navigation_node::TYPE_CONTAINER)) {
121 $node->forceopen = true;
123 if ($node = $PAGE->settingsnav->get('root')) {
124 $node->forceopen = false;
128 // Toggle the editing state and switches
129 if ($PAGE->user_allowed_editing()) {
130 if ($edit !== null) { // Editing state was specified
131 $USER->editing = $edit; // Change editing state
132 if (!$currentpage->userid && $edit) {
133 // If we are viewing a system page as ordinary user, and the user turns
134 // editing on, copy the system pages as new user pages, and get the
135 // new page record
136 if (!$currentpage = my_copy_page($USER->id, MY_PAGE_PUBLIC, 'user-profile')) {
137 print_error('mymoodlesetup');
139 $PAGE->set_context($usercontext);
140 $PAGE->set_subpage($currentpage->id);
142 } else { // Editing state is in session
143 if ($currentpage->userid) { // It's a page we can edit, so load from session
144 if (!empty($USER->editing)) {
145 $edit = 1;
146 } else {
147 $edit = 0;
149 } else { // It's a system page and they are not allowed to edit system pages
150 $USER->editing = $edit = 0; // Disable editing completely, just to be safe
154 // Add button for editing page
155 $params = array('edit' => !$edit);
157 if (!$currentpage->userid) {
158 // viewing a system page -- let the user customise it
159 $editstring = get_string('updatemymoodleon');
160 $params['edit'] = 1;
161 } else if (empty($edit)) {
162 $editstring = get_string('updatemymoodleon');
163 } else {
164 $editstring = get_string('updatemymoodleoff');
167 $url = new moodle_url("$CFG->wwwroot/user/profile.php", $params);
168 $button = $OUTPUT->single_button($url, $editstring);
169 $PAGE->set_button($button);
171 } else {
172 $USER->editing = $edit = 0;
175 // HACK WARNING! This loads up all this page's blocks in the system context
176 if ($currentpage->userid == 0) {
177 $CFG->blockmanagerclass = 'my_syspage_block_manager';
180 // TODO WORK OUT WHERE THE NAV BAR IS!
182 echo $OUTPUT->header();
183 echo '<div class="userprofile">';
186 // Print the standard content of this page, the basic profile info
188 echo $OUTPUT->heading(fullname($user));
190 if (is_mnet_remote_user($user)) {
191 $sql = "SELECT h.id, h.name, h.wwwroot,
192 a.name as application, a.display_name
193 FROM {mnet_host} h, {mnet_application} a
194 WHERE h.id = ? AND h.applicationid = a.id";
196 $remotehost = $DB->get_record_sql($sql, array($user->mnethostid));
197 $a = new stdclass();
198 $a->remotetype = $remotehost->display_name;
199 $a->remotename = $remotehost->name;
200 $a->remoteurl = $remotehost->wwwroot;
202 echo $OUTPUT->box(get_string('remoteuserinfo', 'mnet', $a), 'remoteuserinfo');
205 echo '<div class="userprofilebox clearfix"><div class="profilepicture">';
206 echo $OUTPUT->user_picture($user, array('size'=>100));
207 echo '</div>';
209 echo '<div class="descriptionbox"><div class="description">';
210 // Print the description
212 if ($user->description && !isset($hiddenfields['description'])) {
213 if (!empty($CFG->profilesforenrolledusersonly) && !$currentuser && !$DB->record_exists('role_assignments', array('userid'=>$user->id))) {
214 echo get_string('profilenotshown', 'moodle');
215 } else {
216 $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $usercontext->id, 'user', 'profile', null);
217 echo format_text($user->description, $user->descriptionformat);
220 echo '</div>';
223 // Print all the little details in a list
225 echo '<table class="list" summary="">';
227 if (! isset($hiddenfields['country']) && $user->country) {
228 print_row(get_string('country') . ':', get_string($user->country, 'countries'));
231 if (! isset($hiddenfields['city']) && $user->city) {
232 print_row(get_string('city') . ':', $user->city);
235 if (has_capability('moodle/user:viewhiddendetails', $context)) {
236 if ($user->address) {
237 print_row(get_string("address").":", "$user->address");
239 if ($user->phone1) {
240 print_row(get_string("phone").":", "$user->phone1");
242 if ($user->phone2) {
243 print_row(get_string("phone2").":", "$user->phone2");
247 if ($user->maildisplay == 1
248 or ($user->maildisplay == 2 && !isguestuser())
249 or has_capability('moodle/course:useremail', $context)) {
251 $emailswitch = '';
253 if ($currentuser or has_capability('moodle/course:useremail', $context)) { /// Can use the enable/disable email stuff
254 if (!empty($enable) and confirm_sesskey()) { /// Recieved a parameter to enable the email address
255 $DB->set_field('user', 'emailstop', 0, array('id'=>$user->id));
256 $user->emailstop = 0;
258 if (!empty($disable) and confirm_sesskey()) { /// Recieved a parameter to disable the email address
259 $DB->set_field('user', 'emailstop', 1, array('id'=>$user->id));
260 $user->emailstop = 1;
264 if (has_capability('moodle/course:useremail', $context)) { /// Can use the enable/disable email stuff
265 if ($user->emailstop) {
266 $switchparam = 'enable';
267 $switchtitle = get_string('emaildisable');
268 $switchclick = get_string('emailenableclick');
269 $switchpix = 't/emailno';
270 } else {
271 $switchparam = 'disable';
272 $switchtitle = get_string('emailenable');
273 $switchclick = get_string('emaildisableclick');
274 $switchpix = 't/email';
276 $emailswitch = "&nbsp;<a title=\"$switchclick\" ".
277 "href=\"profile.php?id=$user->id&amp;$switchparam=1&amp;sesskey=".sesskey()."\">".
278 "<img src=\"" . $OUTPUT->pix_url("$switchpix") . "\" alt=\"$switchclick\" /></a>";
280 } else if ($currentuser) { /// Can only re-enable an email this way
281 if ($user->emailstop) { // Include link that tells how to re-enable their email
282 $switchparam = 'enable';
283 $switchtitle = get_string('emaildisable');
284 $switchclick = get_string('emailenableclick');
286 $emailswitch = "&nbsp;(<a title=\"$switchclick\" ".
287 "href=\"profile.php?id=$user->id&amp;enable=1&amp;sesskey=".sesskey()."\">$switchtitle</a>)";
291 print_row(get_string("email").":", obfuscate_mailto($user->email, '', $user->emailstop)."$emailswitch");
294 if ($user->url && !isset($hiddenfields['webpage'])) {
295 $url = $user->url;
296 if (strpos($user->url, '://') === false) {
297 $url = 'http://'. $url;
299 print_row(get_string("webpage") .":", '<a href="'.s($url).'">'.s($user->url).'</a>');
302 if ($user->icq && !isset($hiddenfields['icqnumber'])) {
303 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>");
306 if ($user->skype && !isset($hiddenfields['skypeid'])) {
307 print_row(get_string('skypeid').':','<a href="callto:'.urlencode($user->skype).'">'.s($user->skype).
308 ' <img src="http://mystatus.skype.com/smallicon/'.urlencode($user->skype).'" alt="'.get_string('status').'" '.
309 ' /></a>');
311 if ($user->yahoo && !isset($hiddenfields['yahooid'])) {
312 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>");
314 if ($user->aim && !isset($hiddenfields['aimid'])) {
315 print_row(get_string('aimid').':', '<a href="aim:goim?screenname='.urlencode($user->aim).'">'.s($user->aim).'</a>');
317 if ($user->msn && !isset($hiddenfields['msnid'])) {
318 print_row(get_string('msnid').':', s($user->msn));
321 /// Print the Custom User Fields
322 profile_display_fields($user->id);
325 if (!isset($hiddenfields['mycourses'])) {
326 if ($mycourses = enrol_get_users_courses($user->id, true, NULL, 'visible DESC,sortorder ASC')) {
327 $shown=0;
328 $courselisting = '';
329 foreach ($mycourses as $mycourse) {
330 if ($mycourse->category) {
331 $class = '';
332 if ($mycourse->visible == 0) {
333 $ccontext = get_context_instance(CONTEXT_COURSE, $mycourse->id);
334 if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) {
335 continue;
337 $class = 'class="dimmed"';
339 $courselisting .= "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&amp;course={$mycourse->id}\" $class >" . format_string($mycourse->fullname) . "</a>, ";
341 $shown++;
342 if($shown==20) {
343 $courselisting.= "...";
344 break;
347 print_row(get_string('courseprofiles').':', rtrim($courselisting,', '));
350 if (!isset($hiddenfields['firstaccess'])) {
351 if ($user->firstaccess) {
352 $datestring = userdate($user->firstaccess)."&nbsp; (".format_time(time() - $user->firstaccess).")";
353 } else {
354 $datestring = get_string("never");
356 print_row(get_string("firstaccess").":", $datestring);
358 if (!isset($hiddenfields['lastaccess'])) {
359 if ($user->lastaccess) {
360 $datestring = userdate($user->lastaccess)."&nbsp; (".format_time(time() - $user->lastaccess).")";
361 } else {
362 $datestring = get_string("never");
364 print_row(get_string("lastaccess").":", $datestring);
367 /// Printing tagged interests
368 if (!empty($CFG->usetags)) {
369 if ($interests = tag_get_tags_csv('user', $user->id) ) {
370 print_row(get_string('interests') .": ", $interests);
374 echo "</table></div></div>";
377 echo $OUTPUT->blocks_for_region('content');
379 // Print messaging link if allowed
380 if (isloggedin() && has_capability('moodle/site:sendmessage', $context)
381 && !empty($CFG->messaging) && !isguestuser() && !isguestuser($user) && ($USER->id != $user->id)) {
382 echo '<div class="messagebox">';
383 echo '<a href="'.$CFG->wwwroot.'/message/index.php?id='.$user->id.'">'.get_string('messageselectadd').'</a>';
384 echo '</div>';
387 if ($CFG->debugdisplay && debugging('', DEBUG_DEVELOPER) && $currentuser) { // Show user object
388 echo '<br /><br /><hr />';
389 echo $OUTPUT->heading('DEBUG MODE: User session variables');
390 print_object($USER);
393 echo '</div>'; // userprofile class
394 echo $OUTPUT->footer();
397 function print_row($left, $right) {
398 echo "\n<tr><td class=\"label c0\">$left</td><td class=\"info c1\">$right</td></tr>\n";