--- loncom/interface/lonwhatsnew.pm 2009/10/30 16:31:39 1.96
+++ loncom/interface/lonwhatsnew.pm 2013/12/14 02:08:30 1.105.2.9
@@ -1,5 +1,5 @@
#
-# $Id: lonwhatsnew.pm,v 1.96 2009/10/30 16:31:39 bisitz Exp $
+# $Id: lonwhatsnew.pm,v 1.105.2.9 2013/12/14 02:08:30 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'};
@@ -87,7 +89,7 @@ sub handler {
if ( ! $env{'request.course.fn'} || ! $checkallowed{'whatsnew'}) {
# Not in a course, or no whn priv in course
- $env{'user.error.msg'}="/adm/whatsnew::whn:0:0:Cannot display what's new page";
+ $env{'user.error.msg'}="/adm/whatsnew:whn:0:0:Cannot display what's new page";
return HTTP_NOT_ACCEPTABLE;
}
@@ -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";
';
}
@@ -314,6 +386,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 +415,17 @@ sub display_actions_box {
return;
}
+ my $header = '';
if ($refpage eq 'start') {
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).'.'
+ $header .= &mt('Page set to be displayed after you have selected a role in this '.$lctype).'.'
.' '
.&mt('Currently: [_1].',''.$currinit.'')
.' '
@@ -361,7 +436,9 @@ sub display_actions_box {
,''
,''
,'')
- .'
');
+ $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.').' '); } @@ -685,7 +799,7 @@ function toggle_countunread(choice) { .' ' .&mt("This can increase the time taken to gather data for the [_1]What's New Page[_2] by a few seconds.",'','') .' ' - .&mt('Currently set to [_1].',''.$current.'.') + .&mt('Currently set to [_1].',''.$current.'') ); $r->print(' '); + $r->print(' | ||||||
'.$itemserror.' | ||||||
'.&Apache::lonlocal::locallocaltime($item).' | '. ''.$link.' | '. @@ -1667,6 +1823,99 @@ sub display_rolechanges { } return; } + +sub display_crslogins { + my ($r,$logincount,$loggedin,$interval,$crstype,$classlist) = @_; + return unless (ref($classlist) eq 'HASH'); + my %lt = &Apache::lonlocal::texthash( + 'user' => 'User', + 'role' => 'Role', + 'sec' => 'Section', + 'number' => 'Total number of logins', + ); + if ($logincount) { + + my $hdr = '|||||
'.$lt{'number'}.' | '. + ''.$lt{'role'}.' | '. + ''.$lt{'sec'}; + my (%bylastname,%counts); + if (ref($loggedin) eq 'HASH') { + my @logins = sort { $b <=> $a } (keys(%{$loggedin})); + my $numlogin = 0; + my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME(); + 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; + if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') { + $fullname = $classlist->{$uname.':'.$udom}->[$fullnameidx]; + } else { + $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). + ' | ||||||
'.$lt{'chth'}.' | +'.$lt{'chth'}.' | |||||
'.$lt{'chin'}.' | +'.$lt{'chin'}.' | |||||
'.$lt{'chop'}.' | +'.$lt{'chop'}.' | |||||
'.$lt{'chin'}.' | +'.$lt{'chin'}.' | |||||
'.$lt{'chin'}.' | +'.$lt{'chin'}.' | |||||
'.$lt{'chin'}.' | +||||||