--- loncom/interface/lonuserutils.pm 2011/01/05 18:42:53 1.134 +++ loncom/interface/lonuserutils.pm 2012/02/08 16:27:28 1.136.6.1 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.134 2011/01/05 18:42:53 raeburn Exp $ +# $Id: lonuserutils.pm,v 1.136.6.1 2012/02/08 16:27:28 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -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})) { @@ -2729,15 +2738,23 @@ END $in{'clicker'} = $clickers; my $role = $in{'role'}; $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype); - if (! defined($in{'start'}) || $in{'start'} == 0) { - $in{'start'} = &mt('none'); - } else { - $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'}); + unless ($mode eq 'excel') { + if (! defined($in{'start'}) || $in{'start'} == 0) { + $in{'start'} = &mt('none'); + } else { + $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'}); + } + if (! defined($in{'end'}) || $in{'end'} == 0) { + $in{'end'} = &mt('none'); + } else { + $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'}); + } } - if (! defined($in{'end'}) || $in{'end'} == 0) { - $in{'end'} = &mt('none'); - } else { - $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()); @@ -2839,16 +2856,6 @@ END } elsif ($mode eq 'csv') { next if (! defined($CSVfile)); # no need to bother with $linkto - if (! defined($in{'start'}) || $in{'start'} == 0) { - $in{'start'} = &mt('none'); - } else { - $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'}); - } - if (! defined($in{'end'}) || $in{'end'} == 0) { - $in{'end'} = &mt('none'); - } else { - $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'}); - } my @line = (); foreach my $item (@cols) { push @line,&Apache::loncommon::csv_translate($in{$item}); @@ -2858,9 +2865,9 @@ END my $col = 0; foreach my $item (@cols) { if ($item eq 'start' || $item eq 'end') { - if (defined($item) && $item != 0) { + if ((defined($in{$item})) && ($in{$item} != 0)) { $excel_sheet->write($row,$col++, - &Apache::lonstathelpers::calc_serial($in{item}), + &Apache::lonstathelpers::calc_serial($in{$item}), $format->{'date'}); } else { $excel_sheet->write($row,$col++,'none'); @@ -4000,7 +4007,8 @@ sub upfile_drop_add { official => 'Institutional', unofficial => 'Non-institutional', ); - map { $cancreate{$_} = &can_create_user($domain,$context,$_); } keys(%longtypes); + my $newuserdom = $env{'request.role.domain'}; + map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes); # Get new users list foreach my $line (@userdata) { my @secs; @@ -4155,25 +4163,33 @@ sub upfile_drop_add { my (%rulematch,%inst_results,%idinst_results); my $uhome=&Apache::lonnet::homeserver($username,$userdomain); if ($uhome eq 'no_host') { - if ($userdomain ne $domain) { - $r->print('
'. - &mt('[_1]: The domain specified ([_2]) is different to that of the course.', - ''.$username.'',$userdomain).'
'. - &mt('The user does not already exist, and you may not create a new user in a different domain.')); + if ($userdomain ne $newuserdom) { + if ($context eq 'course') { + $r->print('
'. + &mt('[_1]: The domain specified ([_2]) is different to that of the course.', + ''.$username.'',$userdomain).'
'); + } elsif ($context eq 'author') { + $r->print(&mt('[_1]: The domain specified ([_2]) is different to that of the author.', + ''.$username.'',$userdomain).'
'); + } else { + $r->print(&mt('[_1]: The domain specified ([_2]) is different to that of your current role.', + ''.$username.'',$userdomain).'
'); + } + $r->print(&mt('The user does not already exist, and you may not create a new user in a different domain.')); next; } $checkid = 1; $newuser = 1; - my $user = $username.':'.$domain; + my $user = $username.':'.$newuserdom; my $checkhash; my $checks = { 'username' => 1 }; - $checkhash->{$username.':'.$domain} = { 'newuser' => 1, }; + $checkhash->{$username.':'.$newuserdom} = { 'newuser' => 1, }; &Apache::loncommon::user_rule_check($checkhash,$checks, \%alerts,\%rulematch,\%inst_results,\%curr_rules, \%got_rules); if (ref($alerts{'username'}) eq 'HASH') { - if (ref($alerts{'username'}{$domain}) eq 'HASH') { - if ($alerts{'username'}{$domain}{$username}) { + if (ref($alerts{'username'}{$newuserdom}) eq 'HASH') { + if ($alerts{'username'}{$newuserdom}{$username}) { $r->print('
'. &mt('[_1]: matches the username format at your institution, but is not known to your directory service.',''.$username.'').'
'. &mt('Consequently, the user was not created.'));