2001-11-22 06:23:56 +00:00
< ? PHP // $Id$
// Display profile for a particular user
2007-08-17 19:09:11 +00:00
2003-01-05 14:19:20 +00:00
require_once ( " ../config.php " );
2007-04-16 02:49:33 +00:00
require_once ( $CFG -> dirroot . '/user/profile/lib.php' );
2007-07-31 08:09:46 +00:00
require_once ( $CFG -> dirroot . '/tag/lib.php' );
2007-08-17 19:09:11 +00:00
2005-04-04 03:55:37 +00:00
$id = optional_param ( 'id' , 0 , PARAM_INT ); // user id
$course = optional_param ( 'course' , SITEID , PARAM_INT ); // course id (defaults to Site)
$enable = optional_param ( 'enable' , '' ); // enable email
$disable = optional_param ( 'disable' , '' ); // disable email
2001-11-22 06:23:56 +00:00
2004-09-25 12:53:35 +00:00
if ( empty ( $id )) { // See your own profile by default
require_login ();
$id = $USER -> id ;
}
2008-05-31 11:13:21 +00:00
if ( ! $user = $DB -> get_record ( " user " , array ( " id " => $id ))) {
2008-06-13 07:07:45 +00:00
print_error ( 'invaliduserid' );
2001-11-22 06:23:56 +00:00
}
2008-05-31 11:13:21 +00:00
if ( ! $course = $DB -> get_record ( " course " , array ( " id " => $course ))) {
2008-06-13 07:07:45 +00:00
print_error ( 'invalidcourseid' );
2001-11-22 06:23:56 +00:00
}
2009-05-25 21:46:28 +00:00
// special hack for cli installer - continue to site settings
$systemcontext = get_context_instance ( CONTEXT_SYSTEM );
if ( $SITE -> shortname === '' and has_capability ( 'moodle/site:config' , $systemcontext )) {
redirect ( $CFG -> wwwroot . '/' . $CFG -> admin . '/index.php' );
}
2009-07-20 05:40:32 +00:00
/// Set up page URL for blocks etc
if ( $course -> id == SITEID ) {
$PAGE -> set_url ( 'user/view.php' , array ( 'id' => $user -> id ));
} else {
$PAGE -> set_url ( 'user/view.php' , array ( 'id' => $user -> id , 'course' => $course -> id ));
}
2006-10-01 05:26:38 +00:00
/// Make sure the current user is allowed to see this user
if ( empty ( $USER -> id )) {
$currentuser = false ;
} else {
$currentuser = ( $user -> id == $USER -> id );
}
2006-10-04 02:14:25 +00:00
if ( $course -> id == SITEID ) {
2007-04-26 21:41:08 +00:00
$coursecontext = get_context_instance ( CONTEXT_SYSTEM ); // SYSTEM context
2006-10-04 02:14:25 +00:00
} else {
$coursecontext = get_context_instance ( CONTEXT_COURSE , $course -> id ); // Course context
}
2006-10-01 05:26:38 +00:00
$usercontext = get_context_instance ( CONTEXT_USER , $user -> id ); // User context
2007-08-17 19:09:11 +00:00
2009-07-20 06:57:43 +00:00
$PAGE -> set_context ( $usercontext );
2009-07-20 06:09:27 +00:00
2007-03-07 06:22:58 +00:00
if ( ! empty ( $CFG -> forcelogin ) || $course -> id != SITEID ) {
// do not force parents to enrol
2008-05-31 11:13:21 +00:00
if ( ! $DB -> get_record ( 'role_assignments' , array ( 'userid' => $USER -> id , 'contextid' => $usercontext -> id ))) {
2007-03-07 06:22:58 +00:00
require_login ( $course -> id );
}
}
2007-08-17 19:09:11 +00:00
2005-12-28 19:54:08 +00:00
if ( ! empty ( $CFG -> forceloginforprofiles )) {
require_login ();
2004-05-03 15:03:31 +00:00
if ( isguest ()) {
2009-01-02 22:56:48 +00:00
redirect ( get_login_url ());
2004-05-03 15:03:31 +00:00
}
2001-11-22 06:23:56 +00:00
}
2006-10-29 04:21:23 +00:00
$strpersonalprofile = get_string ( 'personalprofile' );
$strparticipants = get_string ( " participants " );
$struser = get_string ( " user " );
2001-11-22 06:23:56 +00:00
2006-10-29 04:21:23 +00:00
$fullname = fullname ( $user , has_capability ( 'moodle/site:viewfullnames' , $coursecontext ));
2003-10-27 14:15:05 +00:00
2007-08-17 19:09:11 +00:00
$navlinks = array ();
2007-11-30 12:08:01 +00:00
if ( has_capability ( 'moodle/course:viewparticipants' , $coursecontext ) || has_capability ( 'moodle/site:viewparticipants' , $systemcontext )) {
$navlinks [] = array ( 'name' => $strparticipants , 'link' => " index.php?id= $course->id " , 'type' => 'misc' );
}
2007-08-17 19:09:11 +00:00
2006-10-29 04:21:23 +00:00
/// If the user being shown is not ourselves, then make sure we are allowed to see them!
2002-07-04 07:52:06 +00:00
2006-10-29 04:21:23 +00:00
if ( ! $currentuser ) {
if ( $course -> id == SITEID ) { // Reduce possibility of "browsing" userbase at site level
2007-08-17 19:09:11 +00:00
if ( $CFG -> forceloginforprofiles and ! isteacherinanycourse ()
and ! isteacherinanycourse ( $user -> id )
and ! has_capability ( 'moodle/user:viewdetails' , $usercontext )) { // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
$navlinks [] = array ( 'name' => $struser , 'link' => null , 'type' => 'misc' );
$navigation = build_navigation ( $navlinks );
print_header ( " $strpersonalprofile : " , " $strpersonalprofile : " , $navigation , " " , " " , true , " " , navmenu ( $course ));
2009-08-06 08:15:05 +00:00
echo $OUTPUT -> heading ( get_string ( 'usernotavailable' , 'error' ));
2009-08-06 14:19:50 +00:00
echo $OUTPUT -> footer ();
2006-10-29 04:21:23 +00:00
exit ;
}
} else { // Normal course
2007-09-06 07:09:36 +00:00
// check capabilities
if ( ! has_capability ( 'moodle/user:viewdetails' , $coursecontext ) &&
! has_capability ( 'moodle/user:viewdetails' , $usercontext )) {
print_error ( 'cannotviewprofile' );
}
2006-10-29 04:21:23 +00:00
if ( ! has_capability ( 'moodle/course:view' , $coursecontext , $user -> id , false )) {
if ( has_capability ( 'moodle/course:view' , $coursecontext )) {
2007-08-17 19:09:11 +00:00
$navlinks [] = array ( 'name' => $fullname , 'link' => null , 'type' => 'misc' );
$navigation = build_navigation ( $navlinks );
print_header ( " $strpersonalprofile : " , " $strpersonalprofile : " , $navigation , " " , " " , true , " " , navmenu ( $course ));
2009-08-06 08:15:05 +00:00
echo $OUTPUT -> heading ( get_string ( 'notenrolled' , $fullname ));
2006-10-29 04:21:23 +00:00
} else {
2007-08-17 19:09:11 +00:00
$navlinks [] = array ( 'name' => $struser , 'link' => null , 'type' => 'misc' );
$navigation = build_navigation ( $navlinks );
print_header ( " $strpersonalprofile : " , " $strpersonalprofile : " , $navigation , " " , " " , true , " " , navmenu ( $course ));
2009-08-06 14:19:50 +00:00
echo $OUTPUT -> heading ( get_string ( 'notenrolledprofile' ));
2005-11-08 07:19:27 +00:00
}
2009-08-18 05:19:25 +00:00
echo $OUTPUT -> continue_button ( $_SERVER [ 'HTTP_REFERER' ]);
2009-08-06 14:19:50 +00:00
echo $OUTPUT -> footer ();
2006-10-29 04:21:23 +00:00
exit ;
2005-11-08 07:19:27 +00:00
}
}
2006-10-29 04:21:23 +00:00
// If groups are in use, make sure we can see that group
2007-09-08 20:53:05 +00:00
if ( groups_get_course_groupmode ( $course ) == SEPARATEGROUPS and ! has_capability ( 'moodle/site:accessallgroups' , $coursecontext )) {
2006-10-29 04:21:23 +00:00
require_login ();
2007-08-17 19:09:11 +00:00
2006-10-29 04:21:23 +00:00
///this is changed because of mygroupid
2007-08-16 11:06:48 +00:00
$gtrue = ( bool ) groups_get_all_groups ( $course -> id , $user -> id );
2006-10-29 04:21:23 +00:00
if ( ! $gtrue ) {
2007-08-17 19:09:11 +00:00
$navigation = build_navigation ( $navlinks );
print_header ( " $strpersonalprofile : " , " $strpersonalprofile : " , $navigation , " " , " " , true , " " , navmenu ( $course ));
2008-04-04 02:54:20 +00:00
print_error ( " groupnotamember " , '' , " ../course/view.php?id= $course->id " );
2006-10-29 04:21:23 +00:00
}
2004-03-09 23:07:35 +00:00
}
}
2007-08-17 19:09:11 +00:00
2004-08-12 06:57:53 +00:00
2006-10-01 05:26:38 +00:00
/// We've established they can see the user's name at least, so what about the rest?
2007-08-17 19:09:11 +00:00
$navlinks [] = array ( 'name' => $fullname , 'link' => null , 'type' => 'misc' );
$navigation = build_navigation ( $navlinks );
print_header ( " $course->fullname : $strpersonalprofile : $fullname " , $course -> fullname ,
$navigation , " " , " " , true , " " , navmenu ( $course ));
2001-11-22 06:23:56 +00:00
2004-03-13 15:22:33 +00:00
2006-11-12 08:55:13 +00:00
if (( $course -> id != SITEID ) and ! isguest () ) { // Need to have access to a course to see that info
2007-03-07 06:22:58 +00:00
if ( ! has_capability ( 'moodle/course:view' , $coursecontext , $user -> id )) {
2009-08-06 14:19:50 +00:00
echo $OUTPUT -> heading ( get_string ( 'notenrolled' , '' , $fullname ));
echo $OUTPUT -> footer ();
2002-06-10 03:49:28 +00:00
die ;
}
2002-06-04 06:49:52 +00:00
}
2002-09-22 03:01:17 +00:00
if ( $user -> deleted ) {
2009-08-06 14:19:50 +00:00
echo $OUTPUT -> heading ( get_string ( 'userdeleted' ));
2008-07-05 14:52:39 +00:00
if ( ! has_capability ( 'moodle/user:update' , $coursecontext )) {
2009-08-06 14:19:50 +00:00
echo $OUTPUT -> footer ();
2008-07-05 14:52:39 +00:00
die ;
}
2002-09-22 03:01:17 +00:00
}
2006-10-01 05:26:38 +00:00
/// OK, security out the way, now we are showing the user
add_to_log ( $course -> id , " user " , " view " , " view.php?id= $user->id &course= $course->id " , " $user->id " );
2006-10-29 04:21:23 +00:00
if ( $course -> id != SITEID ) {
2007-11-23 21:31:58 +00:00
$user -> lastaccess = false ;
2008-05-31 11:13:21 +00:00
if ( $lastaccess = $DB -> get_record ( 'user_lastaccess' , array ( 'userid' => $user -> id , 'courseid' => $course -> id ))) {
2006-10-29 04:21:23 +00:00
$user -> lastaccess = $lastaccess -> timeaccess ;
}
}
2006-10-01 05:26:38 +00:00
2006-09-15 15:04:38 +00:00
/// Get the hidden field list
if ( has_capability ( 'moodle/user:viewhiddendetails' , $coursecontext )) {
$hiddenfields = array ();
2005-11-20 21:29:59 +00:00
} else {
$hiddenfields = array_flip ( explode ( ',' , $CFG -> hiddenuserfields ));
}
2001-11-22 06:23:56 +00:00
2005-03-20 12:02:14 +00:00
/// Print tabs at top
/// This same call is made in:
/// /user/view.php
/// /user/edit.php
/// /course/user.php
2006-09-15 15:04:38 +00:00
2005-03-20 12:02:14 +00:00
$currenttab = 'profile' ;
2006-08-15 08:29:29 +00:00
$showroles = 1 ;
2008-07-05 14:52:39 +00:00
if ( ! $user -> deleted ) {
include ( 'tabs.php' );
}
2001-11-22 06:23:56 +00:00
2007-01-04 03:01:30 +00:00
if ( is_mnet_remote_user ( $user )) {
2007-07-14 03:00:12 +00:00
$sql = "
2008-05-31 11:13:21 +00:00
SELECT DISTINCT h . id , h . name , h . wwwroot ,
a . name as application , a . display_name
FROM { mnet_host } h , { mnet_application } a
WHERE h . id = ? AND h . applicationid = a . id
ORDER BY a . display_name , h . name " ;
$remotehost = $DB -> get_record_sql ( $sql , array ( $user -> mnethostid ));
2007-08-17 19:09:11 +00:00
2008-09-10 03:25:28 +00:00
echo '<p class="errorboxcontent">' . get_string ( 'remoteappuser' , $remotehost -> application ) . " <br /> \n " ;
2007-08-03 12:28:33 +00:00
if ( $USER -> id == $user -> id ) {
if ( $remotehost -> application == 'moodle' ) {
echo " Remote { $remotehost -> display_name } : <a href= \" { $remotehost -> wwwroot } /user/edit.php \" > { $remotehost -> name } </a> " . get_string ( 'editremoteprofile' ) . " </p> \n " ;
} else {
echo " Remote { $remotehost -> display_name } : <a href= \" { $remotehost -> wwwroot } / \" > { $remotehost -> name } </a> " . get_string ( 'gotoyourserver' ) . " </p> \n " ;
}
2007-07-14 03:00:12 +00:00
} else {
2007-08-03 12:28:33 +00:00
echo " Remote { $remotehost -> display_name } : <a href= \" { $remotehost -> wwwroot } / \" > { $remotehost -> name } </a></p> \n " ;
2007-07-14 03:00:12 +00:00
}
2007-01-04 03:01:30 +00:00
}
2007-01-06 14:07:00 +00:00
echo '<table width="80%" class="userinfobox" summary="">' ;
echo '<tr>' ;
echo '<td class="side">' ;
2008-02-13 17:03:25 +00:00
print_user_picture ( $user , $course -> id , $user -> picture , true , false , false );
2007-01-06 14:07:00 +00:00
echo '</td><td class="content">' ;
2001-11-22 06:23:56 +00:00
// Print the description
2005-11-20 21:29:59 +00:00
if ( $user -> description && ! isset ( $hiddenfields [ 'description' ])) {
2008-11-10 03:06:27 +00:00
$has_courseid = ( $course -> id != SITEID );
2008-11-12 01:51:28 +00:00
if ( ! $has_courseid && ! empty ( $CFG -> profilesforenrolledusersonly ) && ! $DB -> record_exists ( 'role_assignments' , array ( 'userid' => $id ))) {
2008-11-10 03:06:27 +00:00
echo get_string ( 'profilenotshown' , 'moodle' ) . '<hr />' ;
} else {
echo format_text ( $user -> description , FORMAT_MOODLE ) . " <hr /> " ;
}
2001-11-22 06:23:56 +00:00
}
// Print all the little details in a list
2007-01-06 14:07:00 +00:00
echo '<table class="list">' ;
2001-11-22 06:23:56 +00:00
2008-06-16 12:29:56 +00:00
if ( ! isset ( $hiddenfields [ 'country' ]) && $user -> country ) {
2008-06-16 02:14:59 +00:00
$countries = get_list_of_countries ();
2008-06-16 12:29:56 +00:00
print_row ( get_string ( 'country' ) . ':' , $countries [ $user -> country ]);
}
if ( ! isset ( $hiddenfields [ 'city' ]) && $user -> city ) {
print_row ( get_string ( 'city' ) . ':' , $user -> city );
2002-06-10 04:33:46 +00:00
}
2001-11-22 06:23:56 +00:00
2006-09-15 15:04:38 +00:00
if ( has_capability ( 'moodle/user:viewhiddendetails' , $coursecontext )) {
2001-11-22 06:23:56 +00:00
if ( $user -> address ) {
2002-07-04 07:52:06 +00:00
print_row ( get_string ( " address " ) . " : " , " $user->address " );
2001-11-22 06:23:56 +00:00
}
if ( $user -> phone1 ) {
2002-07-04 07:52:06 +00:00
print_row ( get_string ( " phone " ) . " : " , " $user->phone1 " );
2001-11-22 06:23:56 +00:00
}
if ( $user -> phone2 ) {
2008-03-26 02:58:16 +00:00
print_row ( get_string ( " phone2 " ) . " : " , " $user->phone2 " );
2001-11-22 06:23:56 +00:00
}
}
2004-06-22 18:34:35 +00:00
if ( $user -> maildisplay == 1 or
2006-11-12 08:55:13 +00:00
( $user -> maildisplay == 2 and ( $course -> id != SITEID ) and ! isguest ()) or
2006-12-30 21:40:22 +00:00
has_capability ( 'moodle/course:useremail' , $coursecontext )) {
2004-02-20 10:27:24 +00:00
2004-10-27 06:01:20 +00:00
$emailswitch = '' ;
2006-10-01 05:26:38 +00:00
if ( has_capability ( 'moodle/course:useremail' , $coursecontext ) or $currentuser ) { /// Can use the enable/disable email stuff
2005-06-15 09:49:18 +00:00
if ( ! empty ( $enable )) { /// Recieved a parameter to enable the email address
2008-06-02 21:39:23 +00:00
$DB -> set_field ( 'user' , 'emailstop' , 0 , array ( 'id' => $user -> id ));
2004-02-20 10:27:24 +00:00
$user -> emailstop = 0 ;
}
2005-06-15 09:49:18 +00:00
if ( ! empty ( $disable )) { /// Recieved a parameter to disable the email address
2008-06-02 21:39:23 +00:00
$DB -> set_field ( 'user' , 'emailstop' , 1 , array ( 'id' => $user -> id ));
2004-02-20 10:27:24 +00:00
$user -> emailstop = 1 ;
}
2004-10-27 06:01:20 +00:00
}
2006-10-01 05:26:38 +00:00
if ( has_capability ( 'moodle/course:useremail' , $coursecontext )) { /// Can use the enable/disable email stuff
2004-02-20 10:27:24 +00:00
if ( $user -> emailstop ) {
$switchparam = 'enable' ;
$switchtitle = get_string ( 'emaildisable' );
2004-07-24 06:37:44 +00:00
$switchclick = get_string ( 'emailenableclick' );
2009-07-03 06:19:25 +00:00
$switchpix = 't/emailno' ;
2004-02-20 10:27:24 +00:00
} else {
$switchparam = 'disable' ;
$switchtitle = get_string ( 'emailenable' );
2004-07-24 06:37:44 +00:00
$switchclick = get_string ( 'emaildisableclick' );
2009-07-03 06:19:25 +00:00
$switchpix = 't/email' ;
2004-02-20 10:27:24 +00:00
}
2005-04-18 17:57:26 +00:00
$emailswitch = " <a title= \" $switchclick\ " " .
" href= \" view.php?id= $user->id &course= $course->id & $switchparam =1 \" > " .
2009-08-10 08:24:28 +00:00
" <img src= \" " . $OUTPUT -> old_icon_url ( " $switchpix " ) . " \" alt= \" $switchclick\ " /></ a > " ;
2004-10-27 06:01:20 +00:00
} else if ( $currentuser ) { /// Can only re-enable an email this way
if ( $user -> emailstop ) { // Include link that tells how to re-enable their email
$switchparam = 'enable' ;
$switchtitle = get_string ( 'emaildisable' );
$switchclick = get_string ( 'emailenableclick' );
2005-04-18 17:57:26 +00:00
$emailswitch = " (<a title= \" $switchclick\ " " .
" href= \" view.php?id= $user->id &course= $course->id &enable=1 \" > $switchtitle </a>) " ;
2004-10-27 06:01:20 +00:00
}
2004-02-20 10:27:24 +00:00
}
print_row ( get_string ( " email " ) . " : " , obfuscate_mailto ( $user -> email , '' , $user -> emailstop ) . " $emailswitch " );
2002-08-21 13:29:25 +00:00
}
2001-11-22 06:23:56 +00:00
2005-11-20 21:29:59 +00:00
if ( $user -> url && ! isset ( $hiddenfields [ 'webpage' ])) {
2008-04-11 06:58:20 +00:00
$url = $user -> url ;
if ( strpos ( $user -> url , '://' ) === false ) {
$url = 'http://' . $url ;
}
print_row ( get_string ( " webpage " ) . " : " , " <a href= \" $url\ " > $user -> url </ a > " );
2001-11-22 06:23:56 +00:00
}
2005-11-20 21:29:59 +00:00
if ( $user -> icq && ! isset ( $hiddenfields [ 'icqnumber' ])) {
2007-01-06 14:07:00 +00:00
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 &img=5 \" alt= \" \" /></a> " );
2005-03-05 05:57:10 +00:00
}
2005-11-20 21:29:59 +00:00
if ( $user -> skype && ! isset ( $hiddenfields [ 'skypeid' ])) {
2007-08-17 19:09:11 +00:00
print_row ( get_string ( 'skypeid' ) . ':' , '<a href="callto:' . urlencode ( $user -> skype ) . '">' . s ( $user -> skype ) .
2006-11-25 18:09:33 +00:00
' <img src="http://mystatus.skype.com/smallicon/' . urlencode ( $user -> skype ) . '" alt="' . get_string ( 'status' ) . '" ' .
2007-01-06 14:07:00 +00:00
' /></a>' );
2005-03-05 05:57:10 +00:00
}
2005-11-20 21:29:59 +00:00
if ( $user -> yahoo && ! isset ( $hiddenfields [ 'yahooid' ])) {
2007-01-06 14:07:00 +00:00
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> " );
2005-03-05 05:57:10 +00:00
}
2005-11-20 21:29:59 +00:00
if ( $user -> aim && ! isset ( $hiddenfields [ 'aimid' ])) {
2005-03-05 06:26:44 +00:00
print_row ( get_string ( 'aimid' ) . ':' , '<a href="aim:goim?screenname=' . s ( $user -> aim ) . '">' . s ( $user -> aim ) . '</a>' );
2005-03-05 05:57:10 +00:00
}
2005-11-20 21:29:59 +00:00
if ( $user -> msn && ! isset ( $hiddenfields [ 'msnid' ])) {
2005-03-05 05:57:10 +00:00
print_row ( get_string ( 'msnid' ) . ':' , s ( $user -> msn ));
2001-11-22 06:23:56 +00:00
}
2007-04-16 02:49:33 +00:00
/// Print the Custom User Fields
profile_display_fields ( $user -> id );
2008-12-01 22:06:33 +00:00
if ( ! isset ( $hiddenfields [ 'mycourses' ])) {
if ( $mycourses = get_my_courses ( $user -> id , null , null , false , 21 )) {
$shown = 0 ;
$courselisting = '' ;
foreach ( $mycourses as $mycourse ) {
if ( $mycourse -> category ) {
if ( $mycourse -> id != $course -> id ){
$class = '' ;
if ( $mycourse -> visible == 0 ) {
// get_my_courses will filter courses $USER cannot see
// if we get one with visible 0 it just means it's hidden
// ... but not from $USER
$class = 'class="dimmed"' ;
}
$courselisting .= " <a href= \" { $CFG -> wwwroot } /user/view.php?id= { $user -> id } &course= { $mycourse -> id } \" $class > "
. format_string ( $mycourse -> fullname ) . " </a>, " ;
}
else {
$courselisting .= format_string ( $mycourse -> fullname ) . " , " ;
2007-09-19 07:21:47 +00:00
}
2006-11-06 02:33:13 +00:00
}
2008-12-01 22:06:33 +00:00
$shown ++ ;
if ( $shown == 20 ) {
$courselisting .= " ... " ;
break ;
2003-11-19 07:55:00 +00:00
}
}
2008-12-01 22:06:33 +00:00
print_row ( get_string ( 'courses' ) . ':' , rtrim ( $courselisting , ', ' ));
2003-11-19 07:55:00 +00:00
}
}
2009-03-11 11:22:55 +00:00
if ( ! isset ( $hiddenfields [ 'firstaccess' ])) {
if ( $user -> firstaccess ) {
$datestring = userdate ( $user -> firstaccess ) . " ( " . format_time ( time () - $user -> firstaccess ) . " ) " ;
} else {
$datestring = get_string ( " never " );
}
print_row ( get_string ( " firstaccess " ) . " : " , $datestring );
}
2005-11-20 21:29:59 +00:00
if ( ! isset ( $hiddenfields [ 'lastaccess' ])) {
if ( $user -> lastaccess ) {
$datestring = userdate ( $user -> lastaccess ) . " ( " . format_time ( time () - $user -> lastaccess ) . " ) " ;
} else {
$datestring = get_string ( " never " );
}
print_row ( get_string ( " lastaccess " ) . " : " , $datestring );
2002-09-06 15:10:36 +00:00
}
2006-08-15 08:29:29 +00:00
/// printing roles
2007-12-12 07:13:09 +00:00
if ( $rolestring = get_user_roles_in_context ( $id , $coursecontext )) {
2007-04-15 15:51:16 +00:00
print_row ( get_string ( 'roles' ) . ':' , format_string ( $rolestring , false ));
2006-09-13 06:56:25 +00:00
}
2005-11-08 07:19:27 +00:00
2006-03-07 06:22:59 +00:00
/// Printing groups
2009-04-09 08:29:51 +00:00
if ( ! isset ( $hiddenfields [ 'groups' ])) {
$isseparategroups = ( $course -> groupmode == SEPARATEGROUPS and ! has_capability ( 'moodle/site:accessallgroups' , $coursecontext ));
if ( ! $isseparategroups ){
if ( $usergroups = groups_get_all_groups ( $course -> id , $user -> id )){
$groupstr = '' ;
foreach ( $usergroups as $group ){
$groupstr .= ' <a href="' . $CFG -> wwwroot . '/user/index.php?id=' . $course -> id . '&group=' . $group -> id . '">' . format_string ( $group -> name ) . '</a>,' ;
}
print_row ( get_string ( " group " ) . " : " , rtrim ( $groupstr , ', ' ));
2005-11-08 07:19:27 +00:00
}
}
}
2006-03-07 06:22:59 +00:00
/// End of printing groups
2005-11-08 07:19:27 +00:00
2007-07-31 08:09:46 +00:00
/// Printing Interests
if ( ! empty ( $CFG -> usetags )) {
2008-02-26 06:43:54 +00:00
if ( $interests = tag_get_tags_csv ( 'user' , $user -> id ) ) {
2008-02-25 01:58:17 +00:00
print_row ( get_string ( 'interests' ) . " : " , $interests );
2007-07-31 08:09:46 +00:00
}
}
2007-08-17 19:09:11 +00:00
/// End of Printing Interests
2007-07-31 08:09:46 +00:00
2003-10-21 06:40:39 +00:00
echo " </table> " ;
2001-11-22 06:23:56 +00:00
2003-10-21 06:40:39 +00:00
echo " </td></tr></table> " ;
2001-11-22 06:23:56 +00:00
2007-01-04 03:01:30 +00:00
$userauth = get_auth_plugin ( $user -> auth );
2007-02-21 21:53:28 +00:00
$passwordchangeurl = false ;
2007-04-26 21:41:08 +00:00
if ( $currentuser and $userauth -> can_change_password () and ! isguestuser () and has_capability ( 'moodle/user:changeownpassword' , $systemcontext )) {
if ( ! $passwordchangeurl = $userauth -> change_password_url ()) {
2007-02-21 21:53:28 +00:00
if ( empty ( $CFG -> loginhttps )) {
$passwordchangeurl = " $CFG->wwwroot /login/change_password.php " ;
} else {
$passwordchangeurl = str_replace ( 'http:' , 'https:' , $CFG -> wwwroot . '/login/change_password.php' );
}
2004-06-22 18:34:35 +00:00
}
2002-11-28 12:31:46 +00:00
}
2002-06-04 06:29:36 +00:00
// Print other functions
2007-01-06 14:07:00 +00:00
echo '<div class="buttons">' ;
2005-12-02 02:37:01 +00:00
2007-04-20 10:02:38 +00:00
if ( $passwordchangeurl ) {
2007-04-21 21:20:17 +00:00
$params = array ( 'id' => $course -> id );
2009-01-02 20:32:05 +00:00
if ( session_is_loggedinas ()) {
2007-04-20 10:02:38 +00:00
$passwordchangeurl = '' ; // do not use actual change password url - might contain sensitive data
2007-04-21 21:20:17 +00:00
} else {
$parts = explode ( '?' , $passwordchangeurl );
$passwordchangeurl = reset ( $parts );
$after = next ( $parts );
preg_match_all ( '/([^&=]+)=([^&=]+)/' , $after , $matches );
if ( count ( $matches )) {
foreach ( $matches [ 0 ] as $key => $match ) {
$params [ $matches [ 1 ][ $key ]] = $matches [ 2 ][ $key ];
}
}
2007-04-20 10:02:38 +00:00
}
2007-02-21 21:53:28 +00:00
echo " <form action= \" $passwordchangeurl\ " method = \ " get \" > " ;
2007-03-01 04:30:42 +00:00
echo " <div> " ;
2007-04-21 21:20:17 +00:00
foreach ( $params as $key => $value ) {
echo '<input type="hidden" name="' . $key . '" value="' . s ( $value ) . '" />' ;
}
2009-01-02 20:32:05 +00:00
if ( session_is_loggedinas ()) {
2007-02-21 21:53:28 +00:00
// changing of password when "Logged in as" is not allowed
echo " <input type= \" submit \" value= \" " . get_string ( " changepassword " ) . " \" disabled= \" disabled \" /> " ;
} else {
2004-09-07 08:05:25 +00:00
echo " <input type= \" submit \" value= \" " . get_string ( " changepassword " ) . " \" /> " ;
2002-11-28 12:31:46 +00:00
}
2007-03-01 04:30:42 +00:00
echo " </div> " ;
2007-02-21 21:53:28 +00:00
echo " </form> " ;
2002-10-17 12:25:25 +00:00
}
2006-09-15 15:04:38 +00:00
if ( $course -> id != SITEID && empty ( $course -> metacourse )) { // Mostly only useful at course level
2008-02-05 12:59:28 +00:00
$canunenrol = false ;
if ( $user -> id == $USER -> id ) { // Myself
$canunenrol = has_capability ( 'moodle/course:view' , $coursecontext , NULL ) && // Course participant
has_capability ( 'moodle/role:unassignself' , $coursecontext , NULL , false ) && // Can unassign myself
get_user_roles ( $coursecontext , $user -> id , false ); // Must have role in course
} else if ( has_capability ( 'moodle/role:assign' , $coursecontext , NULL )) { // I can assign roles
if ( $roles = get_user_roles ( $coursecontext , $user -> id , false )) {
$canunenrol = true ;
foreach ( $roles as $role ) {
if ( ! user_can_assign ( $coursecontext , $role -> roleid )) {
$canunenrol = false ; // I can not unassign all roles in this course :-(
break ;
}
}
}
}
if ( $canunenrol ) {
echo '<form action="' . $CFG -> wwwroot . '/course/unenrol.php" method="get">' ;
echo '<div>' ;
2006-09-15 15:04:38 +00:00
echo '<input type="hidden" name="id" value="' . $course -> id . '" />' ;
echo '<input type="hidden" name="user" value="' . $user -> id . '" />' ;
2008-02-05 12:59:28 +00:00
echo '<input type="submit" value="' . s ( get_string ( 'unenrolme' , '' , $course -> shortname )) . '" />' ;
echo '</div>' ;
2007-01-06 14:07:00 +00:00
echo '</form>' ;
2006-09-15 15:04:38 +00:00
}
2003-10-31 06:50:19 +00:00
}
2006-09-15 15:04:38 +00:00
2009-01-02 20:32:05 +00:00
if ( ! $user -> deleted and $USER -> id != $user -> id && ! session_is_loggedinas () && has_capability ( 'moodle/user:loginas' , $coursecontext ) &&
2007-02-13 08:31:10 +00:00
! has_capability ( 'moodle/site:doanything' , $coursecontext , $user -> id , false )) {
2007-01-06 14:07:00 +00:00
echo '<form action="' . $CFG -> wwwroot . '/course/loginas.php" method="get">' ;
2008-02-05 12:59:28 +00:00
echo '<div>' ;
2006-09-15 15:04:38 +00:00
echo '<input type="hidden" name="id" value="' . $course -> id . '" />' ;
echo '<input type="hidden" name="user" value="' . $user -> id . '" />' ;
2007-03-19 18:54:58 +00:00
echo '<input type="hidden" name="sesskey" value="' . sesskey () . '" />' ;
2006-09-15 15:04:38 +00:00
echo '<input type="submit" value="' . get_string ( 'loginas' ) . '" />' ;
2008-02-05 12:59:28 +00:00
echo '</div>' ;
2007-01-06 14:07:00 +00:00
echo '</form>' ;
2002-07-27 10:23:45 +00:00
}
2006-10-01 05:26:38 +00:00
2008-07-05 14:52:39 +00:00
if ( ! $user -> deleted and ! empty ( $CFG -> messaging ) and ! isguest () and has_capability ( 'moodle/site:sendmessage' , get_context_instance ( CONTEXT_SYSTEM ))) {
2005-03-20 12:02:14 +00:00
if ( ! empty ( $USER -> id ) and ( $USER -> id == $user -> id )) {
2008-06-02 21:47:31 +00:00
if ( $countmessages = $DB -> count_records ( 'message' , array ( 'useridto' => $user -> id ))) {
2005-01-31 07:11:42 +00:00
$messagebuttonname = get_string ( " messages " , " message " ) . " ( $countmessages ) " ;
} else {
$messagebuttonname = get_string ( " messages " , " message " );
}
2007-01-06 14:07:00 +00:00
echo " <form onclick= \" this.target='message' \" action= \" ../message/index.php \" method= \" get \" > " ;
2007-03-01 04:30:42 +00:00
echo " <div> " ;
2005-01-31 07:11:42 +00:00
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); \" /> " ;
2007-03-01 04:30:42 +00:00
echo " </div> " ;
2007-01-06 14:07:00 +00:00
echo " </form> " ;
2004-12-28 13:49:44 +00:00
} else {
2007-01-06 14:07:00 +00:00
echo " <form onclick= \" this.target='message $user->id ' \" action= \" ../message/discussion.php \" method= \" get \" > " ;
2007-03-01 04:30:42 +00:00
echo " <div> " ;
2005-01-31 07:11:42 +00:00
echo " <input type= \" hidden \" name= \" id \" value= \" $user->id\ " /> " ;
2005-04-16 02:31:41 +00:00
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); \" /> " ;
2007-03-01 04:30:42 +00:00
echo " </div> " ;
2007-01-06 14:07:00 +00:00
echo " </form> " ;
2004-12-28 13:49:44 +00:00
}
}
2006-03-16 19:32:17 +00:00
// Authorize.net: User Payments
2006-03-13 21:19:04 +00:00
if ( $course -> enrol == 'authorize' || ( empty ( $course -> enrol ) && $CFG -> enrol == 'authorize' )) {
2007-01-06 14:07:00 +00:00
echo " <form action= \" ../enrol/authorize/index.php \" method= \" get \" > " ;
2007-03-01 04:30:42 +00:00
echo " <div> " ;
2006-03-16 19:32:17 +00:00
echo " <input type= \" hidden \" name= \" course \" value= \" $course->id\ " /> " ;
2006-03-13 21:19:04 +00:00
echo " <input type= \" hidden \" name= \" user \" value= \" $user->id\ " /> " ;
echo " <input type= \" submit \" value= \" " . get_string ( 'payments' ) . " \" /> " ;
2007-03-01 04:30:42 +00:00
echo " </div> " ;
2007-01-06 14:07:00 +00:00
echo " </form> " ;
2006-03-13 21:19:04 +00:00
}
2007-01-06 14:07:00 +00:00
echo " </div> \n " ;
2007-01-23 02:14:29 +00:00
if ( $CFG -> debugdisplay && debugging ( '' , DEBUG_DEVELOPER ) && $USER -> id == $user -> id ) { // Show user object
2006-09-13 06:56:25 +00:00
echo '<hr />' ;
2009-08-06 14:19:50 +00:00
echo $OUTPUT -> heading ( 'DEBUG MODE: User session variables' );
2006-09-13 06:56:25 +00:00
print_object ( $USER );
}
2007-01-23 02:14:29 +00:00
2009-08-06 14:19:50 +00:00
echo $OUTPUT -> footer ();
2001-11-22 06:23:56 +00:00
/// Functions ///////
function print_row ( $left , $right ) {
2007-01-06 14:07:00 +00:00
echo " \n <tr><td class= \" label c0 \" > $left </td><td class= \" info c1 \" > $right </td></tr> \n " ;
2001-11-22 06:23:56 +00:00
}
?>