--- loncom/interface/lonuserutils.pm	2011/08/05 14:46:58	1.136
+++ loncom/interface/lonuserutils.pm	2012/08/19 00:18:16	1.139
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.136 2011/08/05 14:46:58 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.139 2012/08/19 00:18:16 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -47,8 +47,7 @@ sub modifystudent {
     # this one.  If $csec is defined, drop them from all other sections of
     # this course and add them to section $csec
     my ($cnum,$cdom) = &get_course_identity($courseid);
-    my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
-    my %roles = &Apache::lonnet::dump('roles',$udom,$unam,'.',undef,$extra);
+    my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
     my ($tmp) = keys(%roles);
     # Bail out if we were unable to get the students roles
     return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
@@ -1422,6 +1421,7 @@ sub curr_role_permissions {
 sub my_custom_roles {
     my ($crstype) = @_;
     my %returnhash=();
+    my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
     my %rolehash=&Apache::lonnet::dump('roles');
     foreach my $key (keys(%rolehash)) {
         if ($key=~/^rolesdef\_(\w+)$/) {
@@ -2321,6 +2321,7 @@ END
                        'type'       => "enroll type/action",
                        'email'      => "e-mail address",
                        'photo'      => "photo",
+                       'lastlogin'  => "last login", 
                        'extent'     => "extent",
                        'pr'         => "Proceed",
                        'ca'         => "check all",
@@ -2369,6 +2370,9 @@ END
             push(@cols,'groups');
         }
         push(@cols,'email');
+        if ($context eq 'course') {
+            push(@cols,'lastlogin');
+        }
     }
 
     my $rolefilter = $env{'form.showrole'};
@@ -2593,6 +2597,11 @@ END
                                                 Future  => 'Future',
                                                 Expired => 'Expired',
                                                );
+    # If this is for a single course get last course "log-in".
+    my %crslogins;
+    if ($context eq 'course') {
+        %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
+    }
     # Get groups, role, permanent e-mail so we can sort on them if
     # necessary.
     foreach my $user (keys(%{$userlist})) {
@@ -2741,6 +2750,12 @@ END
                 $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
             }
         }
+        if ($context eq 'course') {
+            my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
+            if ($lastlogin ne '') {
+                $in{'lastlogin'} = &Apache::lonlocal::locallocaltime($lastlogin);
+            }
+        }
         if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
             $r->print(&Apache::loncommon::start_data_table_row());
             my $checkval;