--- loncom/interface/lonwhatsnew.pm 2009/10/30 16:31:39 1.96
+++ loncom/interface/lonwhatsnew.pm 2010/09/19 15:05:59 1.98.2.4
@@ -1,5 +1,5 @@
#
-# $Id: lonwhatsnew.pm,v 1.96 2009/10/30 16:31:39 bisitz Exp $
+# $Id: lonwhatsnew.pm,v 1.98.2.4 2010/09/19 15:05:59 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -42,6 +42,7 @@ use Time::Local;
use GDBM_File;
use lib '/home/httpd/lib/perl/';
use LONCAPA;
+use HTML::Entities;
#----------------------------
# handler
@@ -71,6 +72,7 @@ sub handler {
['mdc','versionchanges',0],
['vcl','newroles',1],
['vcl','oldroles',1],
+ ['whn','crslogin',1],
) {
my ($perm,$key,$check_section) = @{ $perm_check };
my $scope = $env{'request.course.id'};
@@ -142,6 +144,13 @@ sub handler {
$r->print(&Apache::lonhtmlcommon::breadcrumbs
("What's New?",#'Course_Action_Items_Intervals'
));
+ } elsif ($command eq 'chgcrslogininterval' && $checkallowed{'crslogin'}) {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/whatsnew?command=chgcrslogininterval&refpage='.$refpage,
+ text=>"Change interval"});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs
+ ("What's New?",#'Course_Action_Items_Intervals'
+ ));
} else {
$r->print(&Apache::lonhtmlcommon::breadcrumbs
("What's New?",#'Course_Action_Items_Display'
@@ -187,10 +196,17 @@ sub display_main_box {
604800 => 'roles which expired since last week',
86400 => 'roles which expired since yesterday',
);
+ my %crslogins = (
+ -1 => 'last logins for anyone who has ever logged in',
+ 2592000 => 'last logins for users in last 30 days',
+ 604800 => 'last logins for users in last 7 days',
+ 86400 => 'last logins for users in last 24 hours',
+ );
my %interval_titles = (
versions => \%versions,
newroles => \%newroles,
oldroles => \%oldroles,
+ crslogin => \%crslogins,
);
my %initpage = &Apache::lonlocal::texthash (
firstres => "first resource in the $lctype",
@@ -219,6 +235,9 @@ sub display_main_box {
} elsif (($command eq 'chgoldroleinterval')
&& $checkallowed->{'oldroles'}) {
&display_interval_config($r,$refpage,\%interval_titles,'oldroles');
+ } elsif (($command eq 'chgcrslogininterval')
+ && $checkallowed->{'crslogin'}) {
+ &display_interval_config($r,$refpage,\%interval_titles,'crslogin');
} else {
&display_actions_box($r,$command,$refpage,\%threshold_titles,
\%interval_titles,\%initpage,$cdom,$crs,$checkallowed);
@@ -244,9 +263,11 @@ sub display_header {
my $scripttag;
unless ($command eq 'chgthreshold' || $command eq 'chginterval' ||
- $command eq 'chgoldroleinterval' || $command eq 'chgnewroleinterval') {
+ $command eq 'chgoldroleinterval' ||
+ $command eq 'chgnewroleinterval' || $command eq 'chgcrslogininterval') {
$scripttag = <<"END";
';
}
@@ -281,6 +348,7 @@ END
sub display_actions_box {
my ($r,$command,$refpage,$threshold_titles,$interval_titles,$initpage,
$cdom,$crs,$checkallowed) = @_;
+ my $custommenu = &Apache::loncommon::needs_gci_custom();
my $udom = $env{'user.domain'};
my $uname = $env{'user.name'};
my $cid = $env{'request.course.id'};
@@ -314,6 +382,8 @@ sub display_actions_box {
my %expired;
my $activecount;
my %activated;
+ my %loggedin;
+ my $logincount;
my %res_title = ();
my %show = ();
my $needitems = 0;
@@ -341,16 +411,18 @@ sub display_actions_box {
return;
}
- if ($refpage eq 'start') {
+ my $header = '';
+ if (($refpage eq 'start') && (!$custommenu)) {
if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
&GDBM_READER(),0640)) {
- my $furl=$bighash{'first_url'};
+ my $furl=&HTML::Entities::encode($bighash{'first_url'},'"<>&');
untie(%bighash);
- $r->print(''.$lt{'gtfr'}.
- '
');
+ $header .= ''.$lt{'gtfr'}.
+ '
';
}
}
- $r->print(&mt('Page set to be displayed after you have selected a role in this '.$lctype).'.'
+ unless ($custommenu) {
+ $header .= &mt('Page set to be displayed after you have selected a role in this '.$lctype).'.'
.' '
.&mt('Currently: [_1].',''.$currinit.'')
.' '
@@ -361,7 +433,10 @@ sub display_actions_box {
,''
,''
,'')
- .'
');
+ $r->print('');
+ unless($custommenu) {
+ $r->print('');
+ }
+ $r->print('
'.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' expired.').' '); } elsif ($context eq 'newroles') { $r->print(' '.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' became available.').' '); + } elsif ($context eq 'crslogin') { + $r->print(' '.&mt('Choose the time window to use to display the last login by a user in the '.$lctype).' '); } else { $r->print(' '.&mt('Choose the time window to use to display resources in the '.$lctype.' with version changes.').' '); } @@ -673,12 +796,14 @@ sub display_discussion_config { 'off' => 'on', ); $r->print(''); $r->print(' ' .&mt('Choose whether or not to display a count of the number of new posts for each resource or discussion board which has unread posts.') @@ -787,10 +912,10 @@ sub display_launcher { $tograde,$ungraded,$bombs,$bombed,$changed,$warnings,$triggered, $newdiscussions,$unread,$msgcount,$newmsgs,$critmsgcount,$critmsgs, $interval,$countunread,$expired,$expirecount,$activated,$activecount, - $crstype,$itemserror) = @_; + $crstype,$itemserror,$loggedin,$logincount,$custommenu) = @_; if ($$checkallowed{$action}) { - &start_box($r,$show,$headings,$action,$refpage,$action); + &start_box($r,$show,$headings,$action,$refpage,$action,$custommenu); if ($$show{$action}) { if ($action eq 'handgrading') { # UNGRADED ITEMS &display_handgrade($r,$tograde,$ungraded,$itemserror); @@ -800,7 +925,7 @@ sub display_launcher { &display_versionchanges($r,$changed,$res_title,$interval->{'versions'},$itemserror); } elsif ($action eq 'abovethreshold') { # DEGDIFF/AV. TRIES TRIGGERS &display_abovethreshold($r,$refpage,$warnings,$triggered, - $res_title,$itemserror); + $res_title,$itemserror,$custommenu); } elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION &display_coursediscussion($r,$newdiscussions,$unread, $countunread,$res_title,$itemserror); @@ -814,6 +939,10 @@ sub display_launcher { } elsif ($action eq 'oldroles') { # EXPIRED ROLES &display_rolechanges($r,$expirecount,$expired,$interval->{'oldroles'}, $crstype); + } elsif ($action eq 'crslogin') { #LAST LOGIN + &display_crslogins($r,$logincount,$loggedin,$interval->{'crslogin'}, + $crstype); + } } &end_box($r); @@ -824,7 +953,7 @@ sub display_launcher { sub getitems { my ($unread,$ungraded,$bombed,$triggered,$changed,$newdiscussions, $tograde,$bombs,$warnings,$threshold,$cdom,$crs,$res_title,$show, - $starttime,$countunread) = @_; + $starttime,$countunread,$custommenu) = @_; my $navmap = Apache::lonnavmaps::navmap->new(); if (!defined($navmap)) { my $itemserror = ''.&mt('An error occurred retrieving information about the course.').' '.&mt('It is recommended that you [_1]re-select the course[_2].','','').''; @@ -884,7 +1013,7 @@ sub getitems { # Maxtries and degree of difficulty for problem parts, unless handgradeable if ($$show{'abovethreshold'}) { &check_thresholds($resource,$symb,\%resourcetracker, - $triggered,$threshold,$warnings); + $triggered,$threshold,$warnings,$custommenu); } } @@ -958,7 +1087,7 @@ sub check_bombed { } sub check_thresholds { - my ($resource,$symb,$resourcetracker,$triggered,$threshold,$warnings) = @_; + my ($resource,$symb,$resourcetracker,$triggered,$threshold,$warnings,$custommenu) = @_; # Compile maxtries and degree of difficulty for problem parts, unless handgradeable my @parts = @{$resource->parts()}; my %stats; @@ -1016,12 +1145,17 @@ sub check_thresholds { $$triggered{$symb}{text}[$partcount] = ' | '.&mt('single part').' | '; } - $$triggered{$symb}{text}[$partcount] .= ' -'.$stats{$part}{users}.' | -'.$stats{$part}{attempts}.' | -'.$stats{$part}{degdiff}.' | -'.$lastreset{$part}.' | -'; + if ($custommenu) { + $$triggered{$symb}{text}[$partcount] .= ' + | '.$stats{$part}{users}.' | '; + } else { + $$triggered{$symb}{text}[$partcount] .= ' +'.$stats{$part}{users}.' | +'.$stats{$part}{attempts}.' | +'.$stats{$part}{degdiff}.' | +'.$lastreset{$part}.' | +'; + } $partcount ++; } $$triggered{$symb}{numparts} = $partcount; @@ -1032,7 +1166,14 @@ sub check_thresholds { sub get_curr_thresholds { - my ($threshold,$uname,$udom,$cid,$cdom,$crs) = @_; + my ($threshold,$uname,$udom,$cid,$cdom,$crs,$custommenu) = @_; + if ($custommenu) { + %$threshold = (av_attempts => 0, + degdiff => 0.00000000000000, + numstudents => 1 + ); + return; + } # set default values %$threshold = (av_attempts => 2, degdiff => 0.5, @@ -1411,6 +1552,39 @@ sub getrolechanges { return $rolechgcount; } +sub getloggedin { + my ($cdom,$crs,$lastlogins,$starttime) = @_; + my $context = 'course'; + my ($permission,$allowed) = + &Apache::lonuserutils::get_permission($context); + my $viewablesec = &Apache::lonuserutils::viewable_section($permission); + my %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$crs); + my $logincount = 0; + my ($tmp) = keys(%crslogins); + unless ($tmp =~ /^(con_lost|error|no_such_host)/i) { + if (keys(%crslogins) > 0) { + foreach my $key (keys(%crslogins)) { + my ($uname,$udom,$section,$role) = split(/:/,$key); + my $eventtime = $crslogins{$key}; + if ($eventtime > $starttime) { + if (($viewablesec ne '') && ($section ne '')) { + next if ($viewablesec ne $section); + } + my %chginfo = ( + 'section' => $section, + 'uname' => $uname, + 'udom' => $udom, + 'role' => $role, + ); + $logincount ++; + push (@{$lastlogins->{$eventtime}},\%chginfo); + } + } + } + } + return $logincount; +} + sub checkversions { my ($cdom,$crs,$navmap,$changed,$starttime) = @_; my %changes=&Apache::lonnet::dump('versionupdate',$cdom,$crs); @@ -1511,7 +1685,7 @@ sub display_haserrors { } sub display_abovethreshold { - my ($r,$refpage,$warnings,$triggered,$res_title,$itemserror) = @_; + my ($r,$refpage,$warnings,$triggered,$res_title,$itemserror,$custommenu) = @_; my %lt = &Apache::lonlocal::texthash( reso => 'Resource', part => 'Part', @@ -1525,16 +1699,35 @@ sub display_abovethreshold { ); if (@{$warnings} > 0) { @{$warnings} = sort { &cmp_title($a,$b,$res_title) } @{$warnings}; - $r->print(''); + unless ($custommenu) { + $r->print(' | |||
'.$itemserror.' | |||||||||||||||
'.$lt{'number'}.' | '. + ''.$lt{'role'}.' | '. + ''.$lt{'sec'}; + my (%bylastname,%counts); + if (ref($loggedin) eq 'HASH') { + my @logins = sort { $b <=> $a } (keys(%{$loggedin})); + my $numlogin = 0; + foreach my $item (@logins) { + if (ref($loggedin->{$item}) eq 'ARRAY') { + foreach my $user (@{$loggedin->{$item}}) { + if (ref($user) eq 'HASH') { + my $section; + my $role = + &Apache::lonnet::plaintext($user->{'role'},$crstype); + my $status = &mt($user->{'status'}); + if ($user->{'section'} eq '') { + $section = &mt('none'); + } else { + $section = $user->{'section'}; + } + $counts{$user->{'role'}}{$section} ++; + my $uname = $user->{'uname'}; + my $udom = $user->{'udom'}; + my $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname'); + my $link = + &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom); + push(@{$bylastname{$fullname}}, + ' | '.$link.' | '. + ''.$role.' | '. + ''.$section.' | '); + } + } + } + } + my $table; + foreach my $person (sort(keys(%bylastname))) { + if (ref($bylastname{$person}) eq 'ARRAY') { + foreach my $item (@{$bylastname{$person}}) { + $numlogin ++; + my $css_class = $numlogin%2?' class="LC_odd_row"':''; + $table .= '||||||||||
'.$counts{$role}{$sec}.' | '. + ''.$showrole.' | '. + ''.$sec.' | |||||||||||||
'. + &mt('There are no '.$interval). + ' | '.$showhide.' | '); if (($caller eq 'abovethreshold') && ($$show{$caller})) { - if ($$show{$caller}) { + if ($$show{$caller} && !$custommenu) { $r->print('||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
'.$lt{'chth'}.' | +'.$lt{'chth'}.' | ||||||||||||||
'.$lt{'chin'}.' | +'.$lt{'chin'}.' | ||||||||||||||
'.$lt{'chop'}.' | +'.$lt{'chop'}.' | ||||||||||||||
'.$lt{'chin'}.' | +'.$lt{'chin'}.' | ||||||||||||||
'.$lt{'chin'}.' | +'.$lt{'chin'}.' | +||||||||||||||
'.$lt{'chin'}.' | |||||||||||||||